Example usage for javax.xml.ws BindingProvider getRequestContext

List of usage examples for javax.xml.ws BindingProvider getRequestContext

Introduction

In this page you can find the example usage for javax.xml.ws BindingProvider getRequestContext.

Prototype

Map<String, Object> getRequestContext();

Source Link

Document

Get the context that is used to initialize the message context for request messages.

Usage

From source file:test.integ.be.e_contract.sts.CXFSTSClientTest.java

@Test
public void testExampleWebService() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus("cxf-https-trust-all.xml");
    BusFactory.setDefaultBus(bus);/*from  ww w .  ja  v a  2s. c  om*/
    // get the JAX-WS client
    URL wsdlLocation = CXFSTSClientTest.class.getResource("/example-localhost-sts.wsdl");
    ExampleService exampleService = new ExampleService(wsdlLocation,
            new QName("urn:be:e-contract:sts:example", "ExampleService"));
    ExampleServicePortType port = exampleService.getExampleServicePort();

    // set the web service address on the client stub
    BindingProvider bindingProvider = (BindingProvider) port;
    Map<String, Object> requestContext = bindingProvider.getRequestContext();
    final String WS_LOCATION = "https://localhost/iam/example";
    // final String WS_LOCATION = "https://www.e-contract.be/iam/example";
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_LOCATION);

    requestContext.put(SecurityConstants.STS_CLIENT_SOAP12_BINDING, "true");
    requestContext.put(SecurityConstants.SIGNATURE_CRYPTO, new BeIDCrypto());
    requestContext.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
    requestContext.put(SecurityConstants.SIGNATURE_USERNAME, "username");
    requestContext.put(SecurityConstants.CALLBACK_HANDLER, new ExampleSecurityPolicyCallbackHandler());
    requestContext.put(SecurityConstants.PREFER_WSMEX_OVER_STS_CLIENT_CONFIG, "true");

    // invoke the web service
    String result = port.echo("hello world");
    LOGGER.debug("result: " + result);

    bus.shutdown(true);
}

From source file:test.integ.be.e_contract.sts.CXFSTSClientTest.java

@Test
public void testSelfSignedCertificateFails() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus("cxf-https-trust-all.xml");
    BusFactory.setDefaultBus(bus);/* w w w. j  av  a  2 s  . c  om*/
    // get the JAX-WS client
    URL wsdlLocation = CXFSTSClientTest.class.getResource("/example-localhost-sts.wsdl");
    ExampleService exampleService = new ExampleService(wsdlLocation,
            new QName("urn:be:e-contract:sts:example", "ExampleService"));
    ExampleServicePortType port = exampleService.getExampleServicePort();

    // set the web service address on the client stub
    BindingProvider bindingProvider = (BindingProvider) port;
    Map<String, Object> requestContext = bindingProvider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://localhost/iam/example");

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    KeyPair keyPair = keyPairGenerator.generateKeyPair();
    PrivateKey privateKey = keyPair.getPrivate();
    PublicKey publicKey = keyPair.getPublic();
    X509Certificate certificate = getCertificate(privateKey, publicKey);
    List<X509Certificate> certificates = new LinkedList<>();
    certificates.add(certificate);

    requestContext.put(SecurityConstants.STS_CLIENT_SOAP12_BINDING, "true");
    requestContext.put(SecurityConstants.SIGNATURE_CRYPTO, new ClientCrypto(privateKey, certificates));
    requestContext.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
    requestContext.put(SecurityConstants.SIGNATURE_USERNAME, "username");
    requestContext.put(SecurityConstants.CALLBACK_HANDLER, new ExampleSecurityPolicyCallbackHandler());
    requestContext.put(SecurityConstants.PREFER_WSMEX_OVER_STS_CLIENT_CONFIG, "true");

    // invoke the web service
    try {
        port.echo("hello world");
        fail();
    } catch (SOAPFaultException e) {
        // expected
        assertTrue(e.getMessage().contains("security token"));
    }

    bus.shutdown(true);
}

From source file:test.integ.be.fedict.hsm.client.HSMProxyClientTest.java

@Test
public void testSecurityAuditGenerationByWSSecurity() throws Exception {
    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.getInstance();
    DigitalSignatureServicePortType dssPort = digitalSignatureService.getDigitalSignatureServicePort();
    BindingProvider bindingProvider = (BindingProvider) dssPort;

    String location = "http://localhost:8080/hsm-proxy-ws/dss";
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    ObjectFactory objectFactory = new ObjectFactory();
    SignRequest signRequest = objectFactory.createSignRequest();

    try {//w  w w . jav a2 s .c o m
        dssPort.sign(signRequest);
        fail();
    } catch (SOAPFaultException e) {
        LOG.debug("expected exception: " + e.getMessage());
        // expected
    }
}

From source file:test.integ.be.fedict.hsm.ws.WebServiceTest.java

private DigitalSignatureServicePortType getPort() {
    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.getInstance();
    DigitalSignatureServicePortType dssPort = digitalSignatureService.getDigitalSignatureServicePort();
    BindingProvider bindingProvider = (BindingProvider) dssPort;
    String location = this.baseURL.toString() + "dss";
    LOG.debug("location: " + location);
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);
    return dssPort;
}

From source file:test.unit.be.fedict.trust.xkms2.XKMSPortImplTest.java

@Test
public void test() throws Exception {
    int port = getFreePort();
    String address = "http://localhost:" + port + "/xkms2";
    HttpServer server = HttpServer.create(new InetSocketAddress("localhost", port), 5);
    ExecutorService threads = Executors.newFixedThreadPool(5);
    server.setExecutor(threads);/*  w w  w  .  j a v  a 2 s . c o  m*/
    server.start();

    XKMSPortType xkmsPort = new XKMSPortImpl();
    Endpoint endpoint = Endpoint.create(xkmsPort);

    HttpContext httpContext = server.createContext("/xkms2");
    LOG.debug("http context attributes: " + httpContext.getAttributes());
    endpoint.publish(httpContext);

    assertTrue(endpoint.isPublished());

    HttpClient httpClient = new HttpClient();
    GetMethod getMethod = new GetMethod(address + "?wsdl");
    int statusCode = httpClient.executeMethod(getMethod);
    LOG.debug("status code: " + statusCode);
    assertEquals(HttpServletResponse.SC_OK, statusCode);
    LOG.debug("runtime WSDL: " + getMethod.getResponseBodyAsString());

    getMethod = new GetMethod(address + "?wsdl=1");
    statusCode = httpClient.executeMethod(getMethod);
    LOG.debug("status code: " + statusCode);
    assertEquals(HttpServletResponse.SC_OK, statusCode);
    LOG.debug("runtime WSDL: " + getMethod.getResponseBodyAsString());

    XKMSService xkmsService = XKMSServiceFactory.getInstance();
    XKMSPortType xkmsPortClient = xkmsService.getXKMSPort();
    BindingProvider bindingProviderClient = (BindingProvider) xkmsPortClient;
    bindingProviderClient.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);

    // EasyMock.replay(mockServletContext);
    // ValidateResultType validateResult = xkmsPortClient.validate(null);
    // EasyMock.verify(mockServletContext);
}

From source file:uk.ac.open.lts.webmaths.CheckServlet.java

private static void setUrl(Object port, String url) {
    BindingProvider bp = (BindingProvider) port;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
}