Java Code Examples for org.apache.cxf.service.model.BindingOperationInfo#getInput()

The following examples show how to use org.apache.cxf.service.model.BindingOperationInfo#getInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoapBindingFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void initializeBindingOperation(SoapBindingInfo bi, BindingOperationInfo boi) {
    SoapOperationInfo soi = new SoapOperationInfo();

    SoapOperation soapOp =
        SOAPBindingUtil.getSoapOperation(boi.getExtensors(ExtensibilityElement.class));

    if (soapOp != null) {
        String action = soapOp.getSoapActionURI();
        if (action == null) {
            action = "";
        }
        soi.setAction(action);
        soi.setStyle(soapOp.getStyle());
    }

    boi.addExtensor(soi);

    if (boi.getInput() != null) {
        initializeMessage(bi, boi, boi.getInput());
    }

    if (boi.getOutput() != null) {
        initializeMessage(bi, boi, boi.getOutput());
    }
}
 
Example 2
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }

    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }

    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();

    if (bmi == null) {
        return;
    }

    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);

    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding
            && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
 
Example 3
Source File: BareOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    Exchange exchange = message.getExchange();
    BindingOperationInfo operation = exchange.getBindingOperationInfo();

    if (operation == null) {
        return;
    }

    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    List<MessagePartInfo> parts = null;
    BindingMessageInfo bmsg = null;
    boolean client = isRequestor(message);

    if (!client) {
        if (operation.getOutput() != null) {
            bmsg = operation.getOutput();
            parts = bmsg.getMessageParts();
        } else {
            // partial response to oneway
            return;
        }
    } else {
        bmsg = operation.getInput();
        parts = bmsg.getMessageParts();
    }

    writeParts(message, exchange, operation, objs, parts);
}
 
Example 4
Source File: ServiceModelUtilTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSchema() throws Exception {
    BindingInfo bindingInfo = null;
    bindingInfo = serviceInfo.getBindings().iterator().next();
    QName name = new QName(serviceInfo.getName().getNamespaceURI(), "inHeader");
    BindingOperationInfo inHeader = bindingInfo.getOperation(name);
    BindingMessageInfo input = inHeader.getInput();
    assertNotNull(input);
    assertEquals(input.getMessageInfo().getName().getLocalPart(), "inHeaderRequest");
    assertEquals(input.getMessageInfo().getName().getNamespaceURI(),
                 "http://org.apache.cxf/headers");
    assertEquals(input.getMessageInfo().getMessageParts().size(), 2);
    assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
    assertEquals(
        input.getMessageInfo().getMessageParts().get(0).getElementQName().getLocalPart(), "inHeader");
    assertEquals(input.getMessageInfo().getMessageParts().get(0).getElementQName().getNamespaceURI(),
                 "http://org.apache.cxf/headers");

    assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
    assertEquals(
        input.getMessageInfo().getMessageParts().get(1).getElementQName().getLocalPart(), "passenger");
    assertEquals(input.getMessageInfo().getMessageParts().get(1).getElementQName().getNamespaceURI(),
                 "http://mycompany.example.com/employees");
    assertTrue(input.getMessageInfo().getMessageParts().get(1).isElement());

    MessagePartInfo messagePartInfo = input.getMessageInfo().getMessageParts().get(0);
    SchemaInfo schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
    assertEquals(schemaInfo.getNamespaceURI(), "http://org.apache.cxf/headers");

    messagePartInfo = input.getMessageInfo().getMessageParts().get(1);
    schemaInfo = ServiceModelUtil.getSchema(serviceInfo, messagePartInfo);
    assertEquals(schemaInfo.getNamespaceURI(), "http://mycompany.example.com/employees");
}
 
Example 5
Source File: HeaderUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static Set<QName> getHeaderQNameInOperationParam(SoapMessage soapMessage) {
    BindingOperationInfo bop = soapMessage.getExchange().getBindingOperationInfo();
    if (bop != null) {
        if (bop.getInput() != null) {
            return getHeaderParts(bop.getInput());
        }
        if (bop.getOutput() != null) {
            return getHeaderParts(bop.getOutput());
        }
    }
    return Collections.emptySet();
}
 
Example 6
Source File: ServiceModelPolicyUpdater.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void addPolicyAttachments(Collection<PolicyAttachment> attachments) {
    for (PolicyAttachment pa : attachments) {
        boolean policyUsed = false;

        for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
            BindingMessageInfo inputMessage = boi.getInput();
            BindingMessageInfo outputMessage = boi.getOutput();

            if (pa.appliesTo(boi)) {
                // Add wsp:PolicyReference to wsdl:binding/wsdl:operation
                addPolicyRef(boi, pa.getPolicy());
                // Add it to wsdl:portType/wsdl:operation too
                // FIXME - since the appliesTo is for BindingOperationInfo, I think its dodgy
                // that the policy ref should also be associated with the port type
                addPolicyRef(ei.getInterface().getOperation(boi.getName()), pa.getPolicy());
                policyUsed = true;
            } else if (pa.appliesTo(inputMessage)) {
                addPolicyRef(inputMessage, pa.getPolicy());
                policyUsed = true;
            } else if (pa.appliesTo(outputMessage)) {
                addPolicyRef(outputMessage, pa.getPolicy());
                policyUsed = true;
            }
        }

        // Add wsp:Policy to top-level wsdl:definitions
        if (policyUsed) {
            addPolicy(pa);
        }
    }
}
 
Example 7
Source File: EffectivePolicyImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
Assertor initialisePolicy(EndpointInfo ei,
                      BindingOperationInfo boi,
                      PolicyEngine engine,
                      boolean requestor,
                      boolean request,
                      Assertor assertor,
                      Message m) {

    if (boi.isUnwrapped()) {
        boi = boi.getUnwrappedOperation();
    }

    BindingMessageInfo bmi = request ? boi.getInput() : boi.getOutput();
    EndpointPolicy ep;
    if (requestor) {
        ep = engine.getClientEndpointPolicy(ei, getAssertorAs(assertor, Conduit.class), m);
    } else {
        ep = engine.getServerEndpointPolicy(ei, getAssertorAs(assertor, Destination.class), m);
    }
    policy = ep.getPolicy();
    if (ep instanceof EndpointPolicyImpl) {
        assertor = ((EndpointPolicyImpl)ep).getAssertor();
    }

    policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m));
    if (null != bmi) {
        policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedMessagePolicy(bmi, m));
    }
    policy = policy.normalize(engine.getRegistry(), true);
    return assertor;
}
 
Example 8
Source File: XMLMessageOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped()
        || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
 
Example 9
Source File: XMLMessageInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (isGET(message)) {
        LOG.fine("XMLMessageInInterceptor skipped in HTTP GET method");
        return;
    }
    Endpoint ep = message.getExchange().getEndpoint();

    XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
    if (xsr == null) {
        return;
    }
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
    if (!StaxUtils.toNextElement(reader)) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT", LOG));
    }

    Exchange ex = message.getExchange();
    QName startQName = reader.getName();
    // handling xml fault message
    if (startQName.getLocalPart().equals(XMLFault.XML_FAULT_ROOT)) {
        message.getInterceptorChain().abort();

        if (ep.getInFaultObserver() != null) {
            ep.getInFaultObserver().onMessage(message);
            return;
        }
    }
    // handling xml normal inbound message
    BindingOperationInfo boi = ex.getBindingOperationInfo();
    boolean isRequestor = isRequestor(message);
    if (boi == null) {
        BindingInfo service = ep.getEndpointInfo().getBinding();
        boi = getBindingOperationInfo(isRequestor, startQName, service, xsr);
        if (boi != null) {
            ex.put(BindingOperationInfo.class, boi);
            ex.setOneWay(boi.getOperationInfo().isOneWay());
        }
    } else {
        BindingMessageInfo bmi = isRequestor ? boi.getOutput() : boi.getInput();

        if (hasRootNode(bmi, startQName)) {
            try {
                xsr.nextTag();
            } catch (XMLStreamException xse) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
            }
        }
    }
}
 
Example 10
Source File: CorbaStreamInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void handleRequest(Message msg) {
    ORB orb;
    ServiceInfo service;
    CorbaDestination destination;
    if (msg.getDestination() != null) {
        destination = (CorbaDestination)msg.getDestination();
    } else {
        destination = (CorbaDestination)msg.getExchange().getDestination();
    }
    service = destination.getBindingInfo().getService();

    CorbaMessage message = (CorbaMessage) msg;

    Exchange exchange = message.getExchange();

    CorbaTypeMap typeMap = message.getCorbaTypeMap();

    BindingInfo bInfo = destination.getBindingInfo();
    InterfaceInfo info = bInfo.getInterface();
    String opName = exchange.get(String.class);
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();
    OperationType opType = null;
    BindingOperationInfo bopInfo = null;
    QName opQName = null;
    while (i.hasNext()) {
        bopInfo = i.next();
        if (bopInfo.getName().getLocalPart().equals(opName)) {
            opType = bopInfo.getExtensor(OperationType.class);
            opQName = bopInfo.getName();
            break;
        }
    }

    if (opType == null) {
        throw new RuntimeException("Couldn't find the binding operation for " + opName);
    }

    orb = exchange.get(ORB.class);

    ServerRequest request = exchange.get(ServerRequest.class);
    NVList list = prepareArguments(message, info, opType,
                                   opQName, typeMap,
                                   destination, service);
    request.arguments(list);
    message.setList(list);

    HandlerIterator paramIterator = new HandlerIterator(message, true);

    CorbaTypeEventProducer eventProducer = null;
    BindingMessageInfo msgInfo = bopInfo.getInput();
    boolean wrap = false;
    if (bopInfo.isUnwrappedCapable()) {
        wrap = true;
    }

    if (wrap) {
        // wrapper element around our args
        QName wrapperElementQName = msgInfo.getMessageInfo().getName();
        eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName,
                                                                  paramIterator,
                                                                  service,
                                                                  orb);
    } else {
        eventProducer = new ParameterEventProducer(paramIterator,
                                                   service,
                                                   orb);
    }
    CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
    message.setContent(XMLStreamReader.class, reader);
}
 
Example 11
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoBodyParts() throws Exception {
    Definition d = createDefinition("/wsdl_soap/no_body_parts.wsdl");
    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                    "NoBodyParts"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                                          "operation1"));

    assertNotNull(boi);
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertNull(sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertNull(bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(0, parts.size());
}
 
Example 12
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testFactory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());
}
 
Example 13
Source File: SoapBindingFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSoap12Factory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);

    expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap12_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
    assertTrue(sbi.getSoapVersion() instanceof Soap12);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("sayHiAction", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());

    boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
    sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    Collection<BindingFaultInfo> faults = boi.getFaults();
    assertEquals(1, faults.size());
    BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http",
                                                        "pingMeFault"));
    assertNotNull(faultInfo);
}
 
Example 14
Source File: JaxWsEndpointImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void extractWsdlExtensibilities(EndpointInfo endpoint) {
    List<ExtensibilityElement> portExtensors = getExtensors(endpoint);
    List<ExtensibilityElement> bindingExtensors = getExtensors(endpoint.getBinding());

    //check the extensions under <wsdl:binding>
    checkRespectBindingFeature(bindingExtensors);

    Collection<BindingOperationInfo> bindingOperations = endpoint.getBinding().getOperations();
    if (null != bindingOperations) {
        Iterator<BindingOperationInfo> iterator = bindingOperations.iterator();
        while (iterator.hasNext()) {
            BindingOperationInfo operationInfo = iterator.next();
            BindingMessageInfo inputInfo = operationInfo.getInput();
            BindingMessageInfo outputnfo = operationInfo.getOutput();
            Collection<BindingFaultInfo> faults = operationInfo.getFaults();

            //check the extensions under <wsdl:operation>
            checkRespectBindingFeature(getExtensors(operationInfo));
            //check the extensions under <wsdl:input>
            checkRespectBindingFeature(getExtensors(inputInfo));
            //check the extensions under <wsdl:output>
            checkRespectBindingFeature(getExtensors(outputnfo));
            if (null != faults) {
                Iterator<BindingFaultInfo> faultIterator = faults.iterator();
                while (faultIterator.hasNext()) {
                    BindingFaultInfo faultInfo = faultIterator.next();

                    //check the extensions under <wsdl:fault>
                    checkRespectBindingFeature(getExtensors(faultInfo));
                }
            }

        }
    }


    if (hasUsingAddressing(bindingExtensors) || hasUsingAddressing(portExtensors)) {
        WSAddressingFeature feature = new WSAddressingFeature();
        if (addressingRequired(bindingExtensors)
            || addressingRequired(portExtensors)) {
            feature.setAddressingRequired(true);
        }
        addAddressingFeature(feature);
    }
    extractWsdlEprs(endpoint);
}
 
Example 15
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testBindingMessageInfo() throws Exception {
    setUpBasic();
    BindingInfo bindingInfo = null;
    bindingInfo = serviceInfo.getBindings().iterator().next();

    QName name = new QName(serviceInfo.getName().getNamespaceURI(), "sayHi");
    BindingOperationInfo sayHi = bindingInfo.getOperation(name);
    BindingMessageInfo input = sayHi.getInput();
    assertNotNull(input);
    assertEquals(input.getMessageInfo().getName().getLocalPart(), "sayHiRequest");
    assertEquals(input.getMessageInfo().getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertEquals(input.getMessageInfo().getMessageParts().size(), 1);
    assertEquals(input.getMessageInfo().getMessageParts().get(0).getName().getLocalPart(), "in");
    assertEquals(input.getMessageInfo().getMessageParts().get(0).getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertTrue(input.getMessageInfo().getMessageParts().get(0).isElement());
    QName elementName = input.getMessageInfo().getMessageParts().get(0).getElementQName();
    assertEquals(elementName.getLocalPart(), "sayHi");
    assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");

    BindingMessageInfo output = sayHi.getOutput();
    assertNotNull(output);
    assertEquals(output.getMessageInfo().getName().getLocalPart(), "sayHiResponse");
    assertEquals(output.getMessageInfo().getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertEquals(output.getMessageInfo().getMessageParts().size(), 1);
    assertEquals(output.getMessageInfo().getMessageParts().get(0).getName().getLocalPart(), "out");
    assertEquals(output.getMessageInfo().getMessageParts().get(0).getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertTrue(output.getMessageInfo().getMessageParts().get(0).isElement());
    elementName = output.getMessageInfo().getMessageParts().get(0).getElementQName();
    assertEquals(elementName.getLocalPart(), "sayHiResponse");
    assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");

    assertTrue(sayHi.getFaults().isEmpty());

    name = new QName(serviceInfo.getName().getNamespaceURI(), "pingMe");
    BindingOperationInfo pingMe = bindingInfo.getOperation(name);
    assertNotNull(pingMe);
    assertEquals(1, pingMe.getFaults().size());
    BindingFaultInfo fault = pingMe.getFaults().iterator().next();

    assertNotNull(fault);
    assertEquals(fault.getFaultInfo().getName().getLocalPart(), "pingMeFault");
    assertEquals(fault.getFaultInfo().getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertEquals(fault.getFaultInfo().getMessageParts().size(), 1);
    assertEquals(fault.getFaultInfo().getMessageParts().get(0).getName().getLocalPart(), "faultDetail");
    assertEquals(fault.getFaultInfo().getMessageParts().get(0).getName().getNamespaceURI(),
            "http://apache.org/hello_world_soap_http");
    assertTrue(fault.getFaultInfo().getMessageParts().get(0).isElement());
    elementName = fault.getFaultInfo().getMessageParts().get(0).getElementQName();
    assertEquals(elementName.getLocalPart(), "faultDetail");
    assertEquals(elementName.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
    control.verify();
}
 
Example 16
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void assertBindingOperationMessageExtensions(BindingOperationInfo boi, boolean expectExtensions,
    boolean hasOutput, QName fault) {

    BindingMessageInfo bmi = boi.getInput();
    if (expectExtensions) {
        // REVISIT: bug in wsdl4j?
        // getExtensionAttributes on binding/operation/input element returns an empty map
        // assertEquals(1, bmi.getExtensionAttributes().size());
        // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
        assertEquals(EXTENSION_ELEM, bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
    } else {
        assertNull(bmi.getExtensionAttributes());
        assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
        assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
    }

    if (hasOutput) {
        bmi = boi.getOutput();
        if (expectExtensions) {
            // REVISIT: bug in wsdl4j?
            // getExtensionAttributes on binding/operation/output element returns an empty map
            // assertEquals(1, bmi.getExtensionAttributes().size());
            // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM,
                bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(bmi.getExtensionAttributes());
            assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
            assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
        }
    }

    if (null != fault) {
        BindingFaultInfo bfi = boi.getFault(fault);
        if (expectExtensions) {
            assertEquals(1, bfi.getExtensionAttributes().size());
            assertNotNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, bfi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM,
                bfi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(bfi.getExtensionAttributes());
            assertNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertNull(bfi.getExtensors(UnknownExtensibilityElement.class));
            assertNull(bfi.getExtensor(UnknownExtensibilityElement.class));
        }
    }
}
 
Example 17
Source File: AbstractInDatabindingInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Find the next possible message part in the message. If an operation in
 * the list of operations is no longer a viable match, it will be removed
 * from the Collection.
 *
 * @param exchange
 * @param operations
 * @param name
 * @param client
 * @param index
 */
protected MessagePartInfo findMessagePart(Exchange exchange, Collection<OperationInfo> operations,
                                          QName name, boolean client, int index,
                                          Message message) {
    Endpoint ep = exchange.getEndpoint();
    MessagePartInfo lastChoice = null;
    BindingOperationInfo lastBoi = null;
    BindingMessageInfo lastMsgInfo = null;
    for (Iterator<OperationInfo> itr = operations.iterator(); itr.hasNext();) {
        OperationInfo op = itr.next();

        final BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
        if (boi == null) {
            continue;
        }
        final BindingMessageInfo msgInfo;
        if (client) {
            msgInfo = boi.getOutput();
        } else {
            msgInfo = boi.getInput();
        }

        if (msgInfo == null) {
            itr.remove();
            continue;
        }

        Collection<MessagePartInfo> bodyParts = msgInfo.getMessageParts();
        if (bodyParts.isEmpty() || bodyParts.size() <= index) {
            itr.remove();
            continue;
        }

        MessagePartInfo p = msgInfo.getMessageParts().get(index);
        if (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty()) {
            // message part has same namespace with the message
            name = new QName(p.getMessageInfo().getName().getNamespaceURI(), name.getLocalPart());
        }
        if (name.equals(p.getConcreteName())) {
            exchange.put(BindingOperationInfo.class, boi);
            exchange.setOneWay(op.isOneWay());
            return p;
        }

        if (Constants.XSD_ANYTYPE.equals(p.getTypeQName())) {
            lastChoice = p;
            lastBoi = boi;
            lastMsgInfo = msgInfo;
        } else {
            itr.remove();
        }
    }
    if (lastChoice != null) {
        setMessage(message, lastBoi, client, lastBoi.getBinding().getService(),
                   lastMsgInfo.getMessageInfo());
    }
    return lastChoice;
}