You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by yulinxp <yu...@gmail.com> on 2007/12/26 21:09:23 UTC

how to handle exception in CXF

I am trying to add in BusinessLogicException in the spring HelloWorld
example.
But I just can't get it work!! Below are the server/client stack-trace and
my files. 
Please help me!

----------------------
*server side

Dec 26, 2007 1:48:25 PM org.apache.cxf.phase.PhaseInterceptorChain
doIntercept
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: here BusinessLogicException_Exception...
        at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractIn
voker.java:107)
        at
org.apache.cxf.jaxws.JAXWSMethodInvoker.createFault(JAXWSMethodInvoke
r.java:76)
        at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker
.java:95)
        at
org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.jav
a:100)
        at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker
.java:68)
        at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInv
okerInterceptor.java:56)
        at
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecu
tor.java:37)
        at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(Se
rviceInvokerInterceptor.java:92)
        at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:207)
        at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainIniti
ationObserver.java:73)
        at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(Servlet
Destination.java:79)
        at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(
ServletController.java:256)
        at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletCont
roller.java:160)
        at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCX
FServlet.java:170)
        at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCX
FServlet.java:148)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:175)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:263)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:844)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:584)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: demo.spring.BusinessLogicException_Exception: here
BusinessLogicExcep
tion_Exception...
        at demo.spring.HelloWorldImpl.sayHi(HelloWorldImpl.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(Abst
ractInvoker.java:124)
        at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker
.java:82)
        ... 26 more
Dec 26, 2007 1:48:25 PM
org.apache.cxf.binding.soap.interceptor.Soap12FaultOutIn
terceptor handleMessage
INFO: class
org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptorapp
lication/soap+xml

*client side

INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: Could not parse message.
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:65)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:90)
	at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:179)
	at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:56)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:402)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1948)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1791)
	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:575)
	at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:205)
	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
	at $Proxy35.sayHi(Unknown Source)
	at demo.spring.client.Client.main(Client.java:46)
Caused by: com.ctc.wstx.exc.WstxParsingException: Received
non-all-whitespace CHARACTERS or CDATA event in nextTag().
 at [row,col {unknown-source}]: [1,127]
	at
com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:605)
	at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:461)
	at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1107)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:52)
	... 19 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not
parse message.
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:175)
	at $Proxy35.sayHi(Unknown Source)
	at demo.spring.client.Client.main(Client.java:46)
Caused by: org.apache.cxf.binding.soap.SoapFault: Could not parse message.
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:65)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:90)
	at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:179)
	at
org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:56)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:402)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1948)
	at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1791)
	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:575)
	at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:205)
	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
	... 2 more
Caused by: com.ctc.wstx.exc.WstxParsingException: Received
non-all-whitespace CHARACTERS or CDATA event in nextTag().
 at [row,col {unknown-source}]: [1,127]
	at
com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:605)
	at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:461)
	at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1107)
	at
org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:52)
	... 19 more
----------------------
@WebService(targetNamespace = "http://spring.demo/", name = "HelloWorld")

public interface HelloWorld {

    @ResponseWrapper(targetNamespace = "http://spring.demo/", className =
"demo.spring.SayHiResponse", localName = "sayHiResponse")
    @RequestWrapper(targetNamespace = "http://spring.demo/", className =
"demo.spring.SayHi", localName = "sayHi")
    @WebResult(targetNamespace = "http://spring.demo/", name = "return")
    @WebMethod
    public java.lang.String sayHi(
        @WebParam(targetNamespace = "http://spring.demo/", name = "arg0")
        java.lang.String arg0
    ) throws BusinessLogicException_Exception;
}

----------------------
@WebFault(name = "BusinessLogicException", targetNamespace =
"http://spring.demo/")

public class BusinessLogicException_Exception extends Exception {
    public static final long serialVersionUID = 20071226134020L;
    
    private demo.spring.BusinessLogicException businessLogicException;

    public BusinessLogicException_Exception() {
        super();
    }
    
    public BusinessLogicException_Exception(String message) {
        super(message);
    }
    
    public BusinessLogicException_Exception(String message, Throwable cause)
{
        super(message, cause);
    }

    public BusinessLogicException_Exception(String message,
demo.spring.BusinessLogicException businessLogicException) {
        super(message);
        this.businessLogicException = businessLogicException;
    }

    public BusinessLogicException_Exception(String message,
demo.spring.BusinessLogicException businessLogicException, Throwable cause)
{
        super(message, cause);
        this.businessLogicException = businessLogicException;
    }

    public demo.spring.BusinessLogicException getFaultInfo() {
        return this.businessLogicException;
    }
}

----------------------
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BusinessLogicException")
public class BusinessLogicException {
}

----------------------

@javax.jws.WebService(name = "HelloWorld", serviceName =
"HelloWorldService",
                      portName = "HelloWorldPort",
                      targetNamespace = "http://spring.demo/", 
                      wsdlLocation =
"file:/C:/Work/Application/apache-cxf-2.0.3-incubator/samples/JAX_WS_Fault/wsdl/HelloWorld.wsdl"
,
		      endpointInterface = "demo.spring.HelloWorld")
                      
public class HelloWorldImpl implements HelloWorld {

    private static final Logger LOG =
Logger.getLogger(HelloWorldImpl.class.getName());

    /* (non-Javadoc)
     * @see demo.spring.HelloWorld#sayHi(java.lang.String  arg0 )*
     */
    public java.lang.String sayHi(java.lang.String arg0) throws
BusinessLogicException_Exception    { 
        LOG.info("Executing operation sayHi");
        System.out.println(arg0);
        
        if(!arg0.equalsIgnoreCase("Fault")){
        	return "Hello " + arg0;
        }

        //throw new BusinessLogicException_Exception("here
BusinessLogicException_Exception...");        
        //throw new BusinessLogicException_Exception("look here" , new
BusinessLogicException());        
        throw new BusinessLogicException_Exception("look here" , new
BusinessLogicException(), new Throwable("here throwable"));
    }

}

----------------------

public final class Client {

    private Client() {
    }

    public static void main(String args[]){
        // START SNIPPET: client
        ClassPathXmlApplicationContext context 
            = new ClassPathXmlApplicationContext(new String[]
{"demo/spring/client/client-beans.xml"});

        HelloWorld client = (HelloWorld)context.getBean("client");
        
        String response;
		try {
			response = client.sayHi("Fault");
			System.out.println("Response: " + response);
		} catch (BusinessLogicException_Exception e) {
			// TODO Auto-generated catch block
			System.out.println("client receive exception");
			e.printStackTrace();
		}
        // END SNIPPET: client
    }
}


-- 
View this message in context: http://www.nabble.com/how-to-handle-exception-in-CXF-tp14505864p14505864.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: how to handle exception in CXF

Posted by yulinxp <yu...@gmail.com>.
I have figure out the reason. The reason is SOAP version not matched in
server/client side.
Here is the post for setting client use SOAP1.2
http://www.nabble.com/How-to-set-Soap-version-on-client-side-td14692146.html

Interesting, this only happens when Server side throws
exception(Soap12FaultOutInterceptor).
If server SOAP1.2 doesn't throw exception, Client SOAP1.1 can handle it.

--------------------------------------------------------------


yulinxp wrote:
> 
> In Eclipse, I was using SOAP1.2 for WSDL Generation Option. On Server
> side, I have the following error:
> 
> Dec 26, 2007 1:48:25 PM
> org.apache.cxf.binding.soap.interceptor.Soap12FaultOutIn
> terceptor handleMessage
> INFO: class
> org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptorapp
> lication/soap+xml
> 
> Everything works fine after I changed to use SOAP1.1. Now the question is
> why SOAP1.2 is not working for CXF?
> 

-- 
View this message in context: http://www.nabble.com/how-to-handle-exception-in-CXF-tp14505864p14698413.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: how to handle exception in CXF

Posted by yulinxp <yu...@gmail.com>.
In Eclipse, I was using SOAP1.2 for WSDL Generation Option. On Server side, I
have the following error:

Dec 26, 2007 1:48:25 PM
org.apache.cxf.binding.soap.interceptor.Soap12FaultOutIn
terceptor handleMessage
INFO: class
org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptorapp
lication/soap+xml

Everything works fine after I changed to use SOAP1.1. Now the question is
why SOAP1.2 is not working for CXF?
-- 
View this message in context: http://www.nabble.com/how-to-handle-exception-in-CXF-tp14505864p14580009.html
Sent from the cxf-user mailing list archive at Nabble.com.