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

The following examples show how to use org.apache.cxf.service.model.MessagePartInfo#setTypeClass() . 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 testUnmarshallFromStaxEventReader() throws Exception {
    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    XMLInputFactory factory = XMLInputFactory.newInstance();
    FixNamespacesXMLEventReader reader = new FixNamespacesXMLEventReader(factory.createXMLEventReader(is));

    assertNull(reader.getUnmarshaller());

    part.setTypeClass(GreetMe.class);
    Unmarshaller um = context.createUnmarshaller();
    Object val = JAXBEncoderDecoder.unmarshall(um, reader, part, true);
    assertEquals(um, reader.getUnmarshaller());
    assertNotNull(val);
    assertTrue(val instanceof GreetMe);
    assertEquals("TestSOAPInputPMessage",
                 ((GreetMe)val).getRequestType());

    is.close();
}
 
Example 2
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 3
Source File: JAXRSServiceImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void createMessagePartInfo(OperationInfo oi, Class<?> type, QName qname, Method m,
                                   boolean input) {
    if (type == void.class || Source.class.isAssignableFrom(type)) {
        return;
    }
    if (InjectionUtils.isPrimitive(type) || Response.class == type) {
        return;
    }
    QName mName = new QName(qname.getNamespaceURI(),
                            (input ? "in" : "out") + m.getName());
    MessageInfo ms = oi.createMessage(mName,
                                       input ? MessageInfo.Type.INPUT : MessageInfo.Type.OUTPUT);
    if (input) {
        oi.setInput("in", ms);
    } else {
        oi.setOutput("out", ms);
    }
    QName mpQName = JAXRSUtils.getClassQName(type);
    MessagePartInfo mpi = ms.addMessagePart(mpQName);
    mpi.setConcreteName(mpQName);
    mpi.setTypeQName(mpQName);
    mpi.setTypeClass(type);
}
 
Example 4
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 5
Source File: JAXBEncoderDecoderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnmarshallFromStaxStreamReader() throws Exception {
    QName elName = new QName(wrapperAnnotation.targetNamespace(),
                             wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);

    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = factory.createXMLStreamReader(is);

    QName[] tags = {SOAP_ENV, SOAP_BODY};
    StaxStreamFilter filter = new StaxStreamFilter(tags);
    FixNamespacesXMLStreamReader filteredReader = new FixNamespacesXMLStreamReader(
            factory.createFilteredReader(reader, filter));

    assertNull(filteredReader.getUnmarshaller());

    //Remove START_DOCUMENT & START_ELEMENT pertaining to Envelope and Body Tags.

    part.setTypeClass(GreetMe.class);
    Unmarshaller um = context.createUnmarshaller();
    Object val = JAXBEncoderDecoder.unmarshall(um, filteredReader, part, true);
    assertEquals(um, filteredReader.getUnmarshaller());
    assertNotNull(val);
    assertTrue(val instanceof GreetMe);
    assertEquals("TestSOAPInputPMessage",
                 ((GreetMe)val).getRequestType());

    is.close();
}
 
Example 6
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void initializeParameter(MessagePartInfo part, Class<?> rawClass, Type type) {
    if (implInfo.isWebServiceProvider()) {
        part.setTypeQName(Constants.XSD_ANYTYPE);
        part.setTypeClass(rawClass);
        return;
    }
    super.initializeParameter(part, rawClass, type);
}
 
Example 7
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 8
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 9
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected FaultInfo addFault(final InterfaceInfo service, final OperationInfo op,
                             Class<?> exClass) {
    Class<?> beanClass = getBeanClass(exClass);
    if (beanClass == null) {
        return null;
    }
    String faultMsgName = null;
    for (AbstractServiceConfiguration c : serviceConfigurations) {
        faultMsgName = c.getFaultMessageName(op, exClass, beanClass);
        if (faultMsgName != null) {
            break;
        }
    }
    if (faultMsgName == null) {
        faultMsgName = exClass.getSimpleName();
    }

    QName faultName = getFaultName(service, op, exClass, beanClass);
    FaultInfo fi = op.addFault(new QName(op.getName().getNamespaceURI(), faultMsgName),
                               new QName(op.getName().getNamespaceURI(), faultMsgName));
    fi.setProperty(Class.class.getName(), exClass);
    fi.setProperty("elementName", faultName);
    MessagePartInfo mpi = fi.addMessagePart(new QName(faultName.getNamespaceURI(),
                                                      exClass.getSimpleName()));
    mpi.setElementQName(faultName);
    mpi.setTypeClass(beanClass);
    sendEvent(Event.OPERATIONINFO_FAULT, op, exClass, fi);
    return fi;
}
 
Example 10
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 11
Source File: WrapperClassGenerator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void createWrapperClass(MessagePartInfo wrapperPart,
                                    MessageInfo messageInfo,
                                    OperationInfo op,
                                    Method method,
                                    boolean isRequest) {


    ClassWriter cw = createClassWriter();
    if (cw == null) {
        LOG.warning(op.getName() + " requires a wrapper bean but problems with"
            + " ASM has prevented creating one. Operation may not work correctly.");
        return;
    }
    QName wrapperElement = messageInfo.getName();
    boolean anonymous = factory.getAnonymousWrapperTypes();

    String pkg = getPackageName(method) + ".jaxws_asm" + (anonymous ? "_an" : "");
    String className = pkg + "."
        + StringUtils.capitalize(op.getName().getLocalPart());
    if (!isRequest) {
        className = className + "Response";
    }
    String pname = pkg + ".package-info";
    Class<?> def = findClass(pname, method.getDeclaringClass());
    if (def == null) {
        generatePackageInfo(pname, wrapperElement.getNamespaceURI(),
                            method.getDeclaringClass());
    }

    def = findClass(className, method.getDeclaringClass());
    String origClassName = className;
    int count = 0;
    while (def != null) {
        Boolean b = messageInfo.getProperty("parameterized", Boolean.class);
        if (b != null && b) {
            className = origClassName + (++count);
            def = findClass(className, method.getDeclaringClass());
        } else {
            wrapperPart.setTypeClass(def);
            wrapperBeans.add(def);
            return;
        }
    }
    String classFileName = periodToSlashes(className);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classFileName, null,
             "java/lang/Object", null);

    AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlRootElement;", true);
    av0.visit("name", wrapperElement.getLocalPart());
    av0.visit("namespace", wrapperElement.getNamespaceURI());
    av0.visitEnd();

    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlAccessorType;", true);
    av0.visitEnum("value", "Ljavax/xml/bind/annotation/XmlAccessType;", "FIELD");
    av0.visitEnd();

    av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlType;", true);
    if (!anonymous) {
        av0.visit("name", wrapperElement.getLocalPart());
        av0.visit("namespace", wrapperElement.getNamespaceURI());
    } else {
        av0.visit("name", "");
    }
    av0.visitEnd();

    // add constructor
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    Label lbegin = createLabel();
    mv.visitLabel(lbegin);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    Label lend = createLabel();
    mv.visitLabel(lend);
    mv.visitLocalVariable("this", "L" + classFileName + ";", null, lbegin, lend, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
        generateMessagePart(cw, mpi, method, classFileName);
    }

    cw.visitEnd();

    Class<?> clz = loadClass(className, method.getDeclaringClass(), cw.toByteArray());
    wrapperPart.setTypeClass(clz);
    wrapperBeans.add(clz);
}
 
Example 12
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());
    }