Menu

Examples

Rodrigo Salvo

This API is based on Apache CXF components.

The main idea is to provide a parser (to parse the WSDLs) and a invoker (to invoke the web services).

Here I demonstrate some usage:

Project Admins:


Discussion

  • Rodrigo Salvo

    Rodrigo Salvo - 2013-04-12

    Parser API

    Creates a new parser and parses a wsdl based web service.

    ParserWSDL parser = new ParserWSDL( wsdlUri );
    
    List< WsdlService > services = parser.getWsdlServices();
    
    for ( WsdlService service : services ){
        System.out.println( "- " + service.getServiceName() + " : " + service.getEndpointName() );
    }
    
    for ( Operation operation : parser.getOperations() ){
        System.out.println( operation.getName() );
    }
    
     

    Last edit: Rodrigo Salvo 2013-04-13
  • Rodrigo Salvo

    Rodrigo Salvo - 2013-04-13

    Invoker API

    Creates a new invoker so you can call a web service from the parsed source.

    WSInvoker invoker = new WSInvoker();
    
    Operation op = parser.getOperation( "operationX" );
    
    Attribute req = AttributeFactory
        .createComplexType( "operationX", "namespace")
        .appendPrimitive( "attribute1", "value1" )
        .appendPrimitive( "attribute2", "value2" )
        .appendPrimitive( "attribute3", "value3" )
        .createAttribute();
    
    op.setArgument( req );
    
    Attribute resp = invoker.invoke( op );
    
    System.out.println( resp.toString() );
    

     

    Last edit: Rodrigo Salvo 2013-04-13
  • Rodrigo Salvo

    Rodrigo Salvo - 2013-04-13

    Getting Request Schema

    You can iterate on the request object so you can get all attributes and namespaces used in the request for manipulating specific attributes or filling them as well to create the service request.

    ParserWSDL parser = new ParserWSDL( wsdlUri );
    
    Operation op = parser.getOperation( "operationX" );
    
    Attribute req = op.getArgument();
    
    if ( req instanceof ComplexType ){
        ComplexType ct = (ComplexType) req;
        for ( Attribute att : ct.getAttributes() ){
            if ( att instanceof ComplexType ){
                //call recursively to get the next nested element
            } else {
                Primitive pr = (Primitive) att;
    
                System.out.println( "attribute name: " + pr.getName() + " attribute namespace: " + pr.getNameSpace() );
            }
        }
    }
    

     
  • Rodrigo Salvo

    Rodrigo Salvo - 2013-04-13

    Dealing With Response

    You can iterate the response object as well, or you can also convert its elements to a map and then access the element needed by its name as you go through the xml tree.

    WSInvoker invoker = new WSInvoker();
    
     ...
    
    Attribute resp = invoker.invoke( op );
    
    Map< String, Object > map = AttributeUtils.createFullMapFromType( (ComplexType)resp );
    
    String value = (String)map.get( "primitiveField" );
    
    System.out.println( value );
    
    Map< String, Object > cp = (Map< String, Object >)map.get( "complextField1" );
    
    value = (String)cp.get( "otherPrimitiveField" );
    
    System.out.println( value );
    

     

Log in to post a comment.

MongoDB Logo MongoDB