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
[email protected]
http://dankulp.com/blog