I have a simple route:
public class PartnerRoute extends SpringRouteBuilder
{
#Value("${comm.async.req.incoming.queue}")
private String reqInputQueue;
#Override
public void configure() throws Exception
{
onException(Exception.class)
.to("activemq:queue:wrongMessages");
from("cxf:bean:partnerService")
.log("PartnerData arrived")
.to("activemq:queue:" + reqInputQueue);
}
}
As you see, the start point is a CXF webservice.
The WS defined in camel-context.xml
<cxf:cxfEndpoint id="partnerService"
address="http://${comm.host}:${comm.port}/cxf/PartnerService"
serviceClass="esb.ws.partner.service.PartnerService" />
I would like to handling the CXF exception. (Someone calls the WS with wrong data.)
I have got this error, when I call the WS with wron structure:
2015-02-26 16:16:44,901 | WARN | org.apache.cxf.phase.PhaseInterceptorChain | org.apache.cxf.cxf-api | (LogUtils.java:452) | Interceptor for {http://service.partner.ws.esb.ivir.tsm.hu/}PartnerServiceService#{http://service.partner.ws.esb.ivir.tsm.hu/}startMessageProcessing has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"messageFilterx"). Expected elements are <{}messageFilter>,<{}hash>,<{}priority>,<{}referenceNumber>,<{}responseRequired>,<{}requestDate>,<{}messageType>,<{}consumer>,<{}requestor>
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:881)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:702)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:160)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:192)[135:org.apache.cxf.cxf-api:2.7.11]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[135:org.apache.cxf.cxf-api:2.7.11]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[135:org.apache.cxf.cxf-api:2.7.11]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)[157:org.apache.cxf.cxf-rt-transports-http-jetty:2.7.11]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)[157:org.apache.cxf.cxf-rt-transports-http-jetty:2.7.11]
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:65)[157:org.apache.cxf.cxf-rt-transports-http-jetty:2.7.11]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.Server.handle(Server.java:370)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[63:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
at java.lang.Thread.run(Thread.java:744)[:1.7.0_51]
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"messageFilterx"). Expected elements are <{}messageFilter>,<{}hash>,<{}priority>,<{}referenceNumber>,<{}responseRequired>,<{}requestDate>,<{}messageType>,<{}consumer>,<{}requestor>]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:842)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:101)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
at org.apache.cxf.jaxb.JAXBEncoderDecoder$2.run(JAXBEncoderDecoder.java:870)
at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_51]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:868)[139:org.apache.cxf.cxf-rt-databinding-jaxb:2.7.11]
... 25 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"messageFilterx"). Expected elements are <{}messageFilter>,<{}hash>,<{}priority>,<{}referenceNumber>,<{}responseRequired>,<{}requestDate>,<{}messageType>,<{}consumer>,<{}requestor>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:243)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)[84:org.apache.servicemix.bundles.jaxb-impl:2.2.1.1_2]
... 31 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"messageFilterx"). Expected elements are <{}messageFilter>,<{}hash>,<{}priority>,<{}referenceNumber>,<{}responseRequired>,<{}requestDate>,<{}messageType>,<{}consumer>,<{}requestor>
... 42 more
I set up the "onException" but nothing happened.
Could you help, how can I handling that exception?
Thank you!
Feri
Its a chicken and egg situation. Camel's error handler using onException or errorHandler is during routing. But that entails the consumer is able to accept the incoming message and create a Camel Exchange instance and start route the message.
From the stracktrace this is not the case, as Apache CXF fails to do so. Some Camel components support bridging from the consumer errors to Camel error handler using consumer.bridgeErrorHandler=true option. Not sure if that is the case with CXF.
If you don't want the Exception to go any further, you need to mark it as handled.
onException(Exception.class)
.handled(true)
.to("activemq:queue:wrongMessages");
Related
I am using CXF (cxf-rt-frontend-jaxws, version 3.0.1) to create a web service client from a wsdl url like so:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(url.toString());
factory.setServiceClass(MyServicePort.class);
Object service = factory.create();
However, the call to factory.create() throws a NullPointerException with the following stack trace:
[main] INFO org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean - Creating Service {http://interfaces.project.domain.com/webservice}MyServicePortService from class com.domain.project.webservice.MyServicePort
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at org.apache.cxf.binding.soap.SoapBindingFactory.createSoapBinding(SoapBindingFactory.java:219)
at org.apache.cxf.binding.soap.SoapBindingFactory.createBindingInfo(SoapBindingFactory.java:206)
at org.apache.cxf.binding.AbstractBindingFactory.createBindingInfo(AbstractBindingFactory.java:83)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:341)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:259)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:144)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
The url that I pass to setAddress is of the form: http://host:port/path/to/service?wsdl. I have verified that it is up by doing a curl against that url and getting what I would expect in return.
From inspecting the code on grepcode, it would appear that the exception comes from a null WSDLManager returned from:
bs.getExtension(WSDLManager.class);
... the code for which, I believe is here. And that's where my ability to debug this breaks down.
Any ideas what could be causing CXF to throw the NullPointerException?
We have an Axis2 service running under Tomcat 7. Has anyone seen this
strange exception before?
org.apache.axis2.AxisFault: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,8783]
Message: The content of elements must consist of well-formed character data or markup.
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at omni.web.nms.ws.OmniWebNMSWSStub.fromOM(OmniWebNMSWSStub.java:13816)
at omni.web.nms.ws.OmniWebNMSWSStub.gettingSlotStatusFor1U(OmniWebNMSWSStub.java:29910)
at omni.web.nms.rack1u.TimerFor1uRack.getAllSlotDetailsFromDB(TimerFor1uRack.java:354)
at omni.web.nms.rack1u.TimerFor1uRack.run(TimerFor1uRack.java:119)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: org.apache.axiom.om.impl.exception.OMStreamingException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,8783]
Message: The content of elements must consist of well-formed character data or markup.
at org.apache.axiom.om.impl.llom.SwitchingWrapper.getElementText(SwitchingWrapper.java:940)
at javax.xml.stream.util.StreamReaderDelegate.getElementText(StreamReaderDelegate.java:100)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.getElementText(XMLStreamReaderWrapper.java:100)
at org.apache.axiom.util.stax.debug.XMLStreamReaderValidator.getElementText(XMLStreamReaderValidator.java:75)
at omni.web.nms.ws.OmniWebNMSWSStub$ArrayOfString$Factory.parse(OmniWebNMSWSStub.java:5561)
at omni.web.nms.ws.OmniWebNMSWSStub$GettingSlotStatusFor1UResponse$Factory.parse(OmniWebNMSWSStub.java:25997)
at omni.web.nms.ws.OmniWebNMSWSStub.fromOM(OmniWebNMSWSStub.java:13789)
... 5 more
This was the same issue that i faced when deploying a Service in Axis 2.
add the axis 2 runtime in
Windows>>Preferences> webservice>> Axis2 preferences
and provide the Axis 2 installation directory
this tutorial helped me a lot
[http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jst.ws.axis2.ui.doc.user%2Ftopics%2Fcaxis2tover.html]
My CF9 application running on a windows server pops mail. When I attempt to retrieve the entire body of the message, I sometimes get the following error...
Error:
An exception occurred while retrieving mail.
The cause of this exception was: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart.
Location:
Line 335 in controllers\Submissions.cfc
Not sure if this is pertinent, but FYI every message will have an image attached and the whole process usually works fine. This problem is intermittent.
My Questions
Any idea what causes this?
Any idea how to catch and resolve this issue?
I suspect I'll need to drop down into java, but not sure where to start.
Code Fragments
<cfscript>
// setup variables array for all cfpop calls
CFPopAttributes = {
server = request.pop.server,
port = request.pop.port,
username = request.pop.username,
password = request.pop.password,
timeout = 300
};
</cfscript>
<cfpop
action="getall"
name="entireEmail"
uid="#uid#"
attachmentpath="#originalsPath#"
attributecollection="#CFPopAttributes#" // Line 335
generateuniquefilenames="true"
/>
NOTE: I added the comment "Line 335" above to communicate exactly where in the code the template is breaking. If I move the attributecollection up or down (before/after other attributes), the error always breaks at the attributecollection line.
Stack Trace
struct [Filtered - 1 of 8 keys hidden]
Detail: An exception occurred while invoking an event handler method from Application.cfc. The method name is: onRequest.
Message: Event handler exception.
RootCause:
[struct]
Detail: The cause of this exception was: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart.
Message: An exception occurred while retrieving mail.
RootCause:
[struct]
Message: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart
StackTrace: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.internet.MimeBodyPart
at coldfusion.mail.EmailTable.getAttachmentName(EmailTable.java:819)
at coldfusion.mail.EmailTable.populate(EmailTable.java:283)
at coldfusion.mail.PopImpl.getMails(PopImpl.java:241)
at coldfusion.tagext.net.PopTag$1.run(PopTag.java:433)
at java.security.AccessController.doPrivileged(Native Method)
at coldfusion.tagext.net.PopTag.doStartTag(PopTag.java:429)
at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2799)
at cfSubmissions2ecfc1952269377$funcGETEMAIL.runFunction(D:\home\wwwroot\controllers\Submissions.cfc:335)
The problem is the following:
When sending a mail in webapp running on Play framework 1.2.4 exception with following stack trace can be observed in logs:
Execution exception
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.libs.Mail.buildMessage(Mail.java:79)
at play.libs.Mail.send(Mail.java:35)
at play.mvc.Mailer.send(Mailer.java:347)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
The relevant part here is following:
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
which indicates that NullPointerException was thrown from constructor of play.exceptions.MailException (in 27th line). Source code of this constructor looks like the following:
public MailException(String message, Throwable cause) {
super(message, cause);
StackTraceElement element = getInterestingStrackTraceElement(cause);
if(element != null) {
ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName());
sourceFile = applicationClass.javaFile.relativePath(); // this line is 27th and NPE is thrown from here
source = Arrays.asList(applicationClass.javaSource.split("\n"));
line = element.getLineNumber();
}
}
So either applicationClass local variable or javaFile property is null. Could someone familiar with Play framework weird internals advise what can cause this problem?
Thanks a lot in advance
EDIT after Seb Cesbron answer
We also inspected play.libs.Mail.buildMessage(Mail.java:79) where it is clearly seen that from address is null, but after fixing that, similar exception popped up:
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.mvc.Mailer.send(Mailer.java:349)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
And there, play.mvc.Mailer.send method contains nearly 200 lines of code enclosed in try-catch block, so it got really tricky to find out what was the problem :)
Line 79 in Mail.java refers to a throw MailException because there is no from address.
The NullPointerException in MailException seems to show that there is no file associated to your mail. Are you sure that the file Mails/forgotPassword.html (or txt) exists ?
I'm getting an exception when displaying my jsp page that tries to invoke a function defined getCurrentlocation() in type Person.
The function is invoked by ${person.currentlocation} in the jsp file.
type Exception report
message javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
I am pretty new to jsp technology. Maybe someone could help me out!
Thanks,
Benjamin
This particular ELException is a wrapper exception. This is usually only thrown when invoking the getter method itself has thrown an exception. Something like the following is happening under the covers when this ELException is been thrown:
Object bean;
String property;
Method getter;
// ...
try {
getter.invoke(bean);
} catch (Exception e) {
String message = String.format("Error reading '%s' on type %s", property, bean.getClass().getName());
throw new ELException(message, e);
}
You should look further down in the stacktrace for the real root cause. The complete stacktrace is usually just available in server logs. The real root cause is the bottommost exception of the stacktrace. E.g. the below one is caused by a NullPointerException being thrown in the getter method.
javax.el.ELException: Error reading 'currentlocation' on type **.person.Person
at ...
at ...
at ...
Caused by: java.lang.NullPointerException
at **.person.Person.getCurrentlocation(Person.java:42)
at ...
at ...
The information about the real root cause (the exception type and the line number) should give you enough clues to nail down the problem.
Again, this is not a problem with EL in general. It's just your own code which caused the problem.