You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Alex Labad <al...@gmail.com> on 2010/08/12 14:13:05 UTC

Empty beans generated by Cxf using dynamic client

Hi all!



I have a weird problem with cxf invoking external services: I can handle the
simple ones through the simple DynamicClientFactory, generating the Client
and invoking the services, it is ok.



The problem comes with the Object parameters:

In this case, the client generates the Beans, I fill them through
introspection, check the values as well, but when sending the parameter, in
the server, it just receives an empty bean...



Calling it from SoapUI, it works perfectly

Calling from java: It doesn�t reveive anything (it receives a SimpleBean,
but null when calling the getName or getSurname).

Any help? Ideas? Will be veeeery welcome!!! (Thanks in advance!!!!)



Easier with the code? Here it is: (Attached is the WSDL)



The Service: I did it with Axis2, for dynamic client testing . Where
SimpleBean is just a POJO with name and surname attributes, and their getter
and setters.



*public* String secondObject(SimpleBean simpleBean) {

            *if* (simpleBean != *null*) {

                  *if* (simpleBean *instanceof* SimpleBean) {

                  System.*out*.println("ES UNA simpleBean BEAN");

                  System.*out*.println("name: " +simpleBean.getName());

                  System.*out*.println("surname: "+simpleBean.getSurname());



            }

                  *return* simpleBean.getName()  + " ------------ " +
simpleBean.getSurname();

            }

            *return* "No input provided";

      }



And the JavaCode to call to the service



JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.*newInstance*
();

String methodName=�secondObject�;

      List<String> bindingFiles = *new* ArrayList<String>();

     bindingFiles.add("javabindings.xml");

                Client clientImpl = factory.createClient(wsdlUrl, Thread.*
currentThread*().getContextClassLoader(), bindingFiles);



      Endpoint endpoint = clientImpl.getEndpoint();

      ServiceInfo serviceInfo =
endpoint.getService().getServiceInfos().get(0);

      QName bindingName = *null*;



                  *for* (BindingInfo binfo : serviceInfo.getBindings()) {

                        *if* (binfo.getName().getLocalPart().indexOf(
"Soap11") > -1) {

                             bindingName = binfo.getName();

                        }

                  }



                  BindingInfo binding = serviceInfo.getBinding(bindingName);

                  BindingOperationInfo operationToBeInvoked = *null*;



                  *for* (BindingOperationInfo operation :
binding.getOperations()) {


*if*(methodName.equals(operation.getName().getLocalPart())) {

                             operationToBeInvoked = operation;

                        }

                  }



                  *if* (operationToBeInvoked == *null*) {

                        *throw* *new* NoSuchMethodException(methodName);

                  }



                  System.*out*.println("Invoke, operation info: " +
operationToBeInvoked );



                  BindingMessageInfo inputMessageInfo;



                  *if* (!operationToBeInvoked.isUnwrapped()) {

                        //Operation uses document literal wrapped style.

                        inputMessageInfo =
operationToBeInvoked.getWrappedOperation().getInput();

                  } *else* {

                        inputMessageInfo =
operationToBeInvoked.getUnwrappedOperation().getInput();

                  }



                  List<MessagePartInfo> parts =
inputMessageInfo.getMessageParts();

                  *if* (parts.isEmpty()) {

                        System.*out*.println("parts is empty. No message !"
);

                  } *else* {

                        MessagePartInfo partInfo = parts.get(0); // Input
class is Order

                        // Get the input class Order

                        Class<?> param1Class = partInfo.getTypeClass();



                        System.*out*.println("param1 is of Type: " +
param1Class.getCanonicalName());





                              Object myObject = *create*
(param1Class.getCanonicalName());

                             Method theMethod =
myObject.getClass().getMethod("setTask", String.*class*);

                             theMethod.invoke(myObject, "value1");

                             Method theDayMethod =
myObject.getClass().getMethod("setTheDay", String.*class*);

                             theDayMethod.invoke(myObject, "value2");



                              System.*out*.println("Testing the income.");

                             Method getter1 = myObject.getClass().getMethod(
"getTask", *null*);

                             System.*out*.println(getter1.invoke(myObject, *
null*));

                             Method getter2 = myObject.getClass().getMethod(
"getTheDay", *null*);

                             System.*out*.println(getter2.invoke(myObject, *
null*));



                             Object[] response =
clientImpl.invoke(operationToBeInvoked, myObject);

                             *return* *parseResponse*(response);

                 }

Re: Empty beans generated by Cxf using dynamic client

Posted by Alex Labad <al...@gmail.com>.
Yes, it helps.

Thanks again. I own you one!
Alex

2010/8/17 Daniel Kulp <dk...@apache.org>

> On Tuesday 17 August 2010 1:59:41 am Alex Labad wrote:
> > WOW, like a charm!!!
> >
> > Thanks, really really thanks. I have been trying for a long time before
> > crying for help!!!
> >
> > so.. summing up:
> >
> > when using BOI, the wrapped form is required.
>
> No, when using the BOI, you need to use the from that the BOI is in.  If
> you
> would have done:
>
> boi = boi.getUnwrappedOperation()
>
> to get the unwrapped BOI, then it probably would have also worked.   By
> default, the BOI's returned from the BindingInfo would be the wrapped form
> (as
> it appears in the WSDL).   To use the unwrapped form, you would need to
> pull
> that out.
>
> > As an alternative, we can use
> > the operationName and the wrapped Object as parameters for the invoke
> > operation...
>
> When using the operation name, it would use the form that normal
> "wsdl2java"
> would have generated.  In this case, it would be the unwrapped form.
> However, the client DOES have invokeWrapped(name, ..) if you want to force
> it
> to use the wrapped version.
>
>
> > Am I right? I'm not 100% sure that I got it understood.... but very
> > grateful, anyway.
>
> Hope the above helps.
>
> Dan
>
>
> >
> >
> >
> >
> >
> > 2010/8/16 Daniel Kulp <dk...@apache.org>
> >
> > > I THINK your calls into the opInfo around:
> > > if (!operationToBeInvoked.isUnwrapped()) {
> > >
> > > may be confusing things.  If passing the BindingOperationInfo into the
> > > invoke,
> > > you have to use the input message for the BOI, not it's unwrapped form.
> > >
> > > To check this, change the line:
> > > clientImpl.invoke(operationToBeInvoked, myObject);
> > > to
> > > clientImpl.invoke("objectInput", myObject);
> > > and see if that helps at all.
> > >
> > >
> > > Dan
> > >
> > > On Thursday 12 August 2010 8:13:05 am Alex Labad wrote:
> > > > Hi all!
> > > >
> > > >
> > > >
> > > > I have a weird problem with cxf invoking external services: I can
> > > > handle the simple ones through the simple DynamicClientFactory,
> > > > generating the Client and invoking the services, it is ok.
> > > >
> > > >
> > > >
> > > > The problem comes with the Object parameters:
> > > >
> > > > In this case, the client generates the Beans, I fill them through
> > > > introspection, check the values as well, but when sending the
> > > > parameter,
> > >
> > > in
> > >
> > > > the server, it just receives an empty bean...
> > > >
> > > >
> > > >
> > > > Calling it from SoapUI, it works perfectly
> > > >
> > > > Calling from java: It doesn’t reveive anything (it receives a
> > > > SimpleBean, but null when calling the getName or getSurname).
> > > >
> > > > Any help? Ideas? Will be veeeery welcome!!! (Thanks in advance!!!!)
> > > >
> > > >
> > > >
> > > > Easier with the code? Here it is: (Attached is the WSDL)
> > > >
> > > >
> > > >
> > > > The Service: I did it with Axis2, for dynamic client testing . Where
> > > > SimpleBean is just a POJO with name and surname attributes, and their
> > > > getter and setters.
> > > >
> > > >
> > > >
> > > > *public* String secondObject(SimpleBean simpleBean) {
> > > >
> > > >             *if* (simpleBean != *null*) {
> > > >
> > > >                   *if* (simpleBean *instanceof* SimpleBean) {
> > > >
> > > >                   System.*out*.println("ES UNA simpleBean BEAN");
> > > >
> > > >                   System.*out*.println("name: "
> +simpleBean.getName());
> > > >
> > > >                   System.*out*.println("surname:
> > > > "+simpleBean.getSurname());
> > > >
> > > >             }
> > > >
> > > >                   *return* simpleBean.getName()  + " ------------ " +
> > > >
> > > > simpleBean.getSurname();
> > > >
> > > >             }
> > > >
> > > >             *return* "No input provided";
> > > >
> > > >       }
> > > >
> > > > And the JavaCode to call to the service
> > > >
> > > >
> > > >
> > > > JaxWsDynamicClientFactory factory =
> > >
> > > JaxWsDynamicClientFactory.*newInstance*
> > >
> > > > ();
> > > >
> > > > String methodName=”secondObject”;
> > > >
> > > >       List<String> bindingFiles = *new* ArrayList<String>();
> > > >
> > > >      bindingFiles.add("javabindings.xml");
> > > >
> > > >                 Client clientImpl = factory.createClient(wsdlUrl,
> > >
> > > Thread.*
> > >
> > > > currentThread*().getContextClassLoader(), bindingFiles);
> > > >
> > > >       Endpoint endpoint = clientImpl.getEndpoint();
> > > >
> > > >       ServiceInfo serviceInfo =
> > > >
> > > > endpoint.getService().getServiceInfos().get(0);
> > > >
> > > >       QName bindingName = *null*;
> > > >
> > > >                   *for* (BindingInfo binfo :
> serviceInfo.getBindings())
> > > >                   {
> > > >
> > > >                         *if* (binfo.getName().getLocalPart().indexOf(
> > > >
> > > > "Soap11") > -1) {
> > > >
> > > >                              bindingName = binfo.getName();
> > > >
> > > >                         }
> > > >
> > > >                   }
> > > >
> > > >
> > > >
> > > >                   BindingInfo binding =
> > > >
> > > > serviceInfo.getBinding(bindingName);
> > > >
> > > >                   BindingOperationInfo operationToBeInvoked = *null*;
> > > >
> > > >                   *for* (BindingOperationInfo operation :
> > > > binding.getOperations()) {
> > > >
> > > >
> > > > *if*(methodName.equals(operation.getName().getLocalPart())) {
> > > >
> > > >                              operationToBeInvoked = operation;
> > > >
> > > >                         }
> > > >
> > > >                   }
> > > >
> > > >
> > > >
> > > >                   *if* (operationToBeInvoked == *null*) {
> > > >
> > > >                         *throw* *new*
> > > >                         NoSuchMethodException(methodName);
> > > >
> > > >                   }
> > > >
> > > >
> > > >
> > > >                   System.*out*.println("Invoke, operation info: " +
> > > >
> > > > operationToBeInvoked );
> > > >
> > > >                   BindingMessageInfo inputMessageInfo;
> > > >
> > > >
> > > >
> > > >                   *if* (!operationToBeInvoked.isUnwrapped()) {
> > > >
> > > >                         //Operation uses document literal wrapped
> > > >                         style.
> > > >
> > > >                         inputMessageInfo =
> > > >
> > > > operationToBeInvoked.getWrappedOperation().getInput();
> > > >
> > > >                   } *else* {
> > > >
> > > >                         inputMessageInfo =
> > > >
> > > > operationToBeInvoked.getUnwrappedOperation().getInput();
> > > >
> > > >                   }
> > > >
> > > >
> > > >
> > > >                   List<MessagePartInfo> parts =
> > > >
> > > > inputMessageInfo.getMessageParts();
> > > >
> > > >                   *if* (parts.isEmpty()) {
> > > >
> > > >                         System.*out*.println("parts is empty. No
> > > >                         message
> > >
> > > !"
> > >
> > > > );
> > > >
> > > >                   } *else* {
> > > >
> > > >                         MessagePartInfo partInfo = parts.get(0); //
> > > >                         Input
> > > >
> > > > class is Order
> > > >
> > > >                         // Get the input class Order
> > > >
> > > >                         Class<?> param1Class =
> partInfo.getTypeClass();
> > > >
> > > >
> > > >
> > > >                         System.*out*.println("param1 is of Type: " +
> > > >
> > > > param1Class.getCanonicalName());
> > > >
> > > >                               Object myObject = *create*
> > > >
> > > > (param1Class.getCanonicalName());
> > > >
> > > >                              Method theMethod =
> > > >
> > > > myObject.getClass().getMethod("setTask", String.*class*);
> > > >
> > > >                              theMethod.invoke(myObject, "value1");
> > > >
> > > >                              Method theDayMethod =
> > > >
> > > > myObject.getClass().getMethod("setTheDay", String.*class*);
> > > >
> > > >                              theDayMethod.invoke(myObject, "value2");
> > > >
> > > >                               System.*out*.println("Testing the
> > >
> > > income.");
> > >
> > > >                              Method getter1 =
> > > >
> > > > myObject.getClass().getMethod( "getTask", *null*);
> > >
> > >  System.*out*.println(getter1.invoke(myObject,
> > >
> > > > * null*));
> > > >
> > > >                              Method getter2 =
> > > >
> > > > myObject.getClass().getMethod( "getTheDay", *null*);
> > >
> > >  System.*out*.println(getter2.invoke(myObject,
> > >
> > > > * null*));
> > > >
> > > >                              Object[] response =
> > > >
> > > > clientImpl.invoke(operationToBeInvoked, myObject);
> > > >
> > > >                              *return* *parseResponse*(response);
> > > >
> > > >                  }
> > >
> > > --
> > > Daniel Kulp
> > > dkulp@apache.org
> > > http://dankulp.com/blog
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Empty beans generated by Cxf using dynamic client

Posted by Daniel Kulp <dk...@apache.org>.
On Tuesday 17 August 2010 1:59:41 am Alex Labad wrote:
> WOW, like a charm!!!
> 
> Thanks, really really thanks. I have been trying for a long time before
> crying for help!!!
> 
> so.. summing up:
> 
> when using BOI, the wrapped form is required.

No, when using the BOI, you need to use the from that the BOI is in.  If you 
would have done:

boi = boi.getUnwrappedOperation()

to get the unwrapped BOI, then it probably would have also worked.   By 
default, the BOI's returned from the BindingInfo would be the wrapped form (as 
it appears in the WSDL).   To use the unwrapped form, you would need to pull 
that out.

> As an alternative, we can use
> the operationName and the wrapped Object as parameters for the invoke
> operation...

When using the operation name, it would use the form that normal "wsdl2java" 
would have generated.  In this case, it would be the unwrapped form.   
However, the client DOES have invokeWrapped(name, ..) if you want to force it 
to use the wrapped version.


> Am I right? I'm not 100% sure that I got it understood.... but very
> grateful, anyway.

Hope the above helps.

Dan


> 
> 
> 
> 
> 
> 2010/8/16 Daniel Kulp <dk...@apache.org>
> 
> > I THINK your calls into the opInfo around:
> > if (!operationToBeInvoked.isUnwrapped()) {
> > 
> > may be confusing things.  If passing the BindingOperationInfo into the
> > invoke,
> > you have to use the input message for the BOI, not it's unwrapped form.
> > 
> > To check this, change the line:
> > clientImpl.invoke(operationToBeInvoked, myObject);
> > to
> > clientImpl.invoke("objectInput", myObject);
> > and see if that helps at all.
> > 
> > 
> > Dan
> > 
> > On Thursday 12 August 2010 8:13:05 am Alex Labad wrote:
> > > Hi all!
> > > 
> > > 
> > > 
> > > I have a weird problem with cxf invoking external services: I can
> > > handle the simple ones through the simple DynamicClientFactory,
> > > generating the Client and invoking the services, it is ok.
> > > 
> > > 
> > > 
> > > The problem comes with the Object parameters:
> > > 
> > > In this case, the client generates the Beans, I fill them through
> > > introspection, check the values as well, but when sending the
> > > parameter,
> > 
> > in
> > 
> > > the server, it just receives an empty bean...
> > > 
> > > 
> > > 
> > > Calling it from SoapUI, it works perfectly
> > > 
> > > Calling from java: It doesn’t reveive anything (it receives a
> > > SimpleBean, but null when calling the getName or getSurname).
> > > 
> > > Any help? Ideas? Will be veeeery welcome!!! (Thanks in advance!!!!)
> > > 
> > > 
> > > 
> > > Easier with the code? Here it is: (Attached is the WSDL)
> > > 
> > > 
> > > 
> > > The Service: I did it with Axis2, for dynamic client testing . Where
> > > SimpleBean is just a POJO with name and surname attributes, and their
> > > getter and setters.
> > > 
> > > 
> > > 
> > > *public* String secondObject(SimpleBean simpleBean) {
> > > 
> > >             *if* (simpleBean != *null*) {
> > >             
> > >                   *if* (simpleBean *instanceof* SimpleBean) {
> > >                   
> > >                   System.*out*.println("ES UNA simpleBean BEAN");
> > >                   
> > >                   System.*out*.println("name: " +simpleBean.getName());
> > > 
> > >                   System.*out*.println("surname:
> > > "+simpleBean.getSurname());
> > > 
> > >             }
> > >             
> > >                   *return* simpleBean.getName()  + " ------------ " +
> > > 
> > > simpleBean.getSurname();
> > > 
> > >             }
> > >             
> > >             *return* "No input provided";
> > >       
> > >       }
> > > 
> > > And the JavaCode to call to the service
> > > 
> > > 
> > > 
> > > JaxWsDynamicClientFactory factory =
> > 
> > JaxWsDynamicClientFactory.*newInstance*
> > 
> > > ();
> > > 
> > > String methodName=”secondObject”;
> > > 
> > >       List<String> bindingFiles = *new* ArrayList<String>();
> > >      
> > >      bindingFiles.add("javabindings.xml");
> > >      
> > >                 Client clientImpl = factory.createClient(wsdlUrl,
> > 
> > Thread.*
> > 
> > > currentThread*().getContextClassLoader(), bindingFiles);
> > > 
> > >       Endpoint endpoint = clientImpl.getEndpoint();
> > >       
> > >       ServiceInfo serviceInfo =
> > > 
> > > endpoint.getService().getServiceInfos().get(0);
> > > 
> > >       QName bindingName = *null*;
> > >       
> > >                   *for* (BindingInfo binfo : serviceInfo.getBindings())
> > >                   {
> > >                   
> > >                         *if* (binfo.getName().getLocalPart().indexOf(
> > > 
> > > "Soap11") > -1) {
> > > 
> > >                              bindingName = binfo.getName();
> > >                         
> > >                         }
> > >                   
> > >                   }
> > >                   
> > >                   
> > >                   
> > >                   BindingInfo binding =
> > > 
> > > serviceInfo.getBinding(bindingName);
> > > 
> > >                   BindingOperationInfo operationToBeInvoked = *null*;
> > > 
> > >                   *for* (BindingOperationInfo operation :
> > > binding.getOperations()) {
> > > 
> > > 
> > > *if*(methodName.equals(operation.getName().getLocalPart())) {
> > > 
> > >                              operationToBeInvoked = operation;
> > >                         
> > >                         }
> > >                   
> > >                   }
> > >                   
> > >                   
> > >                   
> > >                   *if* (operationToBeInvoked == *null*) {
> > >                   
> > >                         *throw* *new*
> > >                         NoSuchMethodException(methodName);
> > >                   
> > >                   }
> > >                   
> > >                   
> > >                   
> > >                   System.*out*.println("Invoke, operation info: " +
> > > 
> > > operationToBeInvoked );
> > > 
> > >                   BindingMessageInfo inputMessageInfo;
> > >                   
> > >                   
> > >                   
> > >                   *if* (!operationToBeInvoked.isUnwrapped()) {
> > >                   
> > >                         //Operation uses document literal wrapped
> > >                         style.
> > >                         
> > >                         inputMessageInfo =
> > > 
> > > operationToBeInvoked.getWrappedOperation().getInput();
> > > 
> > >                   } *else* {
> > >                   
> > >                         inputMessageInfo =
> > > 
> > > operationToBeInvoked.getUnwrappedOperation().getInput();
> > > 
> > >                   }
> > >                   
> > >                   
> > >                   
> > >                   List<MessagePartInfo> parts =
> > > 
> > > inputMessageInfo.getMessageParts();
> > > 
> > >                   *if* (parts.isEmpty()) {
> > >                   
> > >                         System.*out*.println("parts is empty. No
> > >                         message
> > 
> > !"
> > 
> > > );
> > > 
> > >                   } *else* {
> > >                   
> > >                         MessagePartInfo partInfo = parts.get(0); //
> > >                         Input
> > > 
> > > class is Order
> > > 
> > >                         // Get the input class Order
> > >                         
> > >                         Class<?> param1Class = partInfo.getTypeClass();
> > >                         
> > >                         
> > >                         
> > >                         System.*out*.println("param1 is of Type: " +
> > > 
> > > param1Class.getCanonicalName());
> > > 
> > >                               Object myObject = *create*
> > > 
> > > (param1Class.getCanonicalName());
> > > 
> > >                              Method theMethod =
> > > 
> > > myObject.getClass().getMethod("setTask", String.*class*);
> > > 
> > >                              theMethod.invoke(myObject, "value1");
> > >                              
> > >                              Method theDayMethod =
> > > 
> > > myObject.getClass().getMethod("setTheDay", String.*class*);
> > > 
> > >                              theDayMethod.invoke(myObject, "value2");
> > >                              
> > >                               System.*out*.println("Testing the
> > 
> > income.");
> > 
> > >                              Method getter1 =
> > > 
> > > myObject.getClass().getMethod( "getTask", *null*);
> >  
> >  System.*out*.println(getter1.invoke(myObject,
> >  
> > > * null*));
> > > 
> > >                              Method getter2 =
> > > 
> > > myObject.getClass().getMethod( "getTheDay", *null*);
> >  
> >  System.*out*.println(getter2.invoke(myObject,
> >  
> > > * null*));
> > > 
> > >                              Object[] response =
> > > 
> > > clientImpl.invoke(operationToBeInvoked, myObject);
> > > 
> > >                              *return* *parseResponse*(response);
> > >                  
> > >                  }
> > 
> > --
> > Daniel Kulp
> > dkulp@apache.org
> > http://dankulp.com/blog

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: Empty beans generated by Cxf using dynamic client

Posted by Alex Labad <al...@gmail.com>.
WOW, like a charm!!!

Thanks, really really thanks. I have been trying for a long time before
crying for help!!!

so.. summing up:

when using BOI, the wrapped form is required. As an alternative, we can use
the operationName and the wrapped Object as parameters for the invoke
operation...

Am I right? I'm not 100% sure that I got it understood.... but very
grateful, anyway.





2010/8/16 Daniel Kulp <dk...@apache.org>

>
> I THINK your calls into the opInfo around:
> if (!operationToBeInvoked.isUnwrapped()) {
>
> may be confusing things.  If passing the BindingOperationInfo into the
> invoke,
> you have to use the input message for the BOI, not it's unwrapped form.
>
> To check this, change the line:
> clientImpl.invoke(operationToBeInvoked, myObject);
> to
> clientImpl.invoke("objectInput", myObject);
> and see if that helps at all.
>
>
> Dan
>
>
>
> On Thursday 12 August 2010 8:13:05 am Alex Labad wrote:
> > Hi all!
> >
> >
> >
> > I have a weird problem with cxf invoking external services: I can handle
> > the simple ones through the simple DynamicClientFactory, generating the
> > Client and invoking the services, it is ok.
> >
> >
> >
> > The problem comes with the Object parameters:
> >
> > In this case, the client generates the Beans, I fill them through
> > introspection, check the values as well, but when sending the parameter,
> in
> > the server, it just receives an empty bean...
> >
> >
> >
> > Calling it from SoapUI, it works perfectly
> >
> > Calling from java: It doesn’t reveive anything (it receives a SimpleBean,
> > but null when calling the getName or getSurname).
> >
> > Any help? Ideas? Will be veeeery welcome!!! (Thanks in advance!!!!)
> >
> >
> >
> > Easier with the code? Here it is: (Attached is the WSDL)
> >
> >
> >
> > The Service: I did it with Axis2, for dynamic client testing . Where
> > SimpleBean is just a POJO with name and surname attributes, and their
> > getter and setters.
> >
> >
> >
> > *public* String secondObject(SimpleBean simpleBean) {
> >
> >             *if* (simpleBean != *null*) {
> >
> >                   *if* (simpleBean *instanceof* SimpleBean) {
> >
> >                   System.*out*.println("ES UNA simpleBean BEAN");
> >
> >                   System.*out*.println("name: " +simpleBean.getName());
> >
> >                   System.*out*.println("surname:
> > "+simpleBean.getSurname());
> >
> >
> >
> >             }
> >
> >                   *return* simpleBean.getName()  + " ------------ " +
> > simpleBean.getSurname();
> >
> >             }
> >
> >             *return* "No input provided";
> >
> >       }
> >
> >
> >
> > And the JavaCode to call to the service
> >
> >
> >
> > JaxWsDynamicClientFactory factory =
> JaxWsDynamicClientFactory.*newInstance*
> > ();
> >
> > String methodName=”secondObject”;
> >
> >       List<String> bindingFiles = *new* ArrayList<String>();
> >
> >      bindingFiles.add("javabindings.xml");
> >
> >                 Client clientImpl = factory.createClient(wsdlUrl,
> Thread.*
> > currentThread*().getContextClassLoader(), bindingFiles);
> >
> >
> >
> >       Endpoint endpoint = clientImpl.getEndpoint();
> >
> >       ServiceInfo serviceInfo =
> > endpoint.getService().getServiceInfos().get(0);
> >
> >       QName bindingName = *null*;
> >
> >
> >
> >                   *for* (BindingInfo binfo : serviceInfo.getBindings()) {
> >
> >                         *if* (binfo.getName().getLocalPart().indexOf(
> > "Soap11") > -1) {
> >
> >                              bindingName = binfo.getName();
> >
> >                         }
> >
> >                   }
> >
> >
> >
> >                   BindingInfo binding =
> > serviceInfo.getBinding(bindingName);
> >
> >                   BindingOperationInfo operationToBeInvoked = *null*;
> >
> >
> >
> >                   *for* (BindingOperationInfo operation :
> > binding.getOperations()) {
> >
> >
> > *if*(methodName.equals(operation.getName().getLocalPart())) {
> >
> >                              operationToBeInvoked = operation;
> >
> >                         }
> >
> >                   }
> >
> >
> >
> >                   *if* (operationToBeInvoked == *null*) {
> >
> >                         *throw* *new* NoSuchMethodException(methodName);
> >
> >                   }
> >
> >
> >
> >                   System.*out*.println("Invoke, operation info: " +
> > operationToBeInvoked );
> >
> >
> >
> >                   BindingMessageInfo inputMessageInfo;
> >
> >
> >
> >                   *if* (!operationToBeInvoked.isUnwrapped()) {
> >
> >                         //Operation uses document literal wrapped style.
> >
> >                         inputMessageInfo =
> > operationToBeInvoked.getWrappedOperation().getInput();
> >
> >                   } *else* {
> >
> >                         inputMessageInfo =
> > operationToBeInvoked.getUnwrappedOperation().getInput();
> >
> >                   }
> >
> >
> >
> >                   List<MessagePartInfo> parts =
> > inputMessageInfo.getMessageParts();
> >
> >                   *if* (parts.isEmpty()) {
> >
> >                         System.*out*.println("parts is empty. No message
> !"
> > );
> >
> >                   } *else* {
> >
> >                         MessagePartInfo partInfo = parts.get(0); // Input
> > class is Order
> >
> >                         // Get the input class Order
> >
> >                         Class<?> param1Class = partInfo.getTypeClass();
> >
> >
> >
> >                         System.*out*.println("param1 is of Type: " +
> > param1Class.getCanonicalName());
> >
> >
> >
> >
> >
> >                               Object myObject = *create*
> > (param1Class.getCanonicalName());
> >
> >                              Method theMethod =
> > myObject.getClass().getMethod("setTask", String.*class*);
> >
> >                              theMethod.invoke(myObject, "value1");
> >
> >                              Method theDayMethod =
> > myObject.getClass().getMethod("setTheDay", String.*class*);
> >
> >                              theDayMethod.invoke(myObject, "value2");
> >
> >
> >
> >                               System.*out*.println("Testing the
> income.");
> >
> >                              Method getter1 =
> > myObject.getClass().getMethod( "getTask", *null*);
> >
> >
>  System.*out*.println(getter1.invoke(myObject,
> > * null*));
> >
> >                              Method getter2 =
> > myObject.getClass().getMethod( "getTheDay", *null*);
> >
> >
>  System.*out*.println(getter2.invoke(myObject,
> > * null*));
> >
> >
> >
> >                              Object[] response =
> > clientImpl.invoke(operationToBeInvoked, myObject);
> >
> >                              *return* *parseResponse*(response);
> >
> >                  }
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Empty beans generated by Cxf using dynamic client

Posted by Daniel Kulp <dk...@apache.org>.
 
I THINK your calls into the opInfo around:
if (!operationToBeInvoked.isUnwrapped()) {

may be confusing things.  If passing the BindingOperationInfo into the invoke, 
you have to use the input message for the BOI, not it's unwrapped form. 

To check this, change the line:
clientImpl.invoke(operationToBeInvoked, myObject);
to
clientImpl.invoke("objectInput", myObject);
and see if that helps at all.


Dan



On Thursday 12 August 2010 8:13:05 am Alex Labad wrote:
> Hi all!
> 
> 
> 
> I have a weird problem with cxf invoking external services: I can handle
> the simple ones through the simple DynamicClientFactory, generating the
> Client and invoking the services, it is ok.
> 
> 
> 
> The problem comes with the Object parameters:
> 
> In this case, the client generates the Beans, I fill them through
> introspection, check the values as well, but when sending the parameter, in
> the server, it just receives an empty bean...
> 
> 
> 
> Calling it from SoapUI, it works perfectly
> 
> Calling from java: It doesn’t reveive anything (it receives a SimpleBean,
> but null when calling the getName or getSurname).
> 
> Any help? Ideas? Will be veeeery welcome!!! (Thanks in advance!!!!)
> 
> 
> 
> Easier with the code? Here it is: (Attached is the WSDL)
> 
> 
> 
> The Service: I did it with Axis2, for dynamic client testing . Where
> SimpleBean is just a POJO with name and surname attributes, and their
> getter and setters.
> 
> 
> 
> *public* String secondObject(SimpleBean simpleBean) {
> 
>             *if* (simpleBean != *null*) {
> 
>                   *if* (simpleBean *instanceof* SimpleBean) {
> 
>                   System.*out*.println("ES UNA simpleBean BEAN");
> 
>                   System.*out*.println("name: " +simpleBean.getName());
> 
>                   System.*out*.println("surname:
> "+simpleBean.getSurname());
> 
> 
> 
>             }
> 
>                   *return* simpleBean.getName()  + " ------------ " +
> simpleBean.getSurname();
> 
>             }
> 
>             *return* "No input provided";
> 
>       }
> 
> 
> 
> And the JavaCode to call to the service
> 
> 
> 
> JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.*newInstance*
> ();
> 
> String methodName=”secondObject”;
> 
>       List<String> bindingFiles = *new* ArrayList<String>();
> 
>      bindingFiles.add("javabindings.xml");
> 
>                 Client clientImpl = factory.createClient(wsdlUrl, Thread.*
> currentThread*().getContextClassLoader(), bindingFiles);
> 
> 
> 
>       Endpoint endpoint = clientImpl.getEndpoint();
> 
>       ServiceInfo serviceInfo =
> endpoint.getService().getServiceInfos().get(0);
> 
>       QName bindingName = *null*;
> 
> 
> 
>                   *for* (BindingInfo binfo : serviceInfo.getBindings()) {
> 
>                         *if* (binfo.getName().getLocalPart().indexOf(
> "Soap11") > -1) {
> 
>                              bindingName = binfo.getName();
> 
>                         }
> 
>                   }
> 
> 
> 
>                   BindingInfo binding =
> serviceInfo.getBinding(bindingName);
> 
>                   BindingOperationInfo operationToBeInvoked = *null*;
> 
> 
> 
>                   *for* (BindingOperationInfo operation :
> binding.getOperations()) {
> 
> 
> *if*(methodName.equals(operation.getName().getLocalPart())) {
> 
>                              operationToBeInvoked = operation;
> 
>                         }
> 
>                   }
> 
> 
> 
>                   *if* (operationToBeInvoked == *null*) {
> 
>                         *throw* *new* NoSuchMethodException(methodName);
> 
>                   }
> 
> 
> 
>                   System.*out*.println("Invoke, operation info: " +
> operationToBeInvoked );
> 
> 
> 
>                   BindingMessageInfo inputMessageInfo;
> 
> 
> 
>                   *if* (!operationToBeInvoked.isUnwrapped()) {
> 
>                         //Operation uses document literal wrapped style.
> 
>                         inputMessageInfo =
> operationToBeInvoked.getWrappedOperation().getInput();
> 
>                   } *else* {
> 
>                         inputMessageInfo =
> operationToBeInvoked.getUnwrappedOperation().getInput();
> 
>                   }
> 
> 
> 
>                   List<MessagePartInfo> parts =
> inputMessageInfo.getMessageParts();
> 
>                   *if* (parts.isEmpty()) {
> 
>                         System.*out*.println("parts is empty. No message !"
> );
> 
>                   } *else* {
> 
>                         MessagePartInfo partInfo = parts.get(0); // Input
> class is Order
> 
>                         // Get the input class Order
> 
>                         Class<?> param1Class = partInfo.getTypeClass();
> 
> 
> 
>                         System.*out*.println("param1 is of Type: " +
> param1Class.getCanonicalName());
> 
> 
> 
> 
> 
>                               Object myObject = *create*
> (param1Class.getCanonicalName());
> 
>                              Method theMethod =
> myObject.getClass().getMethod("setTask", String.*class*);
> 
>                              theMethod.invoke(myObject, "value1");
> 
>                              Method theDayMethod =
> myObject.getClass().getMethod("setTheDay", String.*class*);
> 
>                              theDayMethod.invoke(myObject, "value2");
> 
> 
> 
>                               System.*out*.println("Testing the income.");
> 
>                              Method getter1 =
> myObject.getClass().getMethod( "getTask", *null*);
> 
>                              System.*out*.println(getter1.invoke(myObject,
> * null*));
> 
>                              Method getter2 =
> myObject.getClass().getMethod( "getTheDay", *null*);
> 
>                              System.*out*.println(getter2.invoke(myObject,
> * null*));
> 
> 
> 
>                              Object[] response =
> clientImpl.invoke(operationToBeInvoked, myObject);
> 
>                              *return* *parseResponse*(response);
> 
>                  }

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: Empty beans generated by Cxf using dynamic client

Posted by Alex Labad <al...@gmail.com>.
Further investigation!!!

I didn't say before that I am newie to cxf, and stacked in the bean sending
to services not generated by me!

I have sniffed my server: With CXF the soap request do not contain a <bean>
tag inside it.While the ones generated by Axis2 and SOAP UI do have the
<bean> tag inside it , and they work!!!!

Any idea? it will be really welcome. Thanks in advance!!!
Those are the envelopes sent.

This is the Soap message generated by cxf with the dynamic client:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <objectInput xmlns="http://wstest.wf.gmv.com" xmlns:ns2="
http://wstest.wf.gmv.com/xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:EnumeratedBean">
            <ns2:task>valoooooor</ns2:task>
            <ns2:theDay>theDayMssssethod</ns2:theDay>
            <ns2:time>23123</ns2:time>
        </objectInput>
    </soap:Body>
</soap:Envelope>

This one is the Envelope generated by an Axis1.2 client
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <objectInput xmlns="http://wstest.wf.gmv.com">
            <bean>
                <ns1:task xmlns:ns1="http://wstest.wf.gmv.com/xsd
">123456</ns1:task>
                <ns2:theDay xmlns:ns2="http://wstest.wf.gmv.com/xsd
">kjhlkjhkljhlkjhlkjh</ns2:theDay>
                <ns3:time xmlns:ns3="http://wstest.wf.gmv.com/xsd
">42354234</ns3:time>
            </bean>
        </objectInput>
    </soapenv:Body>
</soapenv:Envelope>

And this one is the one generated by SOAP UI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wst="http://wstest.wf.gmv.com" xmlns:xsd="http://wstest.wf.gmv.com/xsd
">
   <soapenv:Header/>
   <soapenv:Body>
      <wst:objectInput>
         <wst:bean>
            <xsd:task>hgjhgjgjhg</xsd:task>
            <xsd:theDay>233fgergerger</xsd:theDay>
            <xsd:time>2222222222</xsd:time>
         </wst:bean>
      </wst:objectInput>
   </soapenv:Body>
</soapenv:Envelope>