AccessController usage

You would use AccessController.doPrivileged() to give certain code privileges that code earlier in the calling stack DOES NOT have but which the privileged codes DOES have by virtue of that privilege being granted in a policy. For example, assume ClassA invokes methods on ClassB, and ClassB needs to read the java.home system property (to borrow … Read more

How to get name of scenario in cucumber java?

From version 1.6, in addition to, getStatus() and getSourceTagNames(), there is another method, getName() that returns the scenario’s description. For example, for a scenario as follows: Scenario: verify number of topics shown in the UI scenario.getName() returns “verify number of topics shown in the UI” I initialize scenario in @Before as follows: @Before public void … Read more

Deploy Spring Boot to Tomcat

The chapter Packaging executable jar and war files in the Spring Boot reference documentation states: To build a war file that is both executable and deployable into an external container you need to mark the embedded container dependencies as “provided”, e.g: <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <!– … –> <packaging>war</packaging> <!– … … Read more

Should I buffer the InputStream or the InputStreamReader?

r1 is more efficient. The InputStreamReader itself doesn’t have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader. The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the data through a funnel, not through a bottle. Update: here’s a little benchmark program, just … Read more

Error 404: The requested resource is not available using HelloWorld servlet [duplicate]

Try this (if the Java EE V6) package crunch; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; @WebServlet(name=”hello”,urlPatterns={“/hello”}) // added this line public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println(“Hello World”); } } now reach the servlet by http://127.0.0.1:8080/yourapp/hello where 8080 is default Tomcat … Read more

Parent pom and microservices

The ‘problem’ with a multi-module parent pom is that, without complicated profiles, it locks the modules in the same release cycle (assuming you’re using the Release Plugin, which you should be). The way I work with Maven is to have a parent pom that declares: common dependencies (logging APIs, JUnit, etc). common plugins. all dependencies … Read more

how to get parameter’s annotation in java?

getParameterAnnotations returns one array per parameter, using an empty array for any parameter which doesn’t have any annotations. For example: import java.lang.annotation.*; import java.lang.reflect.*; @Retention(RetentionPolicy.RUNTIME) @interface TestMapping { } public class Test { public void testMethod(String noAnnotation, @TestMapping String withAnnotation) { } public static void main(String[] args) throws Exception { Method method = Test.class.getDeclaredMethod (“testMethod”, … Read more