You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nono <ya...@db-is.com> on 2014/01/26 12:23:32 UTC

camel-cxf , return complex type object problem

Dear all, 

I encounter a camel-cxf  's cxf:bean problem 
it seems , it works with return type as Pojo but failed with List<Pojo>
I got exception at karaf like Below. Could anyone give some hints? 

Thanks in advance! 

WARNING: Interceptor for
{http://ws.foo.com/}FileServiceService#{http://ws.foo.com/}getfiles has
thrown exception, unwinding now 
org.apache.cxf.interceptor.Fault 
            at
org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(AbstractWrapperHelper.java:107) 
            at
org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:105) 
            at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) 
            at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77) 
            at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:26 


Below are my blueprint and example code 
################################################################## 
define web service Endpoint 
  <camelcxf:cxfEndpoint id="fileService" 
                         
wsdlURL="classpath:/META-INF/wsdl/FileServiceService.wsdl" 
                          address="http://localhost:8080/foo/file"  
                          serviceClass="com.foo.ws.FileService">
    </camelcxf:cxfEndpoint>
  
  //define route , using cxf:bean , the real web service will be implemented
by 
com.foo.camel.FileProcessor 

<bean id="fp" class="com.foo.camel.FileProcessor" >
    </bean>

  <route id="files">
            <from  uri="cxf:bean:fileService" />
            <to    uri="bean:fp" />
        </route>


public class FileProcessor implements Processor { 
    @Override 
    public void process(Exchange exchng) throws Exception { 
        
          // 
              ....... 

           it works with return type as pojo but failed with List<Pojo>

          //           
         List<FilePojo> fileList = results; 

          
         exchng.getOut().setBody( fileList ); 
        } catch (Exception e) { 

            throw new FileNotFoundException("Something goes wrong in "
+this.getClass().getName(), e); 
        } 
    } 

} 

// proxy web serivce, cxf:bean refers to it 

import javax.jws.WebMethod; 
import javax.jws.WebParam; 
import javax.jws.WebResult; 
import javax.jws.WebService; 
import java.util.List; 
/** 
 * 
 */ 
@WebService 
public class FileService { 

    /** 
     * Web service operation 
     */ 
    @WebMethod(operationName = "getfile") 
    @WebResult(name = "file") 
    public ReceivedPDF getfile(@WebParam(name = "fileName") String fileName)
throws Exception{ 
        //TODO write your implementation code here: 
        
        return null; 
    } 

    /** 
     * Web service operation 
     */ 
    @WebMethod(operationName = "getfiles") 
    @WebResult(name = "files") 
    public List<FilePojo> getfiles(@WebParam(name = "fileNames")
List<String> fileNames) throws Exception{ 
        
        return null; 
    } 
    
    
    
    
} 



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
 Hi Willem,

Thanks for the reply and CNY greetings. 

List and array wrapper are both working, i just unisntall and install bundle
on fuse esb and test again. it is ok now :-)         
  List<String> names = (List<String>) msgList.get(0); 
            ArrayList<Person> pls = new ArrayList<Person>(); 
            for (String s : names) { 
                Person p = new Person(); 
                p.setName(s); 
                pls.add(p); 
            } 
            ArrayList wrapperList = new ArrayList(); 
            wrapperList.add(pls); 
            Object[] wrapperArray = new Object[]{pls}; 
            exchng.getOut().setBody(wrapperArray); 
            // exchng.getOut().setBody(wrapperList);



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746636.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by Willem Jiang <wi...@gmail.com>.
Hi nono,

I just ran a test with a simple echo invocation.
                        // Get the parameter list
                        List<?> parameter = in.getBody(List.class);
                        // Get the operation name
                        String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
                        Object result = operation + " " + (String)parameter.get(0);
                        // Put the result back as a Array
                        Object[] results = new Object[]{result};
                        exchange.getOut().setBody(results);

May be you can share your stack trace and test case here.

 
新春快乐!

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com(http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com(http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On January 29, 2014 at 6:03:01 PM, nono (yan.wang@db-is.com) wrote:
>  
> Hi Willem,
>  
> sorry. i tried again. does not work for me
> could you please post your workable sample test here?
>  
> Thanks!
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746595.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.  
>  


Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
Hi  Willem,

sorry. i tried again. does not work for me
could you please post your workable sample test here?

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746595.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

I just did a simple test, setting the result into an Object Array works as expect.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com(http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com(http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On January 29, 2014 at 2:49:25 PM, nono (yan.wang@db-is.com) wrote:
>  
> Hi
> It worked with List , but failed with Array.
>  
>  
> ArrayList pls = new ArrayList();
> for (String s : names) {
> Person p = new Person();
> p.setName(s);
> pls.add(p);
> }
> ArrayList wrapperList = new ArrayList();
> wrapperList.add(pls);
> Object[] objs = new Object[]{pls};
> exchng.getOut().setBody(objs);
> // exchng.getOut().setBody(wrapperList);
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746573.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.  
>  


Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
Hi 
It worked with List , but failed with Array.


 ArrayList<Person> pls = new ArrayList<Person>();
            for (String s : names) {
                Person p = new Person();
                p.setName(s);
                pls.add(p);
            }
            ArrayList wrapperList = new ArrayList();
            wrapperList.add(pls);
            Object[] objs = new Object[]{pls};
            exchng.getOut().setBody(objs);
            // exchng.getOut().setBody(wrapperList);



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746573.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by Willem Jiang <wi...@gmail.com>.
Yes, you are right.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com(http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com(http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On January 28, 2014 at 7:24:46 PM, nono (yan.wang@db-is.com) wrote:
>  
> you mean i need to do something like this?
>  
> ArrayList wraplist=new new ArrayList();
> wraplist.add(fileList );
> exchng.getOut().setBody( wraplist);
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746531.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.  
>  


Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
you mean i need to do something like this?

 ArrayList wraplist=new new ArrayList();
  wraplist.add(fileList );
  exchng.getOut().setBody( wraplist); 



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746531.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by "Willem.Jiang" <wi...@gmail.com>.
Hi,

For the CXF invocation, it need to return not only the invocation  result,
but also some out parameters, so we use a Array or List to story these
results. If you just set the body with a simple object, camel-cxf can wrap
it into a List, but if you put a list as a return object,  camel will not
wrap it. 

If you want to return a List object, you need to put the List object into an
array or a List.

Willem



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746513.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
here is same problem (with different test case). it works with return type
Pojo but failed with List<Pojo>
or Pojo[]; could it be fuse-esb problem??

20:35:41,671 | WARN  | qtp33362237-410  | PhaseInterceptorChain            |
147 - org.apache.cxf.cxf-api - 2.6.0.redhat-60024 | Interceptor for
{http://jaxws.cxf.examples.fuse.jboss.org/}HelloWorldImplService#{http://jaxws.cxf.examples.fuse.jboss.org/}getPersonList
has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
	at
org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(AbstractWrapperHelper.java:107)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:100)[160:org.apache.cxf.cxf-rt-frontend-jaxws:2.6.0.redhat-60024]
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:231)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)[147:org.apache.cxf.cxf-api:2.6.0.redhat-60024]
	at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:348)[172:org.apache.cxf.cxf-rt-transports-http-jetty:2.6.0.redhat-60024]
	at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:312)[172:org.apache.cxf.cxf-rt-transports-http-jetty:2.6.0.redhat-60024]
	at
org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)[172:org.apache.cxf.cxf-rt-transports-http-jetty:2.6.0.redhat-60024]
	at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1040)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:976)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:193)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.Server.handleAsync(Server.java:403)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:488)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)[79:org.eclipse.jetty.http:7.6.7.v20120910]
	at
org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[79:org.eclipse.jetty.http:7.6.7.v20120910]
	at
org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[84:org.eclipse.jetty.server:7.6.7.v20120910]
	at
org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)[81:org.eclipse.jetty.io:7.6.7.v20120910]
	at
org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)[81:org.eclipse.jetty.io:7.6.7.v20120910]
	at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[90:org.eclipse.jetty.util:7.6.7.v20120910]
	at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[90:org.eclipse.jetty.util:7.6.7.v20120910]
	at java.lang.Thread.run(Thread.java:724)[:1.7.0_40]




--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746509.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by nono <ya...@db-is.com>.
i just copied only top stack traces which is related.
the buttom part of stack traces looks irrelevent for me

Rgds



--
View this message in context: http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478p5746496.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-cxf , return complex type object problem

Posted by Richard Kettelerij <ri...@gmail.com>.
Are you sure this is the complete stacktrace? Look like some part is
missing.


On Sun, Jan 26, 2014 at 12:23 PM, nono <ya...@db-is.com> wrote:

> Dear all,
>
> I encounter a camel-cxf  's cxf:bean problem
> it seems , it works with return type as Pojo but failed with List<Pojo>
> I got exception at karaf like Below. Could anyone give some hints?
>
> Thanks in advance!
>
> WARNING: Interceptor for
> {http://ws.foo.com/}FileServiceService#{http://ws.foo.com/}getfiles has
> thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault
>             at
>
> org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(AbstractWrapperHelper.java:107)
>             at
>
> org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:105)
>             at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
>             at
>
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
>             at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:26
>
>
> Below are my blueprint and example code
> ##################################################################
> define web service Endpoint
>   <camelcxf:cxfEndpoint id="fileService"
>
> wsdlURL="classpath:/META-INF/wsdl/FileServiceService.wsdl"
>                           address="http://localhost:8080/foo/file"
>                           serviceClass="com.foo.ws.FileService">
>     </camelcxf:cxfEndpoint>
>
>   //define route , using cxf:bean , the real web service will be
> implemented
> by
> com.foo.camel.FileProcessor
>
> <bean id="fp" class="com.foo.camel.FileProcessor" >
>     </bean>
>
>   <route id="files">
>             <from  uri="cxf:bean:fileService" />
>             <to    uri="bean:fp" />
>         </route>
>
>
> public class FileProcessor implements Processor {
>     @Override
>     public void process(Exchange exchng) throws Exception {
>
>           //
>               .......
>
>            it works with return type as pojo but failed with List<Pojo>
>
>           //
>          List<FilePojo> fileList = results;
>
>
>          exchng.getOut().setBody( fileList );
>         } catch (Exception e) {
>
>             throw new FileNotFoundException("Something goes wrong in "
> +this.getClass().getName(), e);
>         }
>     }
>
> }
>
> // proxy web serivce, cxf:bean refers to it
>
> import javax.jws.WebMethod;
> import javax.jws.WebParam;
> import javax.jws.WebResult;
> import javax.jws.WebService;
> import java.util.List;
> /**
>  *
>  */
> @WebService
> public class FileService {
>
>     /**
>      * Web service operation
>      */
>     @WebMethod(operationName = "getfile")
>     @WebResult(name = "file")
>     public ReceivedPDF getfile(@WebParam(name = "fileName") String
> fileName)
> throws Exception{
>         //TODO write your implementation code here:
>
>         return null;
>     }
>
>     /**
>      * Web service operation
>      */
>     @WebMethod(operationName = "getfiles")
>     @WebResult(name = "files")
>     public List<FilePojo> getfiles(@WebParam(name = "fileNames")
> List<String> fileNames) throws Exception{
>
>         return null;
>     }
>
>
>
>
> }
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-cxf-return-complex-type-object-problem-tp5746478.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>