Search in sources :

Example 66 with MessageInfo

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

the class RMEndpoint method buildTerminateSequenceOperationInfo.

void buildTerminateSequenceOperationInfo(InterfaceInfo ii, ProtocolVariation protocol) {
    OperationInfo operationInfo = null;
    MessagePartInfo partInfo = null;
    MessageInfo messageInfo = null;
    RMConstants consts = protocol.getConstants();
    operationInfo = ii.addOperation(consts.getTerminateSequenceOperationName());
    messageInfo = operationInfo.createMessage(consts.getTerminateSequenceOperationName(), MessageInfo.Type.INPUT);
    operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
    partInfo = messageInfo.addMessagePart(TERMINATE_PART_NAME);
    partInfo.setElementQName(consts.getTerminateSequenceOperationName());
    partInfo.setElement(true);
    partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceType());
    if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
        messageInfo = operationInfo.createMessage(RM11Constants.INSTANCE.getTerminateSequenceResponseOperationName(), MessageInfo.Type.OUTPUT);
        operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
        partInfo = messageInfo.addMessagePart(TERMINATE_RESPONSE_PART_NAME);
        partInfo.setElementQName(RM11Constants.INSTANCE.getTerminateSequenceResponseOperationName());
        partInfo.setElement(true);
        partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceResponseType());
        partInfo.setIndex(0);
    }
    // for the TerminateSequence operation to an anonymous endpoint
    operationInfo = ii.addOperation(consts.getTerminateSequenceAnonymousOperationName());
    messageInfo = operationInfo.createMessage(consts.getTerminateSequenceAnonymousOperationName(), MessageInfo.Type.OUTPUT);
    operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
    partInfo = messageInfo.addMessagePart(TERMINATE_PART_NAME);
    partInfo.setElementQName(consts.getTerminateSequenceOperationName());
    partInfo.setElement(true);
    partInfo.setTypeClass(protocol.getCodec().getTerminateSequenceType());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 67 with MessageInfo

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

the class InternalContextUtils method getActionFromServiceModel.

/**
 * Get action from service model.
 *
 * @param message the current message
 * @param fault the fault if one is set
 */
private static String getActionFromServiceModel(Message message, Exception fault) {
    String action = null;
    BindingOperationInfo bindingOpInfo = message.getExchange().getBindingOperationInfo();
    if (bindingOpInfo != null) {
        if (bindingOpInfo.isUnwrappedCapable()) {
            bindingOpInfo = bindingOpInfo.getUnwrappedOperation();
        }
        if (fault == null) {
            action = (String) message.get(ContextUtils.ACTION);
            if (StringUtils.isEmpty(action)) {
                action = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            }
            if (action == null || "".equals(action)) {
                MessageInfo msgInfo = ContextUtils.isRequestor(message) ? bindingOpInfo.getOperationInfo().getInput() : bindingOpInfo.getOperationInfo().getOutput();
                String cachedAction = (String) msgInfo.getProperty(ContextUtils.ACTION);
                if (cachedAction == null) {
                    action = getActionFromMessageAttributes(msgInfo);
                } else {
                    action = cachedAction;
                }
                if (action == null && ContextUtils.isRequestor(message)) {
                    SoapOperationInfo soi = getSoapOperationInfo(bindingOpInfo);
                    action = soi == null ? null : soi.getAction();
                    action = StringUtils.isEmpty(action) ? null : action;
                }
            }
        } else {
            Throwable t = fault.getCause();
            // http://www.w3.org/2005/02/addressing/wsdl schema
            for (BindingFaultInfo bfi : bindingOpInfo.getFaults()) {
                FaultInfo fi = bfi.getFaultInfo();
                if (fi.size() == 0) {
                    continue;
                }
                if (t != null && matchFault(t, fi)) {
                    if (fi.getExtensionAttributes() == null) {
                        continue;
                    }
                    String attr = (String) fi.getExtensionAttributes().get(Names.WSAW_ACTION_QNAME);
                    if (attr == null) {
                        attr = (String) fi.getExtensionAttributes().get(new QName(Names.WSA_NAMESPACE_WSDL_NAME_OLD, Names.WSAW_ACTION_NAME));
                    }
                    if (attr != null) {
                        action = attr;
                        break;
                    }
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("action determined from service model: " + action);
    }
    return action;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 68 with MessageInfo

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

the class ContextUtilsTest method testGetActionFromMessage.

@Test
public void testGetActionFromMessage() {
    Message msg = control.createMock(Message.class);
    Exchange exchange = control.createMock(Exchange.class);
    QName mqname = new QName("http://foo.com", "bar");
    QName fqname = new QName("urn:foo:test:4", "fault");
    OperationInfo operationInfo = new OperationInfo();
    MessageInfo messageInfo = new MessageInfo(operationInfo, Type.OUTPUT, mqname);
    messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo"), null));
    operationInfo.setOutput("outputName", messageInfo);
    FaultInfo faultInfo = new FaultInfo(fqname, mqname, operationInfo);
    operationInfo.addFault(faultInfo);
    BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
    // test 1 : retrieving the normal action prop from the message
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    EasyMock.expect(msg.get(ContextUtils.ACTION)).andReturn("urn:foo:test:1");
    control.replay();
    AttributedURIType action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals("urn:foo:test:1", action.getValue());
    control.reset();
    // test 2 : retrieving the normal soap action prop from the message
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    EasyMock.expect(msg.get(SoapBindingConstants.SOAP_ACTION)).andReturn("urn:foo:test:2");
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals("urn:foo:test:2", action.getValue());
    control.reset();
    // test 3 : retrieving the action prop from the message info
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    messageInfo.setProperty(ContextUtils.ACTION, "urn:foo:test:3");
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals("urn:foo:test:3", action.getValue());
    control.reset();
    // test 4 : retrieving the action for a fault without message part
    SoapFault fault = new SoapFault("faulty service", new RuntimeException(), fqname);
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNull(action);
    control.reset();
    // test 5 : retrieving the action for a fault with matching message part
    faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "faultInfo"), null));
    faultInfo.getMessagePart(0).setTypeClass(RuntimeException.class);
    faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:4");
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals("urn:foo:test:4", action.getValue());
    control.reset();
    // test 6 : retrieving the action for a ws-addr fault with matching message part
    fault = new SoapFault("Action Mismatch", new QName(Names.WSA_NAMESPACE_NAME, Names.ACTION_MISMATCH_NAME));
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals(Names.WSA_DEFAULT_FAULT_ACTION, action.getValue());
    control.reset();
    // test 7 : retrieve the action for a fault matching the fault class with the WebFault annotation
    fault = new SoapFault("faulty service", new TestFault(), Fault.FAULT_CODE_SERVER);
    faultInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com:7", "faultInfo"), null));
    faultInfo.getMessagePart(0).setTypeClass(Object.class);
    faultInfo.getMessagePart(0).setConcreteName(new QName("urn:foo:test:7", "testFault"));
    faultInfo.addExtensionAttribute(Names.WSAW_ACTION_QNAME, "urn:foo:test:7");
    EasyMock.expect(msg.getExchange()).andReturn(exchange).anyTimes();
    EasyMock.expect(msg.getContent(Exception.class)).andReturn(fault).anyTimes();
    EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi);
    control.replay();
    action = InternalContextUtils.getAction(msg);
    assertNotNull(action);
    assertEquals("urn:foo:test:7", action.getValue());
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.SoapFault) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) Exchange(org.apache.cxf.message.Exchange) Test(org.junit.Test)

Example 69 with MessageInfo

use of org.apache.cxf.service.model.MessageInfo in project steve by RWTH-i5-IDSG.

the class FromAddressInterceptor method getChargeBoxId.

private String getChargeBoxId(Message message) {
    MessageContentsList lst = MessageContentsList.getContentsList(message);
    if (lst == null) {
        return null;
    }
    MessageInfo mi = (MessageInfo) message.get("org.apache.cxf.service.model.MessageInfo");
    for (MessagePartInfo mpi : mi.getMessageParts()) {
        if (CHARGEBOX_ID_HEADER.equals(mpi.getName().getLocalPart())) {
            return (String) lst.get(mpi);
        }
    }
    return null;
}
Also used : MessageContentsList(org.apache.cxf.message.MessageContentsList) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Aggregations

MessageInfo (org.apache.cxf.service.model.MessageInfo)69 QName (javax.xml.namespace.QName)41 OperationInfo (org.apache.cxf.service.model.OperationInfo)39 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)14 Test (org.junit.Test)14 Endpoint (org.apache.cxf.endpoint.Endpoint)13 Method (java.lang.reflect.Method)9 ArrayList (java.util.ArrayList)9 Service (org.apache.cxf.service.Service)9 MessageContentsList (org.apache.cxf.message.MessageContentsList)8 Fault (org.apache.cxf.interceptor.Fault)7 Exchange (org.apache.cxf.message.Exchange)7 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 FaultInfo (org.apache.cxf.service.model.FaultInfo)7 Message (org.apache.cxf.message.Message)6 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)6