use of javax.xml.ws.handler.Handler 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 javax.xml.ws.handler.Handler in project cxf by apache.
the class JaxWsClientTest method testSoapHandler.
@Test
public void testSoapHandler() {
URL url = getClass().getResource("/wsdl/hello_world.wsdl");
javax.xml.ws.Service s = javax.xml.ws.Service.create(url, SERVICE_NAME);
Greeter greeter = s.getPort(PORT_NAME, Greeter.class);
d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
@SuppressWarnings("rawtypes") List<Handler> chain = ((BindingProvider) greeter).getBinding().getHandlerChain();
chain.add(new SOAPHandler<SOAPMessageContext>() {
public boolean handleMessage(SOAPMessageContext context) {
Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
headers = CastUtils.cast((Map<?, ?>) context.get(MessageContext.HTTP_REQUEST_HEADERS));
if (headers == null) {
headers = new HashMap<>();
context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
}
headers.put("My-Custom-Header", Collections.singletonList("value"));
}
return true;
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public Set<QName> getHeaders() {
return null;
}
public void close(MessageContext messageContext) {
}
});
((BindingProvider) greeter).getBinding().setHandlerChain(chain);
String response = greeter.sayHi();
assertNotNull(response);
assertTrue("custom header should be present", headers.containsKey("My-Custom-Header"));
assertTrue("existing SOAPAction header should not be removed", headers.containsKey("SOAPAction"));
}
use of javax.xml.ws.handler.Handler in project cxf by apache.
the class HandlerChainInvokerTest method setUp.
@Before
public void setUp() {
AbstractHandlerBase.clear();
@SuppressWarnings("rawtypes") List<Handler> handlers = new ArrayList<>();
for (int i = 0; i < logicalHandlers.length; i++) {
logicalHandlers[i] = new TestLogicalHandler();
handlers.add(logicalHandlers[i]);
}
for (int i = 0; i < protocolHandlers.length; i++) {
protocolHandlers[i] = new TestProtocolHandler();
handlers.add(protocolHandlers[i]);
}
invoker = new HandlerChainInvoker(handlers);
message = new MessageImpl();
Exchange e = new ExchangeImpl();
message.setExchange(e);
lmc = new LogicalMessageContextImpl(message);
pmc = new WrappedMessageContext(message);
/*
payload = new DOMSource();
message.setContent(Source.class, payload);*/
}
use of javax.xml.ws.handler.Handler in project cxf by apache.
the class JakartaAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBindingWildcard.
@Test
public void testFindHandlerChainAnnotationPerPortServiceBindingWildcard() {
JakartaHandlerTestImpl handlerTestImpl = new JakartaHandlerTestImpl();
AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
QName portQName = new QName("http://apache.org/handler_test", "SoapPortWildcard");
QName serviceQName = new QName("http://apache.org/handler_test", "SoapServiceWildcard");
String bindingID = "BindingUnknow";
@SuppressWarnings("rawtypes") List<Handler> handlers = chainBuilder.buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, serviceQName, bindingID);
assertNotNull(handlers);
assertEquals(7, handlers.size());
}
use of javax.xml.ws.handler.Handler in project cxf by apache.
the class JakartaAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBinding.
@Test
public void testFindHandlerChainAnnotationPerPortServiceBinding() {
JakartaHandlerTestImpl handlerTestImpl = new JakartaHandlerTestImpl();
AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
QName portQName = new QName("namespacedoesntsupportyet", "SoapPort1");
QName serviceQName = new QName("namespacedoesntsupportyet", "SoapService1");
String bindingID = "http://schemas.xmlsoap.org/wsdl/soap/http";
@SuppressWarnings("rawtypes") List<Handler> handlers = chainBuilder.buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, serviceQName, bindingID);
assertNotNull(handlers);
assertEquals(5, handlers.size());
}
Aggregations