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);
}
}
}
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());
}
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());
}
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());
}
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;
}
Aggregations