Search in sources :

Example 6 with Message

use of javax.wsdl.Message 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 7 with Message

use of javax.wsdl.Message in project cxf by apache.

the class WSDLServiceBuilder method buildMessage.

private void buildMessage(AbstractMessageContainer minfo, Message msg) {
    SchemaCollection schemas = minfo.getOperation().getInterface().getService().getXmlSchemaCollection();
    List<?> orderedParam = msg.getOrderedParts(null);
    for (Part part : cast(orderedParam, Part.class)) {
        MessagePartInfo pi = minfo.addMessagePart(new QName(minfo.getName().getNamespaceURI(), part.getName()));
        if (part.getTypeName() != null) {
            pi.setTypeQName(part.getTypeName());
            pi.setElement(false);
            pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName()));
        } else if (part.getElementName() != null) {
            pi.setElementQName(part.getElementName());
            XmlSchemaElement schemaElement = schemas.getElementByQName(part.getElementName());
            if (null == schemaElement) {
                org.apache.cxf.common.i18n.Message errorMessage = new org.apache.cxf.common.i18n.Message("WSDL4J_BAD_ELEMENT_PART", LOG, part.getName(), part.getElementName());
                throw new WSDLRuntimeException(errorMessage);
            }
            pi.setElement(true);
            pi.setXmlSchema(schemaElement);
        } else {
            org.apache.cxf.common.i18n.Message errorMessage = new org.apache.cxf.common.i18n.Message("PART_NO_NAME_NO_TYPE", LOG, part.getName());
            throw new WSDLRuntimeException(errorMessage);
        }
    }
}
Also used : Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Part(javax.wsdl.Part) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 8 with Message

use of javax.wsdl.Message 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 9 with Message

use of javax.wsdl.Message in project cxf by apache.

the class ServiceWSDLBuilderTest method testSayHiOperation.

@Test
public void testSayHiOperation() throws Exception {
    setupWSDL(WSDL_PATH);
    PortType portType = newDef.getPortType(new QName(newDef.getTargetNamespace(), "Greeter"));
    Collection<Operation> operations = CastUtils.cast(portType.getOperations(), Operation.class);
    assertEquals(4, operations.size());
    Operation sayHi = portType.getOperation("sayHi", "sayHiRequest", "sayHiResponse");
    assertNotNull(sayHi);
    assertEquals(sayHi.getName(), "sayHi");
    Input input = sayHi.getInput();
    assertNotNull(input);
    assertEquals("sayHiRequest", input.getName());
    Message message = input.getMessage();
    assertNotNull(message);
    assertEquals("sayHiRequest", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("in", message.getPart("in").getName());
    Output output = sayHi.getOutput();
    assertNotNull(output);
    assertEquals("sayHiResponse", output.getName());
    message = output.getMessage();
    assertNotNull(message);
    assertEquals("sayHiResponse", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("out", message.getPart("out").getName());
    assertEquals(0, sayHi.getFaults().size());
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Output(javax.wsdl.Output) Operation(javax.wsdl.Operation) PortType(javax.wsdl.PortType) Test(org.junit.Test)

Example 10 with Message

use of javax.wsdl.Message in project cxf by apache.

the class ServiceWSDLBuilderTest method testGreetMeOperation.

@Test
public void testGreetMeOperation() throws Exception {
    setupWSDL(WSDL_PATH);
    PortType portType = newDef.getPortType(new QName(newDef.getTargetNamespace(), "Greeter"));
    Operation greetMe = portType.getOperation("greetMe", "greetMeRequest", "greetMeResponse");
    assertNotNull(greetMe);
    assertEquals("greetMe", greetMe.getName());
    Input input = greetMe.getInput();
    assertNotNull(input);
    assertEquals("greetMeRequest", input.getName());
    Message message = input.getMessage();
    assertNotNull(message);
    assertEquals("greetMeRequest", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("in", message.getPart("in").getName());
    Output output = greetMe.getOutput();
    assertNotNull(output);
    assertEquals("greetMeResponse", output.getName());
    message = output.getMessage();
    assertNotNull(message);
    assertEquals("greetMeResponse", message.getQName().getLocalPart());
    assertEquals(newDef.getTargetNamespace(), message.getQName().getNamespaceURI());
    assertEquals(1, message.getParts().size());
    assertEquals("out", message.getPart("out").getName());
    assertEquals(0, greetMe.getFaults().size());
}
Also used : Input(javax.wsdl.Input) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Output(javax.wsdl.Output) Operation(javax.wsdl.Operation) PortType(javax.wsdl.PortType) Test(org.junit.Test)

Aggregations

Message (javax.wsdl.Message)45 Part (javax.wsdl.Part)26 QName (javax.xml.namespace.QName)25 Operation (javax.wsdl.Operation)22 Input (javax.wsdl.Input)20 BindingOperation (javax.wsdl.BindingOperation)18 Output (javax.wsdl.Output)16 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)9 Map (java.util.Map)8 Binding (javax.wsdl.Binding)8 PortType (javax.wsdl.PortType)8 HashMap (java.util.HashMap)7 BindingInput (javax.wsdl.BindingInput)7 Fault (javax.wsdl.Fault)7 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)7 ArrayList (java.util.ArrayList)6 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)6 BindingOutput (javax.wsdl.BindingOutput)5 Test (org.junit.Test)5 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)4