Java Code Examples for org.apache.cxf.service.model.MessagePartInfo#setElement()

The following examples show how to use org.apache.cxf.service.model.MessagePartInfo#setElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMarshallWithFormQualifiedElement() throws Exception {
    ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
    testObject.setString1("twine");
    testObject.setString2("cord");

    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
    JAXBEncoderDecoder.marshall(context.createMarshaller(), testObject, part, writer);
    writer.flush();
    writer.close();
    String xmlResult = stringWriter.toString();
    // the following is a bit of a crock, but, to tell the truth, this test case most exists
    // so that it could be examined inside the debugger to see how JAXB works.
    assertTrue(xmlResult.contains(":string2>cord</ns"));
}
 
Example 2
Source File: RMEndpoint.java    From cxf with Apache License 2.0 6 votes vote down vote up
void buildCloseSequenceOperationInfo(InterfaceInfo ii, ProtocolVariation protocol) {

        OperationInfo operationInfo = null;
        MessageInfo messageInfo = null;

        RMConstants consts = protocol.getConstants();
        operationInfo = ii.addOperation(consts.getCloseSequenceOperationName());
        messageInfo = operationInfo.createMessage(consts.getCloseSequenceOperationName(),
                                                  MessageInfo.Type.INPUT);
        operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
        if (RM11Constants.NAMESPACE_URI.equals(protocol.getWSRMNamespace())) {
            MessagePartInfo partInfo = messageInfo.addMessagePart(CLOSE_PART_NAME);
            partInfo.setElementQName(consts.getCloseSequenceOperationName());
            partInfo.setElement(true);
            partInfo.setTypeClass(CloseSequenceType.class);
            messageInfo = operationInfo.createMessage(
                RM11Constants.INSTANCE.getCloseSequenceResponseOperationName(),
                MessageInfo.Type.OUTPUT);
            operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
            partInfo = messageInfo.addMessagePart(CLOSE_RESPONSE_PART_NAME);
            partInfo.setElementQName(RM11Constants.INSTANCE.getCloseSequenceResponseOperationName());
            partInfo.setElement(true);
            partInfo.setTypeClass(CloseSequenceResponseType.class);
            partInfo.setIndex(0);
        }
    }
 
Example 3
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMarshalRPCLit() throws Exception {
    QName elName = new QName("http://test_jaxb_marshall", "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);


    Document doc = DOMUtils.createDocument();
    Element elNode = doc.createElementNS(elName.getNamespaceURI(),
                                         elName.getLocalPart());
    JAXBEncoderDecoder.marshall(context.createMarshaller(),
                                new String("TestSOAPMessage"), part,  elNode);

    assertEquals("TestSOAPMessage", elNode.getFirstChild().getFirstChild().getNodeValue());
}
 
Example 4
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBare() throws Exception {
    JAXBDataBinding db = getDataBinding(TradePriceData.class);

    reader = getTestReader("../resources/sayHiDocLitBareReq.xml");
    assertNotNull(reader);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(TradePriceData.class);
    Object val = dr.read(part, reader);

    assertNotNull(val);
    assertTrue(val instanceof TradePriceData);
    assertEquals("CXF", ((TradePriceData)val).getTickerSymbol());
    assertEquals(Float.valueOf(1.0f), new Float(((TradePriceData)val).getTickerPrice()));
}
 
Example 5
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetProperty() throws Exception {
    MyCustomHandler handler = new MyCustomHandler();

    DataWriterImpl<XMLStreamWriter> dw = newDataWriter(handler);
    // Write Stuff
    TradePriceData val = new TradePriceData();
    val.setTickerSymbol("This is a symbol");
    val.setTickerPrice(1.0f);

    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    dw.write(val, part, streamWriter);
    streamWriter.flush();

    // Test MyCustomHandler
    assertTrue(handler.getUsed());
}
 
Example 6
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomNamespaces() throws Exception {
    Map<String, String> mapper = new HashMap<>();
    mapper.put("http://apache.org/hello_world_soap_http/types", "Omnia");
    mapper.put("http://cxf.apache.org/jaxb_form", "Gallia");
    ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
    testObject.setString1("twine");
    testObject.setString2("cord");

    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
    Marshaller m = context.createMarshaller();
    JAXBUtils.setNamespaceMapper(mapper, m);
    JAXBEncoderDecoder.marshall(m, testObject, part, writer);
    writer.flush();
    writer.close();
    String xmlResult = stringWriter.toString();
    // the following is a bit of a crock, but, to tell the truth, this test case most exists
    // so that it could be examined inside the debugger to see how JAXB works.
    assertTrue(xmlResult.contains("Gallia:string2"));
}
 
Example 7
Source File: RMEndpoint.java    From cxf with Apache License 2.0 5 votes vote down vote up
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());

    }
 
Example 8
Source File: DispatchImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addInvokeOperation(boolean oneWay) {
    String name = oneWay ? INVOKE_ONEWAY_NAME : INVOKE_NAME;

    ServiceInfo info = client.getEndpoint().getEndpointInfo().getService();
    OperationInfo opInfo = info.getInterface()
        .addOperation(oneWay ? INVOKE_ONEWAY_QNAME : INVOKE_QNAME);
    MessageInfo mInfo = opInfo.createMessage(new QName(DISPATCH_NS, name + "Request"), Type.INPUT);
    opInfo.setInput(name + "Request", mInfo);
    MessagePartInfo mpi = mInfo.addMessagePart("parameters");
    if (context == null) {
        mpi.setTypeClass(cl);
    }
    mpi.setElement(true);

    if (!oneWay) {
        mInfo = opInfo.createMessage(new QName(DISPATCH_NS, name + "Response"), Type.OUTPUT);
        opInfo.setOutput(name + "Response", mInfo);
        mpi = mInfo.addMessagePart("parameters");
        mpi.setElement(true);
        if (context == null) {
            mpi.setTypeClass(cl);
        }
    }

    for (BindingInfo bind : client.getEndpoint().getEndpointInfo().getService().getBindings()) {
        BindingOperationInfo bo = new BindingOperationInfo(bind, opInfo);
        bind.addOperation(bo);
    }
}
 
Example 9
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteBare() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(TradePriceData.class);

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    TradePriceData val = new TradePriceData();
    val.setTickerSymbol("This is a symbol");
    val.setTickerPrice(1.0f);

    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    dw.write(val, part, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_doc_lit_bare/types", "tickerSymbol"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("This is a symbol", reader.getText());
}
 
Example 10
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteRPCLit2() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(MyComplexStruct.class);

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    MyComplexStruct val = new MyComplexStruct();
    val.setElem1("This is element 1");
    val.setElem2("This is element 2");
    val.setElem3(1);

    QName elName = new QName("http://apache.org/hello_world_rpclit/types",
                             "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    dw.write(val, part, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "in"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "elem1"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("This is element 1", reader.getText());
}
 
Example 11
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteRPCLit1() throws Exception {
    JAXBDataBinding db = getTestWriterFactory();

    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);

    String val = new String("TESTOUTPUTMESSAGE");
    QName elName = new QName("http://apache.org/hello_world_rpclit/types",
                             "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    dw.write(val, part, streamWriter);
    streamWriter.flush();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "in"),
                 reader.getName());

    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("TESTOUTPUTMESSAGE", reader.getText());
}
 
Example 12
Source File: XMLStreamDataWriterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetPropertyWithCustomExceptionHandling() throws Exception {
    MyCustomMarshallerHandler handler = new MyCustomMarshallerHandler();

    DataWriterImpl<XMLStreamWriter> dw = newDataWriter(handler);
    // Write Stuff
    TradePriceData val = new TradePriceData();
    val.setTickerSymbol("This is a symbol");
    val.setTickerPrice(1.0f);

    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    try {
        dw.write(val, part, streamWriter);
        streamWriter.flush();
        fail("Expected exception");
    } catch (Fault f) {
        assertTrue(f.getMessage().contains("My marshalling exception"));
    }

    // Test MyCustomHandler
    assertTrue(handler.getUsed());
    assertTrue(handler.isOnMarshalComplete());
    assertFalse(handler.isOnUnmarshalComplete());
}
 
Example 13
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshallIntoStaxEventWriter() throws Exception {
    GreetMe obj = new GreetMe();
    obj.setRequestType("Hello");
    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    FixNamespacesXMLEventWriter writer = new FixNamespacesXMLEventWriter(opFactory.createXMLEventWriter(baos));
    assertNull(writer.getMarshaller());

    //STARTDOCUMENT/ENDDOCUMENT is not required
    //writer.add(eFactory.createStartDocument("utf-8", "1.0"));
    Marshaller m = context.createMarshaller();
    JAXBEncoderDecoder.marshall(m, obj, part, writer);
    assertEquals(m, writer.getMarshaller());
    //writer.add(eFactory.createEndDocument());
    writer.flush();
    writer.close();

    //System.out.println(baos.toString());

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLInputFactory ipFactory = XMLInputFactory.newInstance();
    XMLEventReader reader = ipFactory.createXMLEventReader(bais);

    Unmarshaller um = context.createUnmarshaller();
    Object val = um.unmarshal(reader, GreetMe.class);
    assertTrue(val instanceof JAXBElement);
    val = ((JAXBElement<?>)val).getValue();
    assertTrue(val instanceof GreetMe);
    assertEquals(obj.getRequestType(),
                 ((GreetMe)val).getRequestType());
}
 
Example 14
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshallIntoStaxStreamWriter() throws Exception {
    GreetMe obj = new GreetMe();
    obj.setRequestType("Hello");
    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    FixNamespacesXMLStreamWriter writer = new FixNamespacesXMLStreamWriter(opFactory.createXMLStreamWriter(baos));

    assertNull(writer.getMarshaller());

    Marshaller m = context.createMarshaller();
    JAXBEncoderDecoder.marshall(m, obj, part, writer);
    assertEquals(m, writer.getMarshaller());
    writer.flush();
    writer.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLInputFactory ipFactory = XMLInputFactory.newInstance();
    XMLEventReader reader = ipFactory.createXMLEventReader(bais);

    Unmarshaller um = context.createUnmarshaller();
    Object val = um.unmarshal(reader, GreetMe.class);
    assertTrue(val instanceof JAXBElement);
    val = ((JAXBElement<?>)val).getValue();
    assertTrue(val instanceof GreetMe);
    assertEquals(obj.getRequestType(),
                 ((GreetMe)val).getRequestType());
}
 
Example 15
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testMarshallExceptionWithOrder() throws Exception {
    Document doc = DOMUtils.getEmptyDocument();
    Element elNode = doc.createElementNS("http://cxf.apache.org",  "ExceptionRoot");

    OrderException exception = new OrderException("Mymessage");
    exception.setAValue("avalue");
    exception.setDetail("detail");
    exception.setInfo1("info1");
    exception.setInfo2("info2");
    exception.setIntVal(10000);

    QName elName = new QName("http://cxf.apache.org", "OrderException");
    ServiceInfo serviceInfo = new ServiceInfo();
    InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
    OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org", "operation"));
    MessageInfo message = new MessageInfo(op, null, null);
    MessagePartInfo part = new MessagePartInfo(elName, message);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(OrderException.class);

    //just need a simple generic context to handle the exceptions internal primitives
    JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] {
        String.class,
    });
    JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception, part, elNode);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    StaxUtils.writeTo(elNode, bout);
    int a = bout.toString().lastIndexOf("aValue");
    int b = bout.toString().lastIndexOf("detail");
    int c = bout.toString().lastIndexOf("info1");
    int d = bout.toString().lastIndexOf("info2");
    int e = bout.toString().lastIndexOf("intVal");
    assertTrue(a < b);
    assertTrue(b < c);
    assertTrue(c < d);
    assertTrue(d < e);
    assertTrue(bout.toString().indexOf("transientValue") < 0);
    assertTrue(bout.toString(), bout.toString().indexOf("mappedField=\"MappedField\"") > 0);
}
 
Example 16
Source File: RMEndpoint.java    From cxf with Apache License 2.0 4 votes vote down vote up
void buildCreateSequenceOperationInfo(InterfaceInfo ii, ProtocolVariation protocol) {

        OperationInfo operationInfo = null;
        MessagePartInfo partInfo = null;
        MessageInfo messageInfo = null;
        RMConstants consts = protocol.getConstants();
        operationInfo = ii.addOperation(consts.getCreateSequenceOperationName());
        messageInfo = operationInfo.createMessage(consts.getCreateSequenceOperationName(),
                                                  MessageInfo.Type.INPUT);
        operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
        partInfo = messageInfo.addMessagePart(CREATE_PART_NAME);
        partInfo.setElementQName(consts.getCreateSequenceOperationName());
        partInfo.setElement(true);
        partInfo.setTypeClass(protocol.getCodec().getCreateSequenceType());

        messageInfo = operationInfo.createMessage(consts.getCreateSequenceResponseOperationName(),
                                                  MessageInfo.Type.OUTPUT);
        operationInfo.setOutput(messageInfo.getName().getLocalPart(), messageInfo);
        partInfo = messageInfo.addMessagePart(CREATE_RESPONSE_PART_NAME);
        partInfo.setElementQName(consts.getCreateSequenceResponseOperationName());
        partInfo.setElement(true);
        partInfo.setTypeClass(protocol.getCodec().getCreateSequenceResponseType());
        partInfo.setIndex(0);

        operationInfo = ii.addOperation(consts.getCreateSequenceOnewayOperationName());
        messageInfo = operationInfo.createMessage(consts.getCreateSequenceOnewayOperationName(),
                                                  MessageInfo.Type.INPUT);
        operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
        partInfo = messageInfo.addMessagePart(CREATE_PART_NAME);
        partInfo.setElementQName(consts.getCreateSequenceOnewayOperationName());
        partInfo.setElement(true);
        partInfo.setTypeClass(protocol.getCodec().getCreateSequenceType());

        operationInfo = ii.addOperation(consts.getCreateSequenceResponseOnewayOperationName());
        messageInfo = operationInfo.createMessage(consts.getCreateSequenceResponseOnewayOperationName(),
                                                  MessageInfo.Type.INPUT);
        operationInfo.setInput(messageInfo.getName().getLocalPart(), messageInfo);
        partInfo = messageInfo.addMessagePart(CREATE_RESPONSE_PART_NAME);
        partInfo.setElementQName(consts.getCreateSequenceResponseOnewayOperationName());
        partInfo.setElement(true);
        partInfo.setTypeClass(protocol.getCodec().getCreateSequenceResponseType());
    }
 
Example 17
Source File: SoapBindingFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void buildMessage(MessageInfo minfo,
                          javax.wsdl.Message msg,
                          SchemaCollection schemas,
                          int nextId,
                          String partNameFilter) {
    for (Part part : cast(msg.getParts().values(), Part.class)) {

        if (StringUtils.isEmpty(partNameFilter)
            || part.getName().equals(partNameFilter)) {

            if (StringUtils.isEmpty(part.getName())) {
                throw new RuntimeException("Problem with WSDL: part element in message "
                                           + msg.getQName().getLocalPart()
                                           + " does not specify a name.");
            }
            QName pqname = new QName(minfo.getName().getNamespaceURI(), part.getName());
            MessagePartInfo pi = minfo.getMessagePart(pqname);
            if (pi != null
                && pi.getMessageInfo().getName().equals(msg.getQName())) {
                continue;
            }
            pi = minfo.addOutOfBandMessagePart(pqname);

            if (!minfo.getName().equals(msg.getQName())) {
                pi.setMessageContainer(new MessageInfo(minfo.getOperation(), null, msg.getQName()));
            }

            if (part.getTypeName() != null) {
                pi.setTypeQName(part.getTypeName());
                pi.setElement(false);
                pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName()));
            } else {
                pi.setElementQName(part.getElementName());
                pi.setElement(true);
                pi.setXmlSchema(schemas.getElementByQName(part.getElementName()));
            }
            pi.setProperty(OUT_OF_BAND_HEADER, Boolean.TRUE);
            pi.setProperty(HEADER, Boolean.TRUE);
            pi.setIndex(nextId);
            nextId++;
        }
    }
}
 
Example 18
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null
        && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG,
                                                           getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;

    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }

    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());

    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());

    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();

    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());

    sendEvent(Event.SERVICE_SET, getService());

    createInterface(serviceInfo);


    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();

    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }

    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method)opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }

        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }

        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName)fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
 
Example 19
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {

        MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();

        final List<MessagePartInfo> messageParts = message.getMessageParts();
        if (messageParts.isEmpty()) {
            return;
        }

        Method method = (Method)opInfo.getProperty(METHOD);
        int paraNumber = 0;
        for (MessagePartInfo mpi : messageParts) {
            SchemaInfo schemaInfo = null;
            XmlSchema schema = null;

            QName qname = (QName)mpi.getProperty(ELEMENT_NAME);
            if (messageParts.size() == 1 && qname == null) {
                qname = !isOut ? getInParameterName(opInfo, method, -1)
                        : getOutParameterName(opInfo, method, -1);

                if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                    qname = isOut
                        ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname
                            .getNamespaceURI(), method.getName());
                }
            } else if (isOut && messageParts.size() > 1 && qname == null) {
                while (!isOutParam(method, paraNumber)) {
                    paraNumber++;
                }
                qname = getOutParameterName(opInfo, method, paraNumber);
            } else if (qname == null) {
                qname = getInParameterName(opInfo, method, paraNumber);
            }

            for (SchemaInfo s : serviceInfo.getSchemas()) {
                if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                    schemaInfo = s;
                    break;
                }
            }

            if (schemaInfo == null) {
                schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
                schema = schemaInfo.getSchema();
            } else {
                schema = schemaInfo.getSchema();
                if (schema != null && schema.getElementByName(qname) != null) {
                    mpi.setElement(true);
                    mpi.setElementQName(qname);
                    mpi.setXmlSchema(schema.getElementByName(qname));
                    paraNumber++;
                    continue;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            XmlSchemaElement el = new XmlSchemaElement(schema, true);
            el.setName(qname.getLocalPart());
            el.setNillable(true);

            if (mpi.isElement()) {
                XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema();
                if (null != oldEl && !oldEl.getQName().equals(qname)) {
                    el.setSchemaTypeName(oldEl.getSchemaTypeName());
                    el.setSchemaType(oldEl.getSchemaType());
                    if (oldEl.getSchemaTypeName() != null) {
                        addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                    }
                }
                mpi.setElement(true);
                mpi.setXmlSchema(el);
                mpi.setElementQName(qname);
                mpi.setConcreteName(qname);
                continue;
            }
            if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
                throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG,
                                                                   method.getDeclaringClass().getName(),
                                                                   method.getName(),
                                                                   mpi.getName()));
            }
            if (mpi.getTypeQName() != null) {
                el.setSchemaTypeName(mpi.getTypeQName());
            } else {
                el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
            }
            mpi.setXmlSchema(el);
            mpi.setConcreteName(qname);
            if (mpi.getTypeQName() != null) {
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }

            mpi.setElement(true);
            mpi.setElementQName(qname);
            paraNumber++;
        }
    }