i am getting issue while start tomcat server - jersey

I am new to jersey multi part. While i am starting the tomcat server getting issue.
#POST
#Path("/uploadImagesUsingJersey")
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces("text/plain")
public Response uploadImages(#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataContentDisposition fileDetail) throws IOException{
String uploadedFileLocation = (String) session.getServletContext().getAttribute("ProfilePhotoPath");
uploadedFileLocation=uploadedFileLocation+236+"/"+fileDetail.getName();
writeToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded to : " + uploadedFileLocation;
employeeVO=new EmployeeInformationVO();
employeeVO=(EmployeeInformationVO) CacheAction.getById(EmployeeInformationVO.class,236);
employeeVO.setPhotoPath(236+"/"+fileDetail.getFileName());
int result=CacheAction.commonAddOrUpdate(employeeVO);
return Response.status(200).entity(result).build();
}
I am using this kind Of jar:
1)jersey-multipart-1.8-ea03.jar
2)mimepull-1.8-sources.jar
3)jersey-server-1.8.jar
4)jersey-bundle-1.8.jar
And i am getting this kind of issue:
INFO: Provider classes found:
class com.owlike.genson.ext.jaxrs.GensonJsonConverter
Nov 13, 2016 10:45:15 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:39 PM'
Nov 13, 2016 10:45:17 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response com.hrm.jersey.action.MyServiceAction.uploadImages(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException, annotated with POST of resource, class com.hrm.jersey.action.MyServiceAction, is not recognized as valid resource method.
Nov 13, 2016 10:45:17 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
com.sun.jersey.spi.inject.Errors$ErrorMessagesException

Related

Microsoft Graph Proxy and Bypass SSL

Im using the below :
Java 8
microsoft-graph : 2.10.0
microsoft-graph-auth : 0.2.0
okhttp : 3.14.9
I want to fetch data from Intune using Microsoft Graph API, want to use proxy and also bypass SSL (for testing). As per documentation, i have used the OKHttpClient. Used the OkHttpClient for configuring the proxy, sslSocketFactory and hostnameVerifier but it is no working.
final ClientCredentialProvider authProvider = new ClientCredentialProvider(this.clientId, this.scopes, this.clientSecret, this.tenantId, NationalCloud.Global);
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
#Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0] {};
}
#Override
public void checkServerTrusted(final X509Certificate[] arg0, final String arg1)
throws CertificateException {
}
#Override
public void checkClientTrusted(final X509Certificate[] arg0, final String arg1)
throws CertificateException {
}
} };
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient httpClient = HttpClients.createDefault(new ICoreAuthenticationProvider() {
#Override
public Request authenticateRequest(final Request request) {
return request;
}
}).newBuilder().proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.proxyHost, this.proxyPort)))
.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]).hostnameVerifier(new HostnameVerifier() {
#Override
public boolean verify(final String arg0, final SSLSession arg1) {
return true;
}
}).build();
final IHttpProvider httpProvider = DefaultClientConfig.createWithAuthenticationProvider(authProvider)
.getHttpProvider(httpClient);
final IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider)
.httpProvider(httpProvider).buildClient();
IUserCollectionPage page = graphClient.users().buildRequest().get();
I get the below errors:
org.apache.oltu.oauth2.common.exception.OAuthSystemException: java.net.UnknownHostException: login.microsoftonline.com
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:108)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:71)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.getAccessTokenNewRequest(ClientCredentialProvider.java:102)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.getAcccessToken(ClientCredentialProvider.java:67)
at com.microsoft.graph.auth.confidentialClient.ClientCredentialProvider.authenticateRequest(ClientCredentialProvider.java:49)
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:395)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:220)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:200)
at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:92)
at com.microsoft.graph.requests.extensions.UserCollectionRequest.get(UserCollectionRequest.java:72)
at com.hsbc.gme.test.graph_test.App.main(App.java:114)
Caused by: java.net.UnknownHostException: login.microsoftonline.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1283)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1258)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at org.apache.oltu.oauth2.client.URLConnectionClient.setRequestBody(URLConnectionClient.java:124)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:91)
... 12 more
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Graph service exception Error code: InvalidAuthenticationToken
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Error message: CompactToken parsing failed with error code: 80049217
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220GET https://graph.microsoft.com/v1.0/users
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220SdkVersion : graph-java/v2.10.0
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220Authorization : [PII_REDACTED]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220401 : Unauthorized
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220[...]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: CoreHttpProvider[send] - 220[Some information was truncated for brevity, enable debug logging for more details]
Mar 14, 2021 11:30:17 PM com.microsoft.graph.logger.DefaultLogger logError
SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217
GET https://graph.microsoft.com/v1.0/users
SdkVersion : graph-java/v2.10.0
Authorization : [PII_REDACTED]
401 : Unauthorized
[...]
[Some information was truncated for brevity, enable debug logging for more details]
Exception in thread "main" com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217
GET https://graph.microsoft.com/v1.0/users
SdkVersion : graph-java/v2.10.0
Authorization : [PII_REDACTED]
401 : Unauthorized
[...]
[Some information was truncated for brevity, enable debug logging for more details]
at com.microsoft.graph.http.GraphServiceException.createFromConnection(GraphServiceException.java:496)
at com.microsoft.graph.http.CoreHttpProvider.handleErrorResponse(CoreHttpProvider.java:503)
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:423)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:220)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:200)
at com.microsoft.graph.http.BaseCollectionRequest.send(BaseCollectionRequest.java:92)
at com.microsoft.graph.requests.extensions.UserCollectionRequest.get(UserCollectionRequest.java:72)
at com.hsbc.gme.test.graph_test.App.main(App.java:114)
Note : If i use https.proxyHost and https.proxyPort then the proxy works, however how can i make it working with the OkHttpClient. Also need a way to bypass SSL

Could not load properties error in spring PropertyPlaceHolderConfigurer

I have the following code, using a PropertyPlaceHolderConfigurer:
public static void main(String[] args) {
Scanner sc=null;
CustomerDTO dto=null;
//create IOC Container
ApplicationContext ctx=new FileSystemXmlApplicationContext("src/main/java/com/nt/cfgs/applicationContext.xml");
//get PropertyPlaaceHolderConfigurer OBJ
BeanFactoryPostProcessor bfpp=ctx.getBean("ppc",PropertyPlaceholderConfigurer.class);
bfpp.postProcessBeanFactory((ConfigurableListableBeanFactory)ctx);
sc=new Scanner(System.in);
System.out.println("Enter Customer NO: ");
int cno=sc.nextInt();
System.out.println("Enter Customer Name: ");
String cname=sc.next();
System.out.println("Enter Principal Amount:: ");
float pamt=sc.nextFloat();
System.out.println("Enter Rate of Interest: ");
float rate=sc.nextFloat();
System.out.println("Enter Time/Period: ");
float time=sc.nextFloat();
//set values to dto
dto=new CustomerDTO();
dto.setCno(cno);
dto.setCname(cname);
dto.setPamt(pamt);
dto.setRate(rate);
dto.setTime(time);
//getBean
LoanService service=ctx.getBean("service",LoanService.class);
System.out.println(service.calcIntrAmt(dto));
}
The code above gives me the following error:
Aug 04, 2018 8:16:08 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext#621be5d1: startup date [Sat Aug 04 20:16:08 IST 2018]; root of context hierarchy
Aug 04, 2018 8:16:08 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\NTSP710\IOC-Beans28ApplicationContextWithPropertyFileConfigurator\src\main\java\com\nt\cfgs\applicationContext.xml]
Aug 04, 2018 8:16:08 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: src\main\java\com\nt\commons\DBDetails.properties
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: src\main\java\com\nt\commons\DBDetails.properties
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:164)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:142)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:85)
at com.nt.test.ClientApp.main(ClientApp.java:21)
Caused by: java.io.FileNotFoundException: src\main\java\com\nt\commons\DBDetails.properties
at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:129)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:162)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80)
... 7 more
How can I fix this problem?
You should put your application context in src/main/resources/com/nt/cfgs/applicationContext.xml, then try reading it with just "com/nt/cfgs/applicationContext.xml" ... Your class does not get executed from the top of your project, but rather from within the target folder - so it cannot see the path you indicate relative to "target".
Or better yet, use a classpath context reader and the path "classpath:com/nt/cfgs/applicationContext.xml" ...
The exception is straightforward. It says
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: src\main\java\com\nt\commons\DBDetails.properties
This means that it's not able to find the DBDetails.properties file in the path given. You need to provide the correct path of the same either in applicationContext.xml or #PropertySource, wherever you have defined it.
I faced the same issue for a .xml file, It wasted lot of my time, eventually I followed these steps to fix it:
Delete your project (or multiple related projects) and its sub-project if any from workspace (don't delete it from your computer disk).
Import the project again, Mine was from git so I did "Import from GIT"
Once import is complete, clean install from pom.xml
Then try running the main class.
There could be a better solution but this fixed my issue,
Might help others too.

Spring not able to locate the xml configuration file

I tried by placing the springConfig.xml in the WEB_INF as well as src directory, but still getting the IOException.
Code:
public class DrawingApp {
public static void main(String[] args) {
//Triangle triangle = new Triangle();
ApplicationContext context = new
ClassPathXmlApplicationContext("springConfig.xml");
Triangle triangle = (Triangle) context.getBean("triangle");
triangle.draw();
((ClassPathXmlApplicationContext)context).close();
}
}
Exception:
Jul 23, 2018 11:33:18 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#179d3b25: startup date [Mon Jul 23 11:33:18 IST 2018]; root of context hierarchy
Jul 23, 2018 11:33:18 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [springConfig.xml]
Jul 23, 2018 11:33:19 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [file:/D:/Learning/Workspace/Java%20Project/Spring2/SpringDemo/target/classes/trace-context.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [trace-context.xml]
Offending resource: class path resource [springConfig.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/D:/Learning/Workspace/Java%20Project/Spring2/SpringDemo/target/classes/trace-context.xml]; nested exception is java.io.FileNotFoundException: D:\Learning\Workspace\Java Project\Spring2\SpringDemo\target\classes\trace-context.xml (The system cannot find the file specified)
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:255)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:180)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:165)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:138)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304
You should specify where is the resource path located within your project. More on this link
https://maven.apache.org/pom.html#Resources

why spring WebApplicationInitializer StandardContext reload immediately after sever start?

I am using spring WebApplicationInitializer instead of AbstractAnnotationConfigDispatcherServletInitializer with the following code.
public class ApplicationInitializer implements WebApplicationInitializer {
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Register the Root application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(AppConfig.class);
// Context loader listener
servletContext.addListener(new ContextLoaderListener(rootContext));
// Register the Web application context
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(WebMvcConfig.class);
// Register the Spring dispatcher servlet
DispatcherServlet dispatcherServlet = new DispatcherServlet(mvcContext);
dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter());
encodingFilter.setInitParameter("encoding", "UTF-8");
encodingFilter.setInitParameter("forceEncoding","true");
encodingFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
The application first start complete then it reload and start again with the following log.
INFO: Initializing Spring root WebApplicationContext
**************************false
Apr 11, 2016 2:58:56 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Apr 11, 2016 2:58:57 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 11, 2016 2:58:57 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 11, 2016 2:58:57 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 18577 ms
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/iamSystem] has started
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'dispatcher'
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Apr 11, 2016 2:59:07 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [iamSystem] registered the JDBC driver [net.sourceforge.jtds.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Apr 11, 2016 2:59:08 AM org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading
Apr 11, 2016 2:59:12 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 11, 2016 2:59:12 AM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [com.egen.iamsystem.config.ApplicationInitializer#fd75714, com.egen.iamsystem.config.core.SpringSecurityInitializer#73113f1f]
Apr 11, 2016 2:59:13 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
**************************false
Apr 11, 2016 2:59:21 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Apr 11, 2016 2:59:22 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/iamSystem] is completed
if i use AbstractAnnotationConfigDispatcherServletInitializer
public class SpringWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class };
// return new Class[] { WebMvcConfig.class };
// return null;
}
// Since we have a single DispatcherServlet here, we can add the WebConfig
// to the root context and make the servlet context empty
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebMvcConfig.class };
// return new Class[] { };
// return null;
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
#Override
protected Filter[] getServletFilters() {
return new Filter[] { new DelegatingFilterProxy("springSecurityFilterChain"),
new OpenEntityManagerInViewFilter() };
}
// By default when the DispatcherServlet can't find a handler for a request
// it sends a 404 response. However if its property
// "throwExceptionIfNoHandlerFound" is set to true this exception is raised
// and may be handled with a configured HandlerExceptionResolver
#Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
boolean done = registration.setInitParameter("throwExceptionIfNoHandlerFound", "true"); // ->
// true
if (!done)
throw new RuntimeException();
}
}
it is ok the server start success with only one time
What is the problem?
You are instantiating it twice , that's why it reloads twice :
// Register the Root application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
.
.
.
// Register the Web application context
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(WebMvcConfig.class);

Using Grizzly as the test container for dropwizard resources

I am trying to get this GrizzlyResourceTest.javaworking with dropwizard v0.6.1. The reason I want to use grizzly as the test container is because InMemoryTestContainer does not support Resource with injectable constructor, see this issue in details InMemoryTestContainer does not support Resource with injectable constructor
Since com.yammer.dropwizard.json.Json and com.yammer.dropwizard.bundles.JavaBundle are not in v0.6.1 anymore, I simply just comment out the lines related to these class.
#Before
public void setUpJersey() throws Exception {
setUpResources();
this.test = new JerseyTest(new GrizzlyWebTestContainerFactory()) {
#Override
protected AppDescriptor configure() {
ClientConfig config = new DefaultClientConfig();
// taken from DropwizardResourceConfig
config.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
config.getSingletons().add(new LoggingExceptionMapper<Throwable>() { }); // create a subclass to pin it to Throwable
config.getClasses().add(InstrumentedResourceMethodDispatchAdapter.class);
config.getClasses().add(CacheControlledResourceMethodDispatchAdapter.class);
for (Class<?> provider : providers) {
config.getClasses().add(provider);
}
config.getSingletons().addAll(singletons);
return new WebAppDescriptor.Builder("com.example.helloworld.resources").clientConfig(config).build();
}
};
test.setUp();
}
My case is more complex since I have HttpServletRequest injected to my resource class like myMethod(#Context HttpServletRequest request). So here I just use PersonResource under dropwizard-example.
QuickTest.java looks like:
public class QuickTest extends GrizzlyResourceTest{
#Test
public void testGrizzly() throws Exception {
ClientResponse rsp = client()
.resource("http://localhost:9998/people").get(ClientResponse.class);
Assert.assertEquals(200, rsp.getStatus());
}
#Override
protected void setUpResources() throws Exception {
}
}
When I run QuickTest, The error I am getting from Console is this:
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Mar 14, 2013 7:14:11 PM com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer <init>
INFO: Creating Grizzly2 Web Container configured at the base URI http://localhost:9998/
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Starting application [TestContext] ...
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext initServlets
INFO: [TestContext] Servlet [com.sun.jersey.spi.container.servlet.ServletContainer] registered for url pattern(s) [[/*]].
Mar 14, 2013 7:14:11 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Application [TestContext] is ready to service requests. Root: [].
Mar 14, 2013 7:14:11 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for field: private javax.servlet.http.HttpServletRequest com.yammer.dropwizard.jersey.LoggingExceptionMapper.request
Any ideas?

Resources