java.lang.IllegalStateException: getWriter() has already been called for this response - spring

I am doing training about CXF and Spring, so I wrote a very simple CXF demo which only has the interface "HelloWorld" and its implementor "HelloWorldWs".
I want to publish it with Tomcat. I wrote a web.xml and applicationContext.xml(Spring profile. Though i can publish the WSDL .But the console list a problem:
Servlet.service() for servlet [CXFServlet] in context with path [/cxf_spring] threw exception java.lang.IllegalStateException: getWriter() has already been called for this response
I did not use or write any io function, just a "sayhi" function. I am stumped.

This is actually a bug and is fixed as part of https://issues.apache.org/jira/browse/CXF-5620,
CXF 2.7.11 (released)

Related

How to use Jersey in Sling?

I've got Sling 8. I then include Jersey and this Jersey connector in my build: https://github.com/hstaudacher/osgi-jax-rs-connector
My next step should be simply write a Jersey Service and test it, but I'm getting this Exception immediately:
27.01.2017 10:54:16.696 *ERROR* [FelixDispatchQueue] com.eclipsesource.jaxrs.publisher FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null.)org.osgi.framework.ServiceException: Service factory returned null.
and
[FelixDispatchQueue] com.eclipsesource.jaxrs.publisher FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory exception: org/apache/felix/shell/Command)
org.osgi.framework.ServiceException: Service factory exception: org/apache/felix/shell/Command
and
Caused by: java.lang.NoClassDefFoundError: org/apache/felix/shell/Command
So I look at my bundles list in Felix, and I don't see any bundle that appears to provide this... So I find it online and install it myself. Now I get this exception:
Service factory exception: org/apache/sling/extensions/threaddump/internal/ThreadDumpCommand
and
Caused by: java.lang.NoClassDefFoundError: org/apache/sling/extensions/threaddump/internal/ThreadDumpCommand
and
Caused by: java.lang.NoClassDefFoundError: org/apache/felix/webconsole/plugins/memoryusage/internal/MemoryUsageCommand
Now, I DO have a bundle installed with this class (it's "Apache Felix Web Console Memory Usage Plugin"). So now I really don't understand what the heck is going on.
I have a feeling that I'm not supposed to be providing my own "felix shell" bundle and that the OSGI in Sling is failing to provide it...
Is anybody successfully using Sling 8 and Jersey?
Maybe you should try with just a vanilla OSGi environment for starters. Once you have Jersey working then you can try integrating with Sling.
I have had success with jaxrs in OSGi, specifically using the Amdatu REST bundles.
https://amdatu.org/application/tutorial/step1/
With this I was able to use JAX-RS annotations to serve HTTP services:
https://github.com/figurate/figurate-core/blob/master/modules/figurate-osgi/src/main/groovy/org/figurate/osgi/http/ServiceInfo.groovy
You can see the bundles I used here:
https://github.com/figurate/figurate-core/blob/master/modules/figurate-osgi/src/test/resources/config/HttpVersionSpec.config

Getting NoSuchMethodError in Kafka Consumer v0.10.0.1

I am trying to move to KafkaClient 0.10.0.1 from 0.9.0.0. The code is working fine in production with 0.9.0.0. Now the same code in development platform throwing exception when a consumer is started with following exception
javax.servlet.ServletException: java.lang.NoSuchMethodError: org/apache/kafka/clients/consumer/KafkaConsumer.subscribe(Ljava/util/List;)V (loaded from file:/home/vcap/app/wlp/usr/shared/config/lib/global/kafka-clients-0.10.0.1.jar by com.ibm.ws.classloading.internal.AppClassLoader#7a0d5027) called from class com.ibm.b2b.msghub.helper.AbstractB2BConsumer (loaded from file:/home/vcap/app/wlp/usr/shared/config/lib/global/B2BBlueMixLib-1.0.jar by com.ibm.ws.classloading.internal.AppClassLoader#7a0d5027).
Madhu
The client API has slightly changed between Kafka 0.9 and 0.10.
The definition of KafkaConsumer.subscribe() has changed. The first argument is now of type Collection instead of List.
This was done to make the API more consistent as now most (all?) calls take a Collection object whereas before it was a mix of several types.

Spring on WebSphere 8: Quartz job with web service call throws JAXBException "<class> is not known to this context"

I'm facing a JAXBException " is not known to this context" when calling a web service from within a job controlled by Quartz on Spring:
javax.xml.ws.WebServiceException: javax.xml.bind.JAXBException: com.xxxx.yyyy.zzzz.ImageMetaData is not known to this context
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMinimalMethodMarshaller.demarshalResponse(DocLitWrappedMinimalMethodMarshaller.java:624)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:593)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:432)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:213)
at com.sun.proxy.$Proxy299.findAllImageMetaData(Unknown Source)
I'm having a Spring 3.2.4 Java EE application with JSF running on IBM WebSphere v8.
When calling a specific web service from the JSF part of the application (i.e. from an action or a service), everything's ok.
The exception occurs only when the call is done from within a Quartz/Spring triggered job.
Executing exacty the same job code from the action does not result in an exception.
I tried a lot of different things like using a corresponding #XmlSeeAlso annotation in the JAXB generated classes but even using the annotation in the webservice interface itself does not solve the issue.
I also updated the Spring and Quartz libraries to more recent versions but this didn't help.
Anyone any idea?
I've finally solved the issue.
After much analysis I encountered the following issue in the Spring framework:
https://jira.spring.io/i#browse/SPR-11125
When a job is triggered via Spring/Quartz on WebSphere, the wrong ContextClassLoader is set.
This may cause many different problems - among them is the JAXBException as described.
The Spring bug is still open - so as a workaround I had to overwrite the context class loader of the current thread by the correct one:
ClassLoader cl = invoiceService.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
The correct class loader can be simply retrieved by a class that has been loaded by the container. Using this class loader as the context class loader for the current thread solved my issue.

Is there a way to use the ActiveMQ Ajax servlet with Tomee?

Is there a way to use the ActiveMQ Ajax servlet with Tomee?
This documentation page implies that it "just works": http://activemq.apache.org/tomee.html
But, elsewhere, it is made clear that the servlet depends upon Jetty: http://activemq.2283324.n4.nabble.com/AjaxServlet-on-Tomcat-td3601798.html. Note that user Hexaplus says he/she got it working by including the Jetty libraries.
I have not had success following Hexaplus's instructions; I get the following error stacktrace
SEVERE: Servlet.service() for servlet [AjaxServlet] in context with path [/myapp] threw exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1673)
at org.apache.catalina.connector.Request.startAsync(Request.java:1666)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1023)
at org.eclipse.jetty.continuation.Servlet3Continuation.suspend(Servlet3Continuation.java:202)
at org.apache.activemq.web.MessageListenerServlet.doMessages(MessageListenerServlet.java:326)
at org.apache.activemq.web.MessageListenerServlet.doGet(MessageListenerServlet.java:246)
at org.apache.activemq.web.AjaxServlet.doGet(AjaxServlet.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
Other people report the same problem, for example: (can't post more than 2 links)
http://mail-archives.apache.org/mod_mbox/activemq-users/201302.mbox/%3C1359730513047-4662633.post#n4.nabble.com%3E

tomcat7, spring 3.0.5, errors, contexts

org.springframework.web.context.ContextLoader, in the event of an exception, does:
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
which looks quite useful, except the servlet context object it is making this call on is not connected, in any way that I can find, to the return value from Tomcat.addWebapp. So when I go looking for this attribute to see whether the startup worked right, I'm thwarted.
Is there a way to connect these two contexts?
Tomcat's documentation says you can get ServletContext from web-app's Context:
ServletContext getServletContext()
See JavaDoc on Context.

Resources