You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by MartyH <ma...@singularity.co.uk> on 2008/02/28 16:23:07 UTC

finding the number of input output parameters using dynamic client.

Hi,
I'm trying to figure out how to get the number of input and output
parameters using cxf.  I had managed to do this using xfire, but since
upgrading I haven't been able to twig this one.  Been trying combinations of
this:

        ServiceInfo model
=client.getEndpoint().getService().getServiceInfos().get(0);
        InterfaceInfo interfaceInfo = model.getInterface();
        Collection<OperationInfo> operationInfos2 =
interfaceInfo.getOperations();

        OperationInfo toCall = null;
        for (OperationInfo operationInfo:operationInfos2){
            if (operationInfo.getName().getLocalPart().equals(methodName)){
                toCall = operationInfo;
                break;
            }
        }
        
        List parts = toCall.getInput().getMessageParts();
        serviceInfo.put("input",new Integer(parts.size()));
        logger.info("Number of input parameters: " + parts.size());
        
        List outputParts = toCall.getOutput().getMessageParts();
        serviceInfo.put("output",new Integer(outputParts.size()));
        logger.info("Number of ouput parameters: " + outputParts.size()); 


and this:

 Collection<BindingOperationInfo> operationInfos = 
           
client.getEndpoint().getBinding().getBindingInfo().getOperations();
        BindingOperationInfo opToCall = null;
        for(BindingOperationInfo oi: operationInfos) {
            if (oi.getName().getLocalPart().equals(methodName)) {
                opToCall = oi;
            }
        }         
        parts = opToCall.getInput().getMessageParts();
        serviceInfo.put("input",new Integer(parts.size()));
        logger.info("Number of input parameters: " + parts.size());
        
        outputParts = opToCall.getOutput().getMessageParts();
        serviceInfo.put("output",new Integer(outputParts.size()));
        logger.info("Number of ouput parameters: " + outputParts.size());


but it always seems to through back 1 and 1 as input and ouptput.

Hope you can help,
thanks.

Marty
-- 
View this message in context: http://www.nabble.com/finding-the-number-of-input-output-parameters-using-dynamic-client.-tp15738768p15738768.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: finding the number of input output parameters using dynamic client.

Posted by MartyH <ma...@singularity.co.uk>.
Yip, using cxf 2.0.4.

Dan, thanks.  That worked a treat. I added this to the code and life is
good.

        if (toCall.isUnwrappedCapable()){
            toCall = toCall.getUnwrappedOperation();
        }

one othe strange thing i'm seeing in my unit tests though is occaisonally
I'm getting this chucked out after i've tried to create dynamic clients one
after the other in junit tests for different services.

java.lang.IllegalStateException: Unable to create JAXBContext for generated
packages: "org.tempuri" doesnt contain ObjectFactory.class or jaxb.index
-- 
View this message in context: http://www.nabble.com/finding-the-number-of-input-output-parameters-using-dynamic-client.-tp15738768p15754236.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: finding the number of input output parameters using dynamic client.

Posted by Daniel Kulp <dk...@apache.org>.
I'm going to assume you are using CXF 2.0.4 or the 2.1 snapshots....   If 
not, definitely update as what I'm about to describe applies to code 
enhanced for that version....

It SOUNDS like you are using a wrapped doc/literal wsdl, which is fine.   
However, in that case, the wsdl message only has a single part in it.  
That is why your call to parts.size() is returning one as the "raw" 
OperationInfo you are getting is exactly as it appears in the wsdl.

However, the OperationInfo has a "isUnwrappedCapable()" call, and if 
true, a getUnwrappedOperation() call that can return a new OperationInfo 
that describes the same operation, but in it's unwrapped form.

With 2.0.3, you pretty much HAD to user the Unwrapped OperationInfo form.   
There wasn't any other option.

With 2.0.4, you have a choice of which form to use.  The 
Client.invoke(...) calls all expect the params to match what 
the "Unwrapped Operation" says they will be.   However, we 
added "Client.invokeUnwrapped(...)" calls that match what the original 
Wrapped operation says.  (in your case, one part which would be the 
wrapper type.  Like a "EchoFoo" object returning a EchoFooResponse 
object).  

Hope that helps.
Dan



On Thursday 28 February 2008, MartyH wrote:
> Hi,
> I'm trying to figure out how to get the number of input and output
> parameters using cxf.  I had managed to do this using xfire, but since
> upgrading I haven't been able to twig this one.  Been trying
> combinations of this:
>
>         ServiceInfo model
> =client.getEndpoint().getService().getServiceInfos().get(0);
>         InterfaceInfo interfaceInfo = model.getInterface();
>         Collection<OperationInfo> operationInfos2 =
> interfaceInfo.getOperations();
>
>         OperationInfo toCall = null;
>         for (OperationInfo operationInfo:operationInfos2){
>             if
> (operationInfo.getName().getLocalPart().equals(methodName)){ toCall =
> operationInfo;
>                 break;
>             }
>         }
>
>         List parts = toCall.getInput().getMessageParts();
>         serviceInfo.put("input",new Integer(parts.size()));
>         logger.info("Number of input parameters: " + parts.size());
>
>         List outputParts = toCall.getOutput().getMessageParts();
>         serviceInfo.put("output",new Integer(outputParts.size()));
>         logger.info("Number of ouput parameters: " +
> outputParts.size());
>
>
> and this:
>
>  Collection<BindingOperationInfo> operationInfos =
>
> client.getEndpoint().getBinding().getBindingInfo().getOperations();
>         BindingOperationInfo opToCall = null;
>         for(BindingOperationInfo oi: operationInfos) {
>             if (oi.getName().getLocalPart().equals(methodName)) {
>                 opToCall = oi;
>             }
>         }
>         parts = opToCall.getInput().getMessageParts();
>         serviceInfo.put("input",new Integer(parts.size()));
>         logger.info("Number of input parameters: " + parts.size());
>
>         outputParts = opToCall.getOutput().getMessageParts();
>         serviceInfo.put("output",new Integer(outputParts.size()));
>         logger.info("Number of ouput parameters: " +
> outputParts.size());
>
>
> but it always seems to through back 1 and 1 as input and ouptput.
>
> Hope you can help,
> thanks.
>
> Marty



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog