Search in sources :

Example 31 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project components by Talend.

the class NetSuiteClientService method setLoginHeaders.

/**
 * Set log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setLoginHeaders(PortT port) throws NetSuiteException {
    if (!StringUtils.isEmpty(credentials.getApplicationId())) {
        Object applicationInfo = createNativeApplicationInfo(credentials);
        try {
            if (applicationInfo != null) {
                Header appInfoHeader = new Header(new QName(getPlatformMessageNamespaceUri(), "applicationInfo"), applicationInfo, new JAXBDataBinding(applicationInfo.getClass()));
                setHeader(port, appInfoHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), "XML binding error", e);
        }
    }
}
Also used : NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 32 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteBare.

@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());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 33 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteWrapper.

@Test
public void testWriteWrapper() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);
    GreetMe val = new GreetMe();
    val.setRequestType("Hello");
    dw.write(val, 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_soap_http/types", "greetMe"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("Hello", reader.getText());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Test(org.junit.Test)

Example 34 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteWrapperReturn.

@Test
public void testWriteWrapperReturn() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMeResponse.class);
    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);
    GreetMeResponse retVal = new GreetMeResponse();
    retVal.setResponseType("TESTOUTPUTMESSAGE");
    dw.write(retVal, 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_soap_http/types", "greetMeResponse"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "responseType"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("TESTOUTPUTMESSAGE", reader.getText());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Example 35 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class XMLStreamDataReaderTest method newDataReader.

private DataReaderImpl<XMLStreamReader> newDataReader(ValidationEventHandler handler) throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMe.class);
    reader = getTestReader("../resources/SetPropertyValidationFailureReq.xml");
    assertNotNull(reader);
    DataReaderImpl<XMLStreamReader> dr = (DataReaderImpl<XMLStreamReader>) db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    // Build message to set custom event handler
    org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
    message.put(JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER, handler);
    message.put("unwrap.jaxb.element", true);
    dr.setProperty("org.apache.cxf.message.Message", message);
    return dr;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Aggregations

JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)51 QName (javax.xml.namespace.QName)24 Test (org.junit.Test)18 JAXBException (javax.xml.bind.JAXBException)15 Header (org.apache.cxf.headers.Header)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)12 ArrayList (java.util.ArrayList)10 DataBinding (org.apache.cxf.databinding.DataBinding)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)7 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)7 Service (org.apache.cxf.service.Service)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 JAXBContext (javax.xml.bind.JAXBContext)5 Bus (org.apache.cxf.Bus)5 URL (java.net.URL)4 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)4 HashMap (java.util.HashMap)3 List (java.util.List)3 MessageContext (javax.xml.ws.handler.MessageContext)3