Search in sources :

Example 31 with BindingProvider

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);
}
Also used : QName(javax.xml.namespace.QName) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Greeter(org.apache.hello_world_soap_http.Greeter) BindingProvider(javax.xml.ws.BindingProvider) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Test(org.junit.Test)

Example 32 with BindingProvider

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));
}
Also used : Greeter(org.apache.hello_world_soap_http.Greeter) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 33 with BindingProvider

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
    }
}
Also used : CalculatorPortType(org.apache.cxf.calculator.CalculatorPortType) WebServiceException(javax.xml.ws.WebServiceException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with BindingProvider

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());
}
Also used : CalculatorPortType(org.apache.cxf.calculator.CalculatorPortType) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 35 with BindingProvider

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);
}
Also used : Bus(org.apache.cxf.Bus) MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) URL(java.net.URL) BusException(org.apache.cxf.BusException) EndpointException(org.apache.cxf.endpoint.EndpointException)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)147 URL (java.net.URL)87 Test (org.junit.Test)74 Service (javax.xml.ws.Service)65 QName (javax.xml.namespace.QName)41 WebServiceException (javax.xml.ws.WebServiceException)24 Greeter (org.apache.hello_world_soap_http.Greeter)23 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)18 Bus (org.apache.cxf.Bus)17 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 InvocationHandler (java.lang.reflect.InvocationHandler)14 SOAPService (org.apache.hello_world_soap_http.SOAPService)14 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)12 STSClient (org.apache.cxf.ws.security.trust.STSClient)11 Greeter (org.apache.cxf.greeter_control.Greeter)10 GreeterService (org.apache.cxf.greeter_control.GreeterService)10 SOAPBinding (javax.xml.ws.soap.SOAPBinding)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 Client (org.apache.cxf.endpoint.Client)9 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)8