use of javax.xml.ws.BindingProvider in project cxf by apache.
the class JettyDigestAuthTest method setupClient.
private HTTPConduit setupClient(boolean async) throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
BindingProvider bp = (BindingProvider) greeter;
ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
HTTPClientPolicy client = new HTTPClientPolicy();
cond.setClient(client);
if (async) {
if (cond instanceof AsyncHTTPConduit) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
fail("Not an async conduit");
}
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
cond.setAuthSupplier(new DigestAuthSupplier());
}
ClientProxy.getClient(greeter).getOutInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {
public void handleMessage(Message message) throws Fault {
Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if (headers.containsKey("Proxy-Authorization")) {
throw new RuntimeException("Should not have Proxy-Authorization");
}
}
});
client.setAllowChunking(false);
return cond;
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class JettyDigestAuthTest method doTest.
private void doTest(boolean async) throws Exception {
setupClient(async);
assertEquals("Hello Alice", greeter.greetMe("Alice"));
assertEquals("Hello Bob", greeter.greetMe("Bob"));
try {
BindingProvider bp = (BindingProvider) greeter;
if (async) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("blah", "foo");
bp.getRequestContext().put(Credentials.class.getName(), creds);
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "blah");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "foo");
}
greeter.greetMe("Alice");
fail("Password was wrong, should have failed");
} catch (WebServiceException wse) {
// ignore - expected
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class CertConstraintsTest method testFailedCall.
public final void testFailedCall(String address) throws Exception {
URL url = SOAPService.WSDL_LOCATION;
SOAPService service = new SOAPService(url, SOAPService.SERVICE);
assertNotNull("Service is null", service);
final Greeter port = service.getHttpsPort();
assertNotNull("Port is null", port);
BindingProvider provider = (BindingProvider) port;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
try {
assertEquals(port.greetMe("Kitty"), "Hello Kitty");
fail("Failure expected");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
} catch (javax.xml.ws.WebServiceException ex) {
// expected
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class DirectDispatchClientTest method invokeService.
private void invokeService(boolean isDirectDispatch) {
BusFactory.setThreadDefaultBus(staticBus);
Service service = Service.create(serviceName);
service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/", "local://Greeter");
Greeter greeter = service.getPort(localPortName, Greeter.class);
if (isDirectDispatch) {
Client client = ClientProxy.getClient(greeter);
client.getOutInterceptors().add(new GZIPOutInterceptor(50));
client.getInInterceptors().add(new GZIPInInterceptor());
InvocationHandler handler = Proxy.getInvocationHandler(greeter);
BindingProvider bp = null;
if (handler instanceof BindingProvider) {
bp = (BindingProvider) handler;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(LocalConduit.DIRECT_DISPATCH, true);
}
}
String reply = greeter.greetMe("test");
assertEquals("Hello test", reply);
reply = greeter.sayHi();
assertNotNull("no response received from service", reply);
assertEquals("Bonjour", reply);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class BusShutdownTest method doWork.
private void doWork(URL wsdlUrl, String address) {
SOAPService service = new SOAPService(wsdlUrl);
assertNotNull(service);
Greeter greeter = service.getSoapPort();
// overwrite client address
InvocationHandler handler = Proxy.getInvocationHandler(greeter);
BindingProvider bp = (BindingProvider) handler;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
Client client = ClientProxy.getClient(greeter);
HTTPConduit c = (HTTPConduit) client.getConduit();
c.setClient(new HTTPClientPolicy());
c.getClient().setConnection(ConnectionType.CLOSE);
// invoke twoway call
greeter.sayHi();
}
Aggregations