Search in sources :

Example 21 with MessageInfo

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

the class JaxWsServiceFactoryBeanTest method testDocLiteralPartWithType.

@Test
public void testDocLiteralPartWithType() throws Exception {
    ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
    serviceFactory.setBus(getBus());
    serviceFactory.setServiceClass(NoBodyPartsImpl.class);
    Service service = serviceFactory.create();
    ServiceInfo serviceInfo = service.getServiceInfos().get(0);
    QName qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "operation1");
    MessageInfo mi = serviceInfo.getMessage(qname);
    qname = new QName("urn:org:apache:cxf:no_body_parts/wsdl", "mimeAttachment");
    MessagePartInfo mpi = mi.getMessagePart(qname);
    QName elementQName = mpi.getElementQName();
    XmlSchemaElement element = serviceInfo.getXmlSchemaCollection().getElementByQName(elementQName);
    assertNotNull(element);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 22 with MessageInfo

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

the class Wsdl11AttachmentPolicyProvider method getEffectivePolicy.

/**
 * The effective policy for a specific WSDL message (input or output) is calculated
 * in relation to a specific port, and includes the element policy of the wsdl:message
 * element that defines the message's type merged with the element policy of the
 * wsdl11:binding and wsdl11:portType message definitions that describe the message.
 * For example, the effective policy of a specific input message for a specific port
 * would be the (element policies of the) wsdl11:message element defining the message type,
 * the wsdl11:portType/wsdl11:operation/wsdl11:input element and the corresponding
 * wsdl11:binding/wsdl11:operation/wsdl11:input element for that message.
 *
 * @param bmi the BindingMessageInfo identifiying the message
 * @return the effective policy
 */
public Policy getEffectivePolicy(BindingMessageInfo bmi, Message m) {
    ServiceInfo si = bmi.getBindingOperation().getBinding().getService();
    DescriptionInfo di = si.getDescription();
    Policy p = getElementPolicy(bmi, false, di);
    MessageInfo mi = bmi.getMessageInfo();
    p = mergePolicies(p, getElementPolicy(mi, true, di));
    Extensible ex = getMessageTypeInfo(mi.getName(), di);
    p = mergePolicies(p, getElementPolicy(ex, false, di));
    return p;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Policy(org.apache.neethi.Policy) Extensible(org.apache.cxf.service.model.Extensible) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 23 with MessageInfo

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

the class PolicyBasedWSS4JStaxInInterceptor method createPolicyEnforcer.

private PolicyEnforcer createPolicyEnforcer(EndpointInfo endpointInfo, SoapMessage msg) throws WSSPolicyException {
    EffectivePolicy dispatchPolicy = null;
    List<OperationPolicy> operationPolicies = new ArrayList<>();
    Collection<BindingOperationInfo> bindingOperationInfos = endpointInfo.getBinding().getOperations();
    for (Iterator<BindingOperationInfo> bindingOperationInfoIterator = bindingOperationInfos.iterator(); bindingOperationInfoIterator.hasNext(); ) {
        BindingOperationInfo bindingOperationInfo = bindingOperationInfoIterator.next();
        QName operationName = bindingOperationInfo.getName();
        // todo: I'm not sure what the effectivePolicy exactly contains,
        // a) only the operation policy,
        // or b) all policies for the service,
        // or c) all policies which applies for the current operation.
        // c) is that what we need for stax.
        EffectivePolicy policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-serve-request");
        // PolicyEngineImpl.POLICY_INFO_REQUEST_SERVER);
        if (MessageUtils.isRequestor(msg)) {
            policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-client-response");
            // Save the Dispatch Policy as it may be used on another BindingOperationInfo
            if (policy != null && "http://cxf.apache.org/jaxws/dispatch".equals(operationName.getNamespaceURI())) {
                dispatchPolicy = policy;
            }
            if (bindingOperationInfo.getOutput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getOutput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        } else {
            if (bindingOperationInfo.getInput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getInput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        }
        SoapOperationInfo soapOperationInfo = bindingOperationInfo.getExtensor(SoapOperationInfo.class);
        if (soapOperationInfo != null && policy == null && dispatchPolicy != null) {
            policy = dispatchPolicy;
        }
        if (policy != null && soapOperationInfo != null) {
            String soapNS;
            BindingInfo bindingInfo = bindingOperationInfo.getBinding();
            if (bindingInfo instanceof SoapBindingInfo) {
                soapNS = ((SoapBindingInfo) bindingInfo).getSoapVersion().getNamespace();
            } else {
                // most probably throw an exception:
                throw new IllegalArgumentException("BindingInfo is not an instance of SoapBindingInfo");
            }
            OperationPolicy operationPolicy = new OperationPolicy(operationName);
            operationPolicy.setPolicy(policy.getPolicy());
            operationPolicy.setOperationAction(soapOperationInfo.getAction());
            operationPolicy.setSoapMessageVersionNamespace(soapNS);
            operationPolicies.add(operationPolicy);
        }
    }
    String soapAction = SoapActionInInterceptor.getSoapAction(msg);
    if (soapAction == null) {
        soapAction = "";
    }
    String actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
    final Collection<org.apache.cxf.message.Attachment> attachments = msg.getAttachments();
    int attachmentCount = 0;
    if (attachments != null && !attachments.isEmpty()) {
        attachmentCount = attachments.size();
    }
    return new PolicyEnforcer(operationPolicies, soapAction, isRequestor(msg), actor, attachmentCount, new WSS4JPolicyAsserter(msg.get(AssertionInfoMap.class)), WSSConstants.NS_SOAP12.equals(msg.getVersion().getNamespace()));
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) OperationPolicy(org.apache.wss4j.policy.stax.OperationPolicy) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEnforcer(org.apache.wss4j.policy.stax.enforcer.PolicyEnforcer)

Example 24 with MessageInfo

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

the class WrappedOutInterceptor method handleMessage.

public void handleMessage(Message message) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
    if (bop != null && bop.isUnwrapped()) {
        XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
        MessageInfo messageInfo;
        if (isRequestor(message)) {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
        } else {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
        }
        QName name = messageInfo.getFirstMessagePart().getConcreteName();
        try {
            String pfx = null;
            Service service = message.getExchange().getService();
            if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
                pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
            }
            if (pfx == null) {
                pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
            }
            xmlWriter.setPrefix(pfx, name.getNamespaceURI());
            xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
            } else {
                xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
            }
        } catch (XMLStreamException e) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
        }
        // Add a final interceptor to write end element
        message.getInterceptorChain().add(ending);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamException(javax.xml.stream.XMLStreamException) Message(org.apache.cxf.message.Message) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 25 with MessageInfo

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

the class RequestWrapperTest method testBuildRequestFields.

@Test
public void testBuildRequestFields() {
    // Test String[]
    Class<?> testingClass = GreeterArray.class;
    OperationInfo opInfo = getOperation(testingClass, "sayStringArray");
    assertNotNull(opInfo);
    RequestWrapper requestWrapper = new RequestWrapper();
    MessageInfo message = opInfo.getUnwrappedOperation().getInput();
    Method method = (Method) opInfo.getProperty("operation.method");
    List<JavaField> fields = requestWrapper.buildFields(method, message);
    assertEquals(1, fields.size());
    JavaField field = fields.get(0);
    assertEquals("arg0", field.getName());
    assertEquals("String[]", field.getType());
    // Test int[]
    opInfo = getOperation(testingClass, "sayIntArray");
    assertNotNull(opInfo);
    message = opInfo.getUnwrappedOperation().getInput();
    method = (Method) opInfo.getProperty("operation.method");
    fields = requestWrapper.buildFields(method, message);
    assertEquals(1, fields.size());
    field = fields.get(0);
    assertEquals("arg0", field.getName());
    assertEquals("int[]", field.getType());
    // Test TestDataBean[]
    opInfo = getOperation(testingClass, "sayTestDataBeanArray");
    assertNotNull(opInfo);
    message = opInfo.getUnwrappedOperation().getInput();
    method = (Method) opInfo.getProperty("operation.method");
    fields = requestWrapper.buildFields(method, message);
    assertEquals(1, fields.size());
    field = fields.get(0);
    assertEquals("arg0", field.getName());
    assertEquals("org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean[]", field.getType());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaField(org.apache.cxf.tools.common.model.JavaField) GreeterArray(org.apache.cxf.tools.fortest.withannotation.doc.GreeterArray) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Method(java.lang.reflect.Method) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Aggregations

MessageInfo (org.apache.cxf.service.model.MessageInfo)73 QName (javax.xml.namespace.QName)42 OperationInfo (org.apache.cxf.service.model.OperationInfo)42 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)38 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)15 Test (org.junit.Test)15 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)14 Endpoint (org.apache.cxf.endpoint.Endpoint)13 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)10 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 Message (org.apache.cxf.message.Message)7 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 FaultInfo (org.apache.cxf.service.model.FaultInfo)7 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)7