use of javax.xml.ws.BindingProvider in project cxf by apache.
the class UsernameOnBehalfOfCachingTest method testAppliesToCaching.
/**
* Test caching the issued token when the STSClient is deployed in an intermediary
*/
@org.junit.Test
public void testAppliesToCaching() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = UsernameOnBehalfOfCachingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = UsernameOnBehalfOfCachingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItOBOAsymmetricSAML2BearerPort4");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, PORT);
TokenTestUtils.updateSTSPort((BindingProvider) port, STSPORT2);
// Disable storing tokens per-proxy
((BindingProvider) port).getRequestContext().put(SecurityConstants.CACHE_ISSUED_TOKEN_IN_ENDPOINT, "false");
// Make a successful invocation
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "alice");
BindingProvider p = (BindingProvider) port;
p.getRequestContext().put(SecurityConstants.STS_APPLIES_TO, "http://localhost:" + PORT + "/doubleit/services/doubleitasymmetricnew");
doubleIt(port, 25);
// Make a successful invocation
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "bob");
p.getRequestContext().put(SecurityConstants.STS_APPLIES_TO, "http://localhost:" + PORT + "/doubleit/services/doubleitasymmetricnew2");
doubleIt(port, 25);
// Change the STSClient so that it can no longer find the STS
clearSTSClient(p);
// Make a successful invocation - should work as token is cached
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "alice");
p.getRequestContext().put(SecurityConstants.STS_APPLIES_TO, "http://localhost:" + PORT + "/doubleit/services/doubleitasymmetricnew");
doubleIt(port, 25);
// Make a successful invocation - should work as token is cached
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "bob");
p.getRequestContext().put(SecurityConstants.STS_APPLIES_TO, "http://localhost:" + PORT + "/doubleit/services/doubleitasymmetricnew2");
doubleIt(port, 25);
// Change appliesTo - should fail
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "alice");
p.getRequestContext().put(SecurityConstants.STS_APPLIES_TO, "http://localhost:" + PORT + "/doubleit/services/doubleitasymmetricnew2");
try {
doubleIt(port, 30);
fail("Failure expected");
} catch (Exception ex) {
//
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class Client method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Please specify the WSDL file.");
System.exit(1);
}
URL wsdlURL;
File wsdlFile = new File(args[0]);
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
System.out.println(wsdlURL);
TestMtomService tms = new TestMtomService(wsdlURL, SERVICE_NAME);
TestMtomPortType port = (TestMtomPortType) tms.getPort(PORT_NAME, TestMtomPortType.class);
Binding binding = ((BindingProvider) port).getBinding();
((SOAPBinding) binding).setMTOMEnabled(true);
URL fileURL = Client.class.getResource("/me.bmp");
File aFile = new File(new URI(fileURL.toString()));
long fileSize = aFile.length();
System.out.println("Filesize of me.bmp image is: " + fileSize);
System.out.println("\nStarting MTOM Test using basic byte array:");
Holder<String> name = new Holder<String>("Sam");
Holder<byte[]> param = new Holder<byte[]>();
param.value = new byte[(int) fileSize];
InputStream in = fileURL.openStream();
int len = in.read(param.value);
while (len < fileSize) {
len += in.read(param.value, len, (int) (fileSize - len));
}
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testByteArray(name, param);
System.out.println("--Received byte[] back from server, returned size is " + param.value.length);
System.out.println("--Returned string value is " + name.value);
Image image = ImageIO.read(new ByteArrayInputStream(param.value));
System.out.println("--Loaded image from byte[] successfully, hashCode=" + image.hashCode());
System.out.println("Successfully ran MTOM/byte array demo");
System.out.println("\nStarting MTOM test with DataHandler:");
name.value = "Bob";
Holder<DataHandler> handler = new Holder<DataHandler>();
handler.value = new DataHandler(fileURL);
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testDataHandler(name, handler);
InputStream mtomIn = handler.value.getInputStream();
fileSize = 0;
for (int i = mtomIn.read(); i != -1; i = mtomIn.read()) {
fileSize++;
}
System.out.println("--Received DataHandler back from server, " + "returned size is " + fileSize);
System.out.println("--Returned string value is " + name.value);
System.out.println("Successfully ran MTOM/DataHandler demo");
System.exit(0);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class JaxWsClientThreadTest method testRequestContextThreadSafety.
@Test
public void testRequestContextThreadSafety() throws Throwable {
URL url = getClass().getResource("/wsdl/hello_world.wsdl");
javax.xml.ws.Service s = javax.xml.ws.Service.create(url, serviceName);
final Greeter greeter = s.getPort(portName, Greeter.class);
final InvocationHandler handler = Proxy.getInvocationHandler(greeter);
((BindingProvider) handler).getRequestContext().put(JaxWsClientProxy.THREAD_LOCAL_REQUEST_CONTEXT, Boolean.TRUE);
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
String address = (String) requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
final Throwable[] errorHolder = new Throwable[1];
Runnable r = new Runnable() {
public void run() {
try {
final String protocol = "http-" + Thread.currentThread().getId();
for (int i = 0; i < 10; i++) {
String threadSpecificaddress = protocol + "://localhost:80/" + i;
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, threadSpecificaddress);
assertEquals("we get what we set", threadSpecificaddress, requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
try {
greeter.greetMe("Hi");
} catch (WebServiceException expected) {
// expected.getCause().printStackTrace();
MalformedURLException mue = (MalformedURLException) expected.getCause();
if (mue == null || mue.getMessage() == null) {
throw expected;
}
assertTrue("protocol contains thread id from context", mue.getMessage().indexOf(protocol) != 0);
}
requestContext.remove(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
assertTrue("property is null", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
}
} catch (Throwable t) {
// capture assert failures
errorHolder[0] = t;
}
}
};
final int numThreads = 5;
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread(r);
}
for (int i = 0; i < numThreads; i++) {
threads[i].start();
}
for (int i = 0; i < numThreads; i++) {
threads[i].join();
}
if (errorHolder[0] != null) {
throw errorHolder[0];
}
// main thread contextValues are un changed
assertTrue("address from existing context has not changed", address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
// get the latest values
((ClientImpl.EchoContext) ((WrappedMessageContext) requestContext).getWrappedMap()).reload();
assertTrue("address is different", !address.equals(requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)));
// verify value reflects what other threads were doing
assertTrue("property is null from last thread execution", requestContext.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY) == null);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class ClientServerWebSocketTest method testFaults.
@Test
public void testFaults() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
ExecutorService ex = Executors.newFixedThreadPool(1);
service.setExecutor(ex);
assertNotNull(service);
String noSuchCodeFault = "NoSuchCodeLitFault";
String badRecordFault = "BadRecordLitFault";
Greeter greeter = service.getPort(portName, Greeter.class);
updateGreeterAddress(greeter, PORT);
for (int idx = 0; idx < 2; idx++) {
try {
greeter.testDocLitFault(noSuchCodeFault);
fail("Should have thrown NoSuchCodeLitFault exception");
} catch (NoSuchCodeLitFault nslf) {
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
try {
greeter.testDocLitFault(badRecordFault);
fail("Should have thrown BadRecordLitFault exception");
} catch (BadRecordLitFault brlf) {
BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
assertEquals("text/xml; charset=utf-8", contentType.toLowerCase());
Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
assertEquals(500, responseCode.intValue());
assertNotNull(brlf.getFaultInfo());
assertEquals("BadRecordLitFault", brlf.getFaultInfo());
}
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class ClientServerWebSocketTest method testBasicConnection.
@Test
public void testBasicConnection() throws Exception {
SOAPService service = new SOAPService();
Greeter greeter = service.getPort(portName, Greeter.class);
updateGreeterAddress(greeter, PORT);
try {
String reply = greeter.greetMe("test");
assertNotNull("no response received from service", reply);
assertEquals("Hello test", reply);
reply = greeter.sayHi();
assertNotNull("no response received from service", reply);
assertEquals("Bonjour", reply);
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
assertEquals(200, responseCode.intValue());
}
Aggregations