Search in sources :

Example 1 with XMLBindingMessageFormat

use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.

the class XMLFormatValidator method findXMLFormatRootNode.

private boolean findXMLFormatRootNode(Iterator<XMLBindingMessageFormat> it, BindingOperationInfo bo, String errorPath) {
    while (it != null && it.hasNext()) {
        XMLBindingMessageFormat xmlFormat = it.next();
        if (xmlFormat.getRootNode() == null) {
            QName rootNodeName = bo.getName();
            addErrorMessage(errorPath + ": empty value of rootNode attribute, the value should be " + rootNodeName);
            return false;
        }
    }
    return true;
}
Also used : XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) QName(javax.xml.namespace.QName)

Example 2 with XMLBindingMessageFormat

use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.

the class XMLMessageOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    MessageInfo mi;
    BindingMessageInfo bmi;
    if (isRequestor(message)) {
        mi = boi.getOperationInfo().getInput();
        bmi = boi.getInput();
    } else {
        mi = boi.getOperationInfo().getOutput();
        bmi = boi.getOutput();
    }
    XMLBindingMessageFormat xmf = bmi.getExtensor(XMLBindingMessageFormat.class);
    QName rootInModel = null;
    if (xmf != null) {
        rootInModel = xmf.getRootNode();
    }
    final int mpn = mi.getMessagePartsNumber();
    if (boi.isUnwrapped() || mpn == 1) {
        // wrapper out interceptor created the wrapper
        // or if bare-one-param
        new BareOutInterceptor().handleMessage(message);
    } else {
        if (rootInModel == null) {
            rootInModel = boi.getName();
        }
        if (mpn == 0 && !boi.isUnwrapped()) {
            // write empty operation qname
            writeMessage(message, rootInModel, false);
        } else {
            // multi param, bare mode, needs write root node
            writeMessage(message, rootInModel, true);
        }
    }
    // in the end we do flush ;)
    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
    try {
        writer.flush();
    } catch (XMLStreamException e) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e));
    }
}
Also used : BareOutInterceptor(org.apache.cxf.wsdl.interceptors.BareOutInterceptor) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 3 with XMLBindingMessageFormat

use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.

the class XmlIoPlugin method createExtension.

public ExtensibilityElement createExtension(final Map<String, Object> args) throws WSDLException {
    XMLBindingMessageFormat xmlFormat = null;
    Class<?> clz = getOption(args, Class.class);
    QName qname = getOption(args, QName.class);
    ExtensibilityElement ext = registry.createExtension(clz, ToolConstants.XML_FORMAT);
    if (ext instanceof JAXBExtensibilityElement) {
        xmlFormat = (XMLBindingMessageFormat) ((JAXBExtensibilityElement) ext).getValue();
    } else {
        xmlFormat = (XMLBindingMessageFormat) ext;
    }
    xmlFormat.setRootNode(qname);
    return ext;
}
Also used : JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) QName(javax.xml.namespace.QName) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 4 with XMLBindingMessageFormat

use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.

the class JAXWSDefinitionBuilderTest method testBuildDefinitionWithXMLBinding.

@Test
public void testBuildDefinitionWithXMLBinding() {
    String qname = "http://apache.org/hello_world_xml_http/bare";
    String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();
    JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
    builder.setBus(BusFactory.getDefaultBus());
    builder.setContext(env);
    Definition def = builder.build(wsdlUrl);
    assertNotNull(def);
    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service) services.get(new QName(qname, "XMLService"));
    assertNotNull(service);
    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("XMLPort");
    assertNotNull(port);
    assertEquals(1, port.getExtensibilityElements().size());
    Object obj = port.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement) obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an AddressType", obj instanceof AddressType);
    Binding binding = port.getBinding();
    assertNotNull(binding);
    assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());
    BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
    assertNotNull(operation);
    BindingInput input = operation.getBindingInput();
    assertNotNull(input);
    assertEquals(1, input.getExtensibilityElements().size());
    obj = input.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement) obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat", obj instanceof XMLBindingMessageFormat);
}
Also used : Binding(javax.wsdl.Binding) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) AddressType(org.apache.cxf.wsdl.http.AddressType) JAXWSDefinitionBuilder(org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder) Test(org.junit.Test)

Example 5 with XMLBindingMessageFormat

use of org.apache.cxf.bindings.xformat.XMLBindingMessageFormat in project cxf by apache.

the class WSDLToXMLProcessorTest method testAllDefault.

@Test
public void testAllDefault() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToXML.main(args);
    File outputFile = new File(output, "hello_world-xmlbinding.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToXMLProcessor processor = new WSDLToXMLProcessor();
    processor.setEnvironment(env);
    processor.parseWSDL(outputFile.getAbsolutePath());
    Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLBinding"));
    if (binding == null) {
        fail("Element wsdl:binding Greeter_XMLBinding Missed!");
    }
    boolean found = false;
    for (Object obj : binding.getExtensibilityElements()) {
        if (obj instanceof XMLFormatBinding) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:binding/> Missed!");
    }
    BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
    if (bo == null) {
        fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
    }
    found = false;
    for (Object obj : bo.getBindingInput().getExtensibilityElements()) {
        if (obj instanceof XMLBindingMessageFormat && ((XMLBindingMessageFormat) obj).getRootNode().getLocalPart().equals("sayHi")) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:body rootNode=\"tns:sayHi\" /> Missed!");
    }
    Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLService"));
    if (service == null) {
        fail("Element wsdl:service Greeter_XMLService Missed!");
    }
    found = false;
    for (Object obj : service.getPort("Greeter_XMLPort").getExtensibilityElements()) {
        if (obj instanceof HTTPAddress) {
            HTTPAddress xmlHttpAddress = (HTTPAddress) obj;
            if (xmlHttpAddress.getLocationURI() != null) {
                found = true;
                break;
            }
        }
    }
    if (!found) {
        fail("Element http:address of service port Missed!");
    }
}
Also used : XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) Binding(javax.wsdl.Binding) HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) File(java.io.File) Test(org.junit.Test)

Aggregations

XMLBindingMessageFormat (org.apache.cxf.bindings.xformat.XMLBindingMessageFormat)6 QName (javax.xml.namespace.QName)5 Binding (javax.wsdl.Binding)2 BindingOperation (javax.wsdl.BindingOperation)2 Service (javax.wsdl.Service)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 JAXBExtensibilityElement (org.apache.cxf.wsdl.JAXBExtensibilityElement)2 Test (org.junit.Test)2 File (java.io.File)1 BindingInput (javax.wsdl.BindingInput)1 Definition (javax.wsdl.Definition)1 Port (javax.wsdl.Port)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 HTTPAddress (javax.wsdl.extensions.http.HTTPAddress)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 XMLFormatBinding (org.apache.cxf.bindings.xformat.XMLFormatBinding)1 Fault (org.apache.cxf.interceptor.Fault)1 Message (org.apache.cxf.message.Message)1 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)1