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 JaxWsServerFactoryBeanTest method testJaxbExtraClass.
@Test
public void testJaxbExtraClass() {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setBus(getBus());
sf.setAddress("http://localhost:9000/test");
sf.setServiceClass(Hello.class);
sf.setStart(false);
Map<String, Object> props = sf.getProperties();
if (props == null) {
props = new HashMap<>();
}
props.put("jaxb.additionalContextClasses", new Class[] { DescriptionType.class, DisplayNameType.class });
sf.setProperties(props);
Server server = sf.create();
assertNotNull(server);
Class<?>[] extraClass = ((JAXBDataBinding) sf.getServiceFactory().getDataBinding()).getExtraClass();
assertEquals(extraClass.length, 2);
assertEquals(extraClass[0], DescriptionType.class);
assertEquals(extraClass[1], DisplayNameType.class);
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class WSDiscoveryClient method addAddressing.
private void addAddressing(BindingProvider p, boolean addSeq, String action) {
AddressingProperties addrProperties = new AddressingProperties();
if (action != null) {
AttributedURIType act = new AttributedURIType();
act.setValue(action);
addrProperties.setAction(act);
}
if (adHoc) {
EndpointReferenceType to = new EndpointReferenceType();
addrProperties.exposeAs(version.getAddressingNamespace());
AttributedURIType epr = new AttributedURIType();
epr.setValue(version.getToAddress());
to.setAddress(epr);
addrProperties.setTo(to);
if (addSeq) {
AppSequenceType s = new AppSequenceType();
s.setInstanceId(instanceId);
s.setMessageNumber(msgId.getAndIncrement());
JAXBElement<AppSequenceType> seq = new ObjectFactory().createAppSequence(s);
Header h = new Header(seq.getName(), seq, new JAXBDataBinding(getJAXBContext()));
List<Header> headers = new ArrayList<>();
headers.add(h);
p.getRequestContext().put(Header.HEADER_LIST, headers);
}
} else {
addrProperties.exposeAs(version.getAddressingNamespace());
}
p.getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project tesb-rt-se by Talend.
the class FlowIdSoapCodec method writeFlowId.
/**
* Write flow id to message.
*
* @param message the message
* @param flowId the flow id
*/
public static void writeFlowId(Message message, String flowId) {
if (!(message instanceof SoapMessage)) {
return;
}
SoapMessage soapMessage = (SoapMessage) message;
Header hdFlowId = soapMessage.getHeader(FLOW_ID_QNAME);
if (hdFlowId != null) {
LOG.warning("FlowId already existing in soap header, need not to write FlowId header.");
return;
}
try {
soapMessage.getHeaders().add(new Header(FLOW_ID_QNAME, flowId, new JAXBDataBinding(String.class)));
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Stored flowId '" + flowId + "' in soap header: " + FLOW_ID_QNAME);
}
} catch (JAXBException e) {
LOG.log(Level.SEVERE, "Couldn't create flowId header.", e);
}
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project tesb-rt-se by Talend.
the class CorrelationIdSoapCodec method writeCorrelationId.
/**
* Write correlation id to message.
*
* @param message the message
* @param correlationId the correlation id
*/
public static void writeCorrelationId(Message message, String correlationId) {
if (!(message instanceof SoapMessage)) {
return;
}
SoapMessage soapMessage = (SoapMessage) message;
Header hdCorrelationId = soapMessage.getHeader(CORRELATION_ID_QNAME);
if (hdCorrelationId != null) {
LOG.warning("CorrelationId already existing in soap header, need not to write CorrelationId header.");
return;
}
if ((soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter) && (((SAAJStreamWriter) soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId").getLength() > 0)) {
LOG.warning("CorrelationId already existing in soap header, need not to write CorrelationId header.");
return;
}
try {
soapMessage.getHeaders().add(new Header(CORRELATION_ID_QNAME, correlationId, new JAXBDataBinding(String.class)));
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Stored correlationId '" + correlationId + "' in soap header: " + CORRELATION_ID_QNAME);
}
} catch (JAXBException e) {
LOG.log(Level.SEVERE, "Couldn't create correlationId header.", e);
}
}
Aggregations