use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class EncoderDecoder method getDataBinding.
/**
* Get the databinding used for the header objects
* @return databinding
*/
protected DataBinding getDataBinding() throws JAXBException {
DataBinding result = databinding;
if (result == null) {
synchronized (this) {
result = databinding;
if (result == null) {
result = new JAXBDataBinding(getContext());
databinding = result;
}
}
}
return result;
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class DispatchImpl method getPayloadElementName.
private QName getPayloadElementName(Object object) {
JAXBDataBinding dataBinding = new JAXBDataBinding();
dataBinding.setContext(context);
DataWriter<XMLStreamWriter> dbwriter = dataBinding.createWriter(XMLStreamWriter.class);
StringWriter stringWriter = new StringWriter();
XMLStreamWriter resultWriter = StaxUtils.createXMLStreamWriter(stringWriter);
DepthXMLStreamReader reader = null;
try {
dbwriter.write(object, resultWriter);
resultWriter.flush();
if (!StringUtils.isEmpty(stringWriter.toString())) {
ByteArrayInputStream binput = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes());
XMLStreamReader xmlreader = StaxUtils.createXMLStreamReader(binput);
reader = new DepthXMLStreamReader(xmlreader);
StaxUtils.skipToStartOfElement(reader);
return reader.getName();
}
} catch (XMLStreamException e) {
// ignore
} finally {
try {
StaxUtils.close(reader);
} catch (XMLStreamException e) {
// ignore
}
StaxUtils.close(resultWriter);
}
return null;
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class ServiceImpl method createDispatch.
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
// using this instead of JaxWsClientFactoryBean so that handlers are configured
JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
// Initialize Features.
configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
final AbstractServiceFactoryBean sf;
try {
DataBinding db;
if (context != null) {
db = new JAXBDataBinding(context);
} else {
db = new SourceDataBinding(type);
}
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
}
JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
// if the client factory has properties specified, then set those into the endpoint
if (clientFac.getProperties() != null) {
endpoint.putAll(clientFac.getProperties());
}
// add all the client factory features onto the endpoint feature list
endpoint.getFeatures().addAll(clientFac.getFeatures());
// if the client factory has a bus specified (other than the thread default),
// then use that for the client. Otherwise use the bus from this service.
Bus clientBus = getBus();
if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
clientBus = clientFac.getBus();
}
@SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
// CXF-3956
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
endpoint.getJaxwsBinding().setHandlerChain(hc);
// create the client object, then initialize the endpoint features against it
Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
for (Feature af : endpoint.getFeatures()) {
af.initialize(client, clientBus);
}
// CXF-2822
initIntercepors(client, clientFac);
if (executor != null) {
client.getEndpoint().setExecutor(executor);
}
// then try to get it from the wsdl
if (!StringUtils.isEmpty(clientFac.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
} else {
// Set the the EPR's address in EndpointInfo
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
}
}
Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
configureObject(disp);
return disp;
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class SimpleDocLitWrappedImpl method echoWithHeader.
public String echoWithHeader(String what) {
List<Header> headers = new ArrayList<>();
Header dummyHeader;
try {
dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "decapitated", new JAXBDataBinding(String.class));
} catch (JAXBException e) {
throw new RuntimeException(e);
}
headers.add(dummyHeader);
context.getMessageContext().put(Header.HEADER_LIST, headers);
return what;
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class SerializationTest method testDeserialization.
@Test
public void testDeserialization() throws Exception {
setupClientAndRhino("simple-dlwu-proxy-factory");
testUtilities.readResourceIntoRhino("/deserializationTests.js");
DataBinding dataBinding = new JAXBDataBinding(TestBean1.class, TestBean2.class);
assertNotNull(dataBinding);
TestBean1 bean = new TestBean1();
bean.stringItem = "bean1>stringItem";
bean.doubleItem = -1.0;
String serialized = serializeObject(dataBinding, bean);
testUtilities.rhinoCallInContext("deserializeTestBean3_1", serialized);
bean = new TestBean1();
bean.stringItem = null;
bean.intItem = 21;
bean.longItem = 200000001;
bean.optionalIntItem = 456123;
bean.optionalIntArrayItem = new int[4];
bean.optionalIntArrayItem[0] = 3;
bean.optionalIntArrayItem[1] = 1;
bean.optionalIntArrayItem[2] = 4;
bean.optionalIntArrayItem[3] = 1;
bean.doubleItem = -1.0;
serialized = serializeObject(dataBinding, bean);
testUtilities.rhinoCallInContext("deserializeTestBean3_2", serialized);
}
Aggregations