Search in sources :

Example 21 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class SoapHeaderInterceptor method handleMessage.

public void handleMessage(Message m) throws Fault {
    SoapMessage message = (SoapMessage) m;
    SoapVersion soapVersion = message.getVersion();
    Exchange exchange = message.getExchange();
    MessageContentsList parameters = MessageContentsList.getContentsList(message);
    if (null == parameters) {
        parameters = new MessageContentsList();
    }
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    if (null == bop) {
        return;
    }
    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
    if (bmi == null) {
        // one way operation.
        return;
    }
    List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
    if (headers == null || headers.isEmpty()) {
        return;
    }
    boolean supportsNode = this.supportsDataReader(message, Node.class);
    Service service = ServiceModelUtil.getService(message.getExchange());
    for (SoapHeaderInfo header : headers) {
        MessagePartInfo mpi = header.getPart();
        try {
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
                Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
                validateHeader(message, mpi, schema);
            }
        } catch (Fault f) {
            if (!isRequestor(message)) {
                f.setFaultCode(Fault.FAULT_CODE_CLIENT);
            }
            throw f;
        }
        if (mpi.getTypeClass() != null) {
            Header param = findHeader(message, mpi);
            Object object = null;
            if (param != null) {
                message.getHeaders().remove(param);
                if (param.getDataBinding() == null) {
                    Node source = (Node) param.getObject();
                    if (source instanceof Element) {
                        // need to remove these attributes as they
                        // would cause validation failures
                        Element el = (Element) source;
                        el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand());
                        el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole());
                    }
                    if (supportsNode) {
                        object = getNodeDataReader(message).read(mpi, source);
                    } else {
                        W3CDOMStreamReader reader = new W3CDOMStreamReader((Element) source);
                        try {
                            // advance into the first tag
                            reader.nextTag();
                        } catch (XMLStreamException e) {
                        // ignore
                        }
                        object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
                    }
                } else {
                    object = param.getObject();
                }
            }
            parameters.put(mpi, object);
        }
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) Schema(javax.xml.validation.Schema) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) Exchange(org.apache.cxf.message.Exchange) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Header(org.apache.cxf.headers.Header) XMLStreamException(javax.xml.stream.XMLStreamException) W3CDOMStreamReader(org.apache.cxf.staxutils.W3CDOMStreamReader)

Example 22 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class SoapPreProtocolOutInterceptor method setSoapAction.

private void setSoapAction(SoapMessage message) {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    // The soap action is set on the wrapped operation.
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }
    String action = getSoapAction(message, boi);
    if (message.getVersion() instanceof Soap11) {
        Map<String, List<String>> tempReqHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
        Map<String, List<String>> reqHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
        if (reqHeaders != null) {
            tempReqHeaders.putAll(reqHeaders);
        }
        if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) {
            tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action));
        }
        message.put(Message.PROTOCOL_HEADERS, tempReqHeaders);
    } else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) {
        String ct = (String) message.get(Message.CONTENT_TYPE);
        if (ct.indexOf("action=\"") == -1) {
            ct = new StringBuilder().append(ct).append("; action=").append(action).toString();
            message.put(Message.CONTENT_TYPE, ct);
        }
    }
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Soap11(org.apache.cxf.binding.soap.Soap11) List(java.util.List) TreeMap(java.util.TreeMap)

Example 23 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class SoapBindingInfo method getSoapAction.

/**
 * Get the soap action for an operation. Will never return null.
 *
 * @param operation
 * @return
 */
public String getSoapAction(OperationInfo operation) {
    BindingOperationInfo b = getOperation(operation.getName());
    SoapOperationInfo opInfo = b.getExtensor(SoapOperationInfo.class);
    if (opInfo != null && opInfo.getAction() != null) {
        return opInfo.getAction();
    }
    return "";
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo)

Example 24 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class MustUnderstandInterceptorTest method testHandleMessageWithSoapHeader11Param.

@Test
public void testHandleMessageWithSoapHeader11Param() throws Exception {
    prepareSoapMessage("test-soap-header.xml");
    dsi.getUnderstoodHeaders().add(RESERVATION);
    ServiceInfo serviceInfo = getMockedServiceModel(getClass().getResource("test-soap-header.wsdl").toString());
    BindingInfo binding = serviceInfo.getBinding(new QName("http://org.apache.cxf/headers", "headerTesterSOAPBinding"));
    BindingOperationInfo bop = binding.getOperation(new QName("http://org.apache.cxf/headers", "inHeader"));
    soapMessage.getExchange().put(BindingOperationInfo.class, bop);
    soapMessage.getInterceptorChain().doIntercept(soapMessage);
    assertEquals("DummaySoapInterceptor getRoles has been called!", true, dsi.isCalledGetRoles());
    assertEquals("DummaySoapInterceptor getUnderstood has been called!", true, dsi.isCalledGetUnderstood());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) Test(org.junit.Test)

Example 25 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class RPCInInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    ServiceInfo si = getMockedServiceModel(this.getClass().getResource("/wsdl_soap/hello_world_rpc_lit.wsdl").toString());
    BindingInfo bi = si.getBinding(new QName(TNS, "Greeter_SOAPBinding_RPCLit"));
    BindingOperationInfo boi = bi.getOperation(new QName(TNS, OPNAME));
    boi.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
    boi.getOperationInfo().getInput().getMessagePartByIndex(0).setIndex(1);
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(MyComplexStruct.class);
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
    soapMessage.getExchange().put(BindingOperationInfo.class, boi);
    control.reset();
    Service service = control.createMock(Service.class);
    JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
    service.getDataBinding();
    EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
    service.getServiceInfos();
    List<ServiceInfo> list = Arrays.asList(si);
    EasyMock.expectLastCall().andReturn(list).anyTimes();
    EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
    soapMessage.getExchange().put(Service.class, service);
    soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    control.replay();
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Before(org.junit.Before)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16