Search in sources :

Example 26 with MessageInfo

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

the class WSDLServiceBuilder method checkForWrapped.

public static void checkForWrapped(OperationInfo opInfo, boolean allowRefs, boolean relaxed, Level logLevel) {
    MessageInfo inputMessage = opInfo.getInput();
    MessageInfo outputMessage = opInfo.getOutput();
    boolean passedRule = true;
    // input message must exist
    if (inputMessage == null || inputMessage.size() == 0 || (inputMessage.size() > 1 && !relaxed)) {
        passedRule = false;
    }
    if (outputMessage != null && outputMessage.size() > 1) {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_1", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    SchemaCollection schemas = opInfo.getInterface().getService().getXmlSchemaCollection();
    XmlSchemaElement inputEl = null;
    XmlSchemaElement outputEl = null;
    // RULE No.2:
    // The input message part refers to a global element declaration whose
    // local name is equal to the operation name.
    MessagePartInfo inputPart = inputMessage.getMessagePartByIndex(0);
    if (!inputPart.isElement()) {
        passedRule = false;
    } else {
        QName inputElementName = inputPart.getElementQName();
        inputEl = schemas.getElementByQName(inputElementName);
        if (inputEl == null) {
            passedRule = false;
        } else if (!opInfo.getName().getLocalPart().equals(inputElementName.getLocalPart())) {
            passedRule = relaxed;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_2", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // The output message part refers to a global element declaration
    if (outputMessage != null && outputMessage.size() == 1) {
        final MessagePartInfo outputPart = outputMessage.getMessagePartByIndex(0);
        if (outputPart != null) {
            if (!outputPart.isElement() || schemas.getElementByQName(outputPart.getElementQName()) == null) {
                passedRule = false;
            } else {
                outputEl = schemas.getElementByQName(outputPart.getElementQName());
            }
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_3", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // RULE No.4 and No5:
    // wrapper element should be pure complex type
    // Now lets see if we have any attributes...
    // This should probably look at the restricted and substitute types too.
    OperationInfo unwrapped = new UnwrappedOperationInfo(opInfo);
    MessageInfo unwrappedInput = new MessageInfo(unwrapped, MessageInfo.Type.INPUT, inputMessage.getName());
    MessageInfo unwrappedOutput = null;
    XmlSchemaComplexType xsct;
    if (inputEl.getSchemaType() instanceof XmlSchemaComplexType) {
        xsct = (XmlSchemaComplexType) inputEl.getSchemaType();
        if (hasAttributes(xsct) || (inputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, inputEl.getQName().getNamespaceURI(), unwrappedInput, allowRefs)) {
            passedRule = false;
        }
    } else {
        passedRule = false;
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_4", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    if (outputMessage != null) {
        unwrappedOutput = new MessageInfo(unwrapped, MessageInfo.Type.OUTPUT, outputMessage.getName());
        if (outputEl != null && outputEl.getSchemaType() instanceof XmlSchemaComplexType) {
            xsct = (XmlSchemaComplexType) outputEl.getSchemaType();
            if (xsct.isAbstract()) {
                passedRule = false;
            }
            if (hasAttributes(xsct) || (outputEl.isNillable() && !relaxed) || !isWrappableSequence(xsct, outputEl.getQName().getNamespaceURI(), unwrappedOutput, allowRefs)) {
                passedRule = false;
            }
        } else {
            passedRule = false;
        }
    }
    if (!passedRule) {
        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("WRAPPED_RULE_5", LOG, opInfo.getName());
        LOG.log(logLevel, message.toString());
        return;
    }
    // we are wrappable!!
    opInfo.setUnwrappedOperation(unwrapped);
    unwrapped.setInput(opInfo.getInputName(), unwrappedInput);
    if (outputMessage != null) {
        unwrapped.setOutput(opInfo.getOutputName(), unwrappedOutput);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) Message(javax.wsdl.Message) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 27 with MessageInfo

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

the class DocLiteralInInterceptorTest method testUnmarshalSourceData.

@Test
public void testUnmarshalSourceData() throws Exception {
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/multiPartDocLitBareReq.xml"));
    assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
    XMLStreamReader filteredReader = new PartialXMLStreamReader(reader, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
    // advance the xml reader to the message parts
    StaxUtils.read(filteredReader);
    assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
    Message m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    Service service = control.createMock(Service.class);
    exchange.put(Service.class, service);
    EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding());
    EasyMock.expect(service.size()).andReturn(0).anyTimes();
    EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
    Endpoint endpoint = control.createMock(Endpoint.class);
    exchange.put(Endpoint.class, endpoint);
    OperationInfo operationInfo = new OperationInfo();
    operationInfo.setProperty("operation.is.synthetic", Boolean.TRUE);
    MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName("http://foo.com", "bar"));
    messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo1"), null));
    messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo2"), null));
    messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo3"), null));
    messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo4"), null));
    for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
        mpi.setMessageContainer(messageInfo);
    }
    operationInfo.setInput("inputName", messageInfo);
    BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
    exchange.put(BindingOperationInfo.class, boi);
    EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
    BindingInfo binding = control.createMock(BindingInfo.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
    EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
    EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
    EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
    EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
    EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
    ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
    EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
    EasyMock.expect(serviceInfo.getName()).andReturn(new QName("http://foo.com", "service")).anyTimes();
    InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
    EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
    EasyMock.expect(interfaceInfo.getName()).andReturn(new QName("http://foo.com", "interface")).anyTimes();
    EasyMock.expect(endpointInfo.getName()).andReturn(new QName("http://foo.com", "endpoint")).anyTimes();
    EasyMock.expect(endpointInfo.getProperty("URI", URI.class)).andReturn(new URI("dummy")).anyTimes();
    List<OperationInfo> operations = new ArrayList<>();
    EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
    m.setExchange(exchange);
    m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
    m.setContent(XMLStreamReader.class, reader);
    control.replay();
    new DocLiteralInInterceptor().handleMessage(m);
    MessageContentsList params = (MessageContentsList) m.getContent(List.class);
    assertEquals(4, params.size());
    assertEquals("StringDefaultInputElem", ((DOMSource) params.get(0)).getNode().getFirstChild().getNodeName());
    assertEquals("IntParamInElem", ((DOMSource) params.get(1)).getNode().getFirstChild().getNodeName());
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) Message(org.apache.cxf.message.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URI(java.net.URI) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) List(java.util.List) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) MessageInfo(org.apache.cxf.service.model.MessageInfo) Exchange(org.apache.cxf.message.Exchange) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 28 with MessageInfo

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

the class ReflectionServiceFactoryBean method createOperation.

protected OperationInfo createOperation(ServiceInfo serviceInfo, InterfaceInfo intf, Method m) {
    OperationInfo op = intf.addOperation(getOperationName(intf, m));
    op.setProperty(m.getClass().getName(), m);
    op.setProperty("action", getAction(op, m));
    final Annotation[] annotations = m.getAnnotations();
    final Annotation[][] parAnnotations = m.getParameterAnnotations();
    op.setProperty(METHOD_ANNOTATIONS, annotations);
    op.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
    boolean isrpc = isRPC(m);
    if (!isrpc && isWrapped(m)) {
        UnwrappedOperationInfo uOp = new UnwrappedOperationInfo(op);
        uOp.setProperty(METHOD_ANNOTATIONS, annotations);
        uOp.setProperty(METHOD_PARAM_ANNOTATIONS, parAnnotations);
        op.setUnwrappedOperation(uOp);
        createMessageParts(intf, uOp, m);
        if (uOp.hasInput()) {
            MessageInfo msg = new MessageInfo(op, MessageInfo.Type.INPUT, uOp.getInput().getName());
            op.setInput(uOp.getInputName(), msg);
            createInputWrappedMessageParts(uOp, m, msg);
            for (MessagePartInfo p : uOp.getInput().getMessageParts()) {
                p.setConcreteName(p.getName());
            }
        }
        if (uOp.hasOutput()) {
            QName name = uOp.getOutput().getName();
            MessageInfo msg = new MessageInfo(op, MessageInfo.Type.OUTPUT, name);
            op.setOutput(uOp.getOutputName(), msg);
            createOutputWrappedMessageParts(uOp, m, msg);
            for (MessagePartInfo p : uOp.getOutput().getMessageParts()) {
                p.setConcreteName(p.getName());
            }
        }
    } else {
        if (isrpc) {
            op.setProperty(FORCE_TYPES, Boolean.TRUE);
        }
        createMessageParts(intf, op, m);
    }
    bindOperation(op, m);
    sendEvent(Event.INTERFACE_OPERATION_BOUND, op, m);
    return op;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 29 with MessageInfo

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

the class ServiceWSDLBuilder method buildService.

protected void buildService(ServiceInfo serviceInfo, Definition definition) {
    Map<QName, MessageInfo> messages = serviceInfo.getMessages();
    for (Map.Entry<QName, MessageInfo> mie : messages.entrySet()) {
        if (!mie.getKey().getNamespaceURI().equals(definition.getTargetNamespace())) {
            continue;
        }
        if (definition.getMessage(mie.getKey()) != null) {
            continue;
        }
        Message message = definition.createMessage();
        addDocumentation(message, mie.getValue().getMessageDocumentation());
        message.setUndefined(false);
        message.setQName(mie.getKey());
        for (MessagePartInfo mpi : mie.getValue().getMessageParts()) {
            Part part = definition.createPart();
            boolean elemental = mpi.isElement();
            // RFSB will turn on isElement bogusly.
            if (elemental && null == serviceInfo.getXmlSchemaCollection().getElementByQName(mpi.getElementQName())) {
                elemental = false;
            }
            if (elemental) {
                part.setElementName(mpi.getElementQName());
            } else {
                part.setTypeName(mpi.getTypeQName());
            }
            part.setName(mpi.getName().getLocalPart());
            message.addPart(part);
        }
        definition.addMessage(message);
    }
    addDocumentation(definition, serviceInfo.getTopLevelDoc());
    Service serv = definition.createService();
    addDocumentation(serv, serviceInfo.getDocumentation());
    serv.setQName(serviceInfo.getName());
    addNamespace(serviceInfo.getName().getNamespaceURI(), definition);
    addExtensibilityElements(definition, serv, getWSDL11Extensors(serviceInfo));
    definition.addService(serv);
    for (EndpointInfo ei : serviceInfo.getEndpoints()) {
        addNamespace(ei.getTransportId(), definition);
        Port port = definition.createPort();
        addDocumentation(port, ei.getDocumentation());
        port.setName(ei.getName().getLocalPart());
        port.setBinding(definition.getBinding(ei.getBinding().getName()));
        addExtensibilityElements(definition, port, getWSDL11Extensors(ei));
        serv.addPort(port);
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) Port(javax.wsdl.Port) Service(javax.wsdl.Service) Map(java.util.Map) HashMap(java.util.HashMap) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 30 with MessageInfo

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

the class BareInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("BareInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    Exchange exchange = message.getExchange();
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Endpoint ep = exchange.getEndpoint();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    ServiceInfo si = ep.getEndpointInfo().getService();
    BindingMessageInfo msgInfo = null;
    boolean client = isRequestor(message);
    Collection<OperationInfo> ops = null;
    if (bop == null) {
        ops = new ArrayList<>();
        ops.addAll(si.getInterface().getOperations());
        if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
            // TO DO : check duplicate operation with no input
            for (OperationInfo op : ops) {
                MessageInfo bmsg = op.getInput();
                if (bmsg.getMessagePartsNumber() == 0) {
                    BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
                    exchange.put(BindingOperationInfo.class, boi);
                    exchange.setOneWay(op.isOneWay());
                }
            }
        }
    } else {
        getMessageInfo(message, bop);
        if (client) {
            msgInfo = bop.getOutput();
        } else {
            msgInfo = bop.getInput();
        }
    }
    int paramNum = 0;
    while (StaxUtils.toNextElement(xmlReader)) {
        QName elName = xmlReader.getName();
        final MessagePartInfo p;
        if (msgInfo != null && msgInfo.getMessageParts() != null) {
            assert msgInfo.getMessageParts().size() > paramNum;
            p = msgInfo.getMessageParts().get(paramNum);
        } else {
            p = findMessagePart(exchange, ops, elName, client, paramNum, message);
        }
        if (p == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
        }
        final Object o;
        try {
            o = dr.read(p, xmlReader);
        } catch (Fault fault) {
            if (!isRequestor(message)) {
                fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
            }
            throw fault;
        }
        if (o != null) {
            parameters.put(p, o);
        }
        paramNum++;
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

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