Swagger ServletHandlerError - java

I want to have a documentation for my REST-Calls, in a earlier Project I written it alone but now the Project is a bit bigger so I searched for a good framework. I found swagger.io. It looks very nice and the implementation looks very simple for the maven project. I set the dependency in the Path
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
and configure the servlets of the web.xml
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
io.swagger.jaxrs.listing,
package.rest
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>0.0.1</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/rest</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
I think I have done it but after a new Maven Install and start the Jetty Server, I called the url localhost:8080/rest/swagger.xaml or ../swagger.json there comes the following Exception:
2016-07-08 09:13:12.058:WARN:oejs.ServletHandler:Error for /rest/swagger.json
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.collection.Values.lazy(Lorg/glassfish/jersey/internal/util/collection/Value;)Lorg/glassfish/jersey/internal/util/collection/Value;
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
Do you can help me?
I tried the install guide if swagger.io also for Jersey 1.17.1 there comes no exception but also no result.

The java.lang.NoSuchMethodError above is stemming from having different versions of Jersey 2 jars in your classpath.
See NoSuchMethodError on Values.lazy (Jersey 2.5.1) and https://java.net/jira/browse/JERSEY-2394 for more details.

Related

Jersey : How to prevent Conflicting URI templates with other web services in the same web app

I am trying to introduce Jersey web service into a web application that has other web services (such as Apache CXF in it) in it. So I added Jersey servlet to my web.xml..
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.freedomoss.crowdcontrol.api</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
During intiliazation this servlet gives the following error about conflicting URL templates...
INFO: Registering Spring bean, restApiService, of type com.mycompany.ws.RestApiService as a root resource class
Mar 12, 2015 11:07:42 PM com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Conflicting URI templates. The URI template / for root resource class com.mycompany.ws.RestApiService and the URI template / transform to the same regular expression (/.*)?
When I look in the code of this RestApiService, I see..
#Path("/")
#Service
public class RestApiService extends AbstractRestService {
Since this other web service is being used elsewhere in the application I cannot change the value of 'Path' although doing so does solve my problem
What else can I do? Can I somehow tell Jersey Servlet not to register this other web service "as a root resource class"?
My goal is to make Jersey work along with this other web service and not change the latter in any way.

Spring Boot App deployed to Weblogic 11g Won't Start

I'm having some issues deploying a Spring Boot application to a Weblogic 10.3.3 Server. I'm desperately crossing my fingers in hopes that someone has seen this issue before. I use Weblogic's admin console to perform the deployment (and that seems to go well), but I get an error from Weblogic when I attempt to start the application:
Caused By: java.lang.IllegalArgumentException: Invalid source 'com.example.Application'
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:223)
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:144)
at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:127)
at org.springframework.boot.SpringApplication.load(SpringApplication.java:620)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
at org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:61)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1863)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3126)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1512)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:486)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:1267)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:41)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:409)
at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:43)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:569)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:150)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:116)
at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:143)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:323)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:844)
at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1253)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:440)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
The app is deployed as a WAR file using spring-boot-legacy and a web.xml. It runs fine on Tomcat 6/7/8. Here are my relevant config files:
web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.example.Application</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>helloWorld</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>helloWorld</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
weblogic.xml
<wls:weblogic-web-app
xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app
http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<wls:context-root>helloWorld</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
Tracing through the stack trace, it appears that Spring Boot's BeanDefinitionLoader class attempts to load the source classes (in my case, just com.example.Application) but fails because it doesn't see it as a class, resource, or package. Looking at the BeanDefinitionLoader class here: BeanDefinitionLoader.java (line 187), it appears that my Application class should get loaded as a Class. Like I mentioned, it does work great in Tomcat, just not in Weblogic.
Is there something Weblogic-specific that I'm missing? Could it be a file encoding issue? Am I missing something from my web.xml?
Thanks for your time!
Update #1
After exhausting Google and StackOverflow for things to try, I added the spring.main.sources: com.example.Application to my application.yml. It had no effect.
My current hunch right now is that the contextAttribute parameter in my web.xml might have something to do with my issue. Just unsure what else I can change it to. Thoughts?
Check that your building your war with the same version of Java as the Weblogic server is running. Eg if it's 1.6 set JAVA_HOME to your 1.6 JDK before running gradle build.
Does boot need higher version of servlet version than Weblogic 10.3.3 Server supports? Does this version bit old??

Enabling Cross Domain in Jersey - Facing runtime exception

I am following this article to make our Jersey to CORS complaint. So far I have implemented ContainerResponseFilter to add Access-Control-Allow-Origin headers to response. This is my snippet:
ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
resp.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String reqHead = req.getHeaderValue("Access-Control-Request-Headers");
if(null != reqHead && !reqHead.equals("")){
resp.header("Access-Control-Allow-Headers", reqHead);
}
contResp.setResponse(resp.build());
And this is my web.xml contents:
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.test.ResponseCorsFilter</param-value>
</init-param>
When I run I get this error:
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
But if I run the same application with these config:
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.test.client</param-value>
</init-param>
I am not getting any error. So this error is occuring only if I try to use ContainerResponseFilter. Can someone help me in resolving this issue?

Tomcat unable to parse web.xml, no error at mentioned code point

I am using Jersey for my web service, and this is how my web.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-name>com.rohanprabhu.external.interfaces.service.web</param-name>
</init-param>**
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-name>true</param-name>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
</web-app>
I am getting an error Occurred at line 10 column 22, which is where I have marked in my file as '**' (it isn't actually there in the file, I just put it on here). Here is (a part) of the stack trace I get:
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.lang.IllegalArgumentException: Can't convert argument: null
at org.apache.tomcat.util.IntrospectionUtils.convert(IntrospectionUtils.java:889)
at org.apache.tomcat.util.digester.CallMethodRule.end(CallMethodRule.java:476)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1057)
... 188 more
Occurred at line 10 column 22
Marking this application unavailable due to previous error(s)
Here is the entire stacktrace, in case that helps: http://pastebin.com/EX4bMGex
I agree the error message is suboptimal, but I'm also sure you want one <param-name> and one <param-value> per <init-param>. :-)
You are using <param-name> twice. but other init attribute should be <param-value>.

Tomcat 7.0.30 does not work with Resteasy 2.3.4

I created a small web application with resteasy 2.3.4 Final, and I deployed it to Tomcat 7.0.30. I got the following error message when tomcat starts:
...
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Sep 11, 2012 9:28:08 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter org.jboss.resteasy.plugins.server.servlet.Filter30Dispatcher
java.lang.NoClassDefFoundError: javax/enterprise/context/spi/Contextual
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
...
My web.xml is as follows:
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/services</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
Problem solved by removing the resteasy-cdi-2.3.4.Final.jar.
that happen to me either but with tomcat 7.0.52 and resteasy-cdi-3.0.6.Final
i removed the resteasy-cdi-3.0.6.Final form the library package and it deployed well

Categories