use of javax.xml.ws.BindingProvider in project cxf by apache.
the class EndpointReferenceTest method testBindingProviderSOAPBinding.
@Test
public void testBindingProviderSOAPBinding() throws Exception {
javax.xml.ws.Service s = javax.xml.ws.Service.create(new QName("http://apache.org/hello_world_soap_http", "SoapPort"));
assertNotNull(s);
Greeter greeter = s.getPort(Greeter.class);
BindingProvider bindingProvider = (BindingProvider) greeter;
EndpointReference er = bindingProvider.getEndpointReference();
assertNotNull(er);
// If the BindingProvider instance has a binding that is either SOAP 1.1/HTTP or SOAP
// 1.2/HTTP, then a W3CEndpointReference MUST be returned.
assertTrue(er instanceof W3CEndpointReference);
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class JaxWsClientTest method testRequestContextPutAndRemoveEcho.
@Test
public void testRequestContextPutAndRemoveEcho() throws Exception {
URL url = getClass().getResource("/wsdl/hello_world.wsdl");
javax.xml.ws.Service s = javax.xml.ws.Service.create(url, serviceName);
final Greeter handler = s.getPort(portName, Greeter.class);
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
requestContext.put(JaxWsClientProxy.THREAD_LOCAL_REQUEST_CONTEXT, Boolean.TRUE);
// future calls to getRequestContext() will use a thread local request context.
// That allows the request context to be threadsafe.
requestContext = ((BindingProvider) handler).getRequestContext();
final String key = "Hi";
requestContext.put(key, "ho");
final Object[] result = new Object[2];
Thread t = new Thread() {
public void run() {
// requestContext in main thread shouldn't affect the requestContext in this thread
Map<String, Object> requestContext = ((BindingProvider) handler).getRequestContext();
result[0] = requestContext.get(key);
requestContext.remove(key);
result[1] = requestContext.get(key);
}
};
t.start();
t.join();
assertNull("thread shouldn't see the put", result[0]);
assertNull("thread did not remove the put", result[1]);
assertEquals("main thread does not see removal", "ho", requestContext.get(key));
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class SOAPBindingTest method testRoles.
@Test
public void testRoles() throws Exception {
URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
assertNotNull(wsdl1);
ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
BindingProvider bindingProvider = (BindingProvider) cal;
assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
assertNotNull(binding.getRoles());
assertEquals(2, binding.getRoles().size());
assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
String myrole = "http://myrole";
Set<String> roles = new HashSet<>();
roles.add(myrole);
binding.setRoles(roles);
assertNotNull(binding.getRoles());
assertEquals(3, binding.getRoles().size());
assertTrue(binding.getRoles().contains(myrole));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
roles.add(Soap12.getInstance().getNoneRole());
try {
binding.setRoles(roles);
fail("did not throw exception");
} catch (WebServiceException e) {
// that's expected with none role
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class SOAPBindingTest method testSAAJ.
@Test
public void testSAAJ() throws Exception {
URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
assertNotNull(wsdl1);
ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
BindingProvider bindingProvider = (BindingProvider) cal;
assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
assertNotNull(binding.getMessageFactory());
assertNotNull(binding.getSOAPFactory());
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class UsernameActAsCachingTest method testDifferentUsersCaching.
/**
* Test caching the issued token when the STSClient is deployed in an intermediary
*/
@org.junit.Test
public void testDifferentUsersCaching() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = UsernameActAsCachingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = UsernameActAsCachingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricSAML2BearerPort3");
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");
doubleIt(port, 25);
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "bob");
doubleIt(port, 30);
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "eve");
try {
doubleIt(port, 30);
fail("Failure expected on a bad user");
} catch (Exception ex) {
//
}
// Change the STSClient so that it can no longer find the STS
BindingProvider p = (BindingProvider) port;
clearSTSClient(p);
// Make a successful invocation
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "alice");
doubleIt(port, 25);
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "bob");
doubleIt(port, 30);
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "eve2");
try {
doubleIt(port, 30);
fail("Failure expected on a bad user");
} catch (Exception ex) {
//
}
// Reset the cache - this invocation should fail
p.getRequestContext().put(TokenStore.class.getName(), new MemoryTokenStore());
((BindingProvider) port).getRequestContext().put(SecurityConstants.USERNAME, "alice");
try {
doubleIt(port, 30);
fail("Failure expected");
} catch (Exception ex) {
//
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
Aggregations