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:org.apache.cxf.systest.http_undertow.UndertowDigestAuthTest.java

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();
    client.setConnectionTimeout(600000);
    client.setReceiveTimeout(600000);//ww w.  j a  va2  s. com
    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;
}

From source file:com.ning.killbill.zuora.zuora.ZuoraConnection.java

public ZuoraConnection(ZuoraConfig config) {
    this.config = config;
    try {/*from w  w  w.  j  a  v a  2 s. c o  m*/
        URL wsdlLocation = ZuoraService.class.getClassLoader()
                .getResource(ZuoraService.class.getAnnotation(WebServiceClient.class).wsdlLocation());

        this.zuoraService = new ZuoraService(wsdlLocation);
        this.stub = zuoraService.getSoap();

        BindingProvider bp = (BindingProvider) stub;
        Map<String, Object> context = bp.getRequestContext();

        context.put(ENDPOINT_ADDRESS_PROPERTY, config.getZuoraApiUrl());

        Client client = ClientProxy.getClient(stub);

        client.getInInterceptors().add(new LoggingInInterceptor());
        client.getOutInterceptors().add(new LoggingOutInterceptor());

        this.apiFactory = new com.zuora.api.ObjectFactory();
        this.objectFactory = new com.zuora.api.object.ObjectFactory();
        this.header = apiFactory.createSessionHeader();
        login();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Could not login to Zuora", ex);
    }
}

From source file:be.agiv.security.client.IPSTSClient.java

/**
 * Main constructor.//from   w  ww .j  a va  2 s  .  co m
 * 
 * @param location
 *            the location of the IP-STS WS-Trust web service.
 * @param realm
 *            the AGIV R-STS realm.
 * @param secondaryParametersNodeList
 *            the DOM node list that will be used as SecondaryParameters for
 *            RST requests.
 */
public IPSTSClient(String location, String realm, NodeList secondaryParametersNodeList) {
    this.location = location;
    this.realm = realm;

    Provider jaxwsProvider = Provider.provider();
    LOG.debug("JAX-WS provider: " + jaxwsProvider.getClass().getName());

    SecurityTokenService_Service service = SecurityTokenServiceFactory.getInstance();
    this.port = service.getSecurityTokenServicePort();
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.wsTrustHandler = new WSTrustHandler();
    this.wsTrustHandler.setSecondaryParameters(secondaryParametersNodeList);
    handlerChain.add(this.wsTrustHandler);
    this.wsAddressingHandler = new WSAddressingHandler();
    handlerChain.add(this.wsAddressingHandler);
    this.wsSecurityHandler = new WSSecurityHandler();
    handlerChain.add(this.wsSecurityHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.policyObjectFactory = new be.agiv.security.jaxb.wspolicy.ObjectFactory();
    this.addrObjectFactory = new be.agiv.security.jaxb.wsaddr.ObjectFactory();
    this.wssObjectFactory = new be.agiv.security.jaxb.wsse.ObjectFactory();

    this.secureRandom = new SecureRandom();
    this.secureRandom.setSeed(System.currentTimeMillis());
}

From source file:com.evolveum.midpoint.pwdfilter.opendj.PasswordPusher.java

ModelPortType setupMidPointConnection() {

    System.out.println("Pwd Sync Endpoint is " + endPoint);

    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);

    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

    Map<String, Object> outProps = new HashMap<String, Object>();

    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);

    outProps.put(WSHandlerConstants.USER, username);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new MidPointPasswordCallback(password));
    System.out.println("After pwd");
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);

    return modelPort;
}

From source file:test.integ.be.fedict.hsm.ws.WebServiceSecurityTest.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);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(new LoggingSOAPHandler());
    binding.setHandlerChain(handlerChain);

    return dssPort;
}

From source file:org.cloudml.connectors.FlexiantConnector.java

@SuppressWarnings("restriction")
public FlexiantConnector(String endPoint, String login, String secretKey) throws MalformedURLException {
    this.endpoint = endPoint;
    System.setProperty("jsse.enableSNIExtension", "false");

    journal.log(Level.INFO, ">> Connecting to Flexiant ...");

    URL url = ClassLoader.getSystemClassLoader().getResource("UserAdmin.wsdl");

    // Get the UserAPI
    UserAPI api = new UserAPI(url, new QName("http://extility.flexiant.net", "UserAPI"));

    // and set the service port on the service
    service = api.getUserServicePort();/* w ww.  j a v  a  2  s .c o m*/

    // Get the binding provider
    BindingProvider portBP = (BindingProvider) service;

    // and set the service endpoint
    portBP.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);

    journal.log(Level.INFO, ">> Authenticating ...");
    // and the caller's authentication details and password
    portBP.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, login);
    portBP.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, secretKey);

}

From source file:ebay.dts.client.BulkDataExchangeCall.java

private Map<String, Object> retrieveHttpHeaders(BindingProvider bp, String headerType) {

    logger.trace("headerType " + headerType);

    Map<String, Object> headerM = null;
    Map<String, Object> contextMap = null;
    String headerTypeName = null;
    if (headerType.equalsIgnoreCase("request")) {
        headerTypeName = "javax.xml.ws.http.request.headers";
        contextMap = bp.getRequestContext();
    } else {//from w w w  .  j  av  a  2s .  c om
        headerTypeName = "javax.xml.ws.http.response.headers";
        contextMap = bp.getResponseContext();
    }

    if (contextMap != null) {
        dumpMap(headerType + " context", contextMap);
        Map requestHeaders = (Map<String, List<String>>) contextMap.get(headerTypeName);
        if (requestHeaders != null) {
            headerM = insertHttpsHeadersMap(headerType, requestHeaders);
        }

    }
    return headerM;
}

From source file:com.evolveum.midpoint.cli.ninja.action.Action.java

protected ModelPortType createModelPort() {
    ModelService modelService = new ModelService();
    ModelPortType port = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) port;

    Client client = ClientProxy.getClient(port);
    Endpoint endpoint = client.getEndpoint();
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = http.getClient();
    if (httpClientPolicy == null) {
        httpClientPolicy = new HTTPClientPolicy();
        http.setClient(httpClientPolicy);
    }/*from  w  w w.j av  a  2 s .c o m*/

    httpClientPolicy.setConnectionTimeout(10000);

    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, params.getUrl().toString());

    requestContext.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    requestContext.put(WSHandlerConstants.USER, params.getUsername());
    requestContext.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);

    ClientPasswordHandler handler = new ClientPasswordHandler();
    handler.setPassword(params.getInsertedPassword());
    requestContext.put(WSHandlerConstants.PW_CALLBACK_REF, handler);

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(requestContext);
    endpoint.getOutInterceptors().add(wssOut);
    if (params.isVerbose()) {
        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
        endpoint.getInInterceptors().add(new LoggingInInterceptor());
    }

    return port;
}

From source file:be.fedict.trust.client.XKMS2Client.java

private void setEndpointAddress(String location) {
    LOG.debug("ws location: " + location);
    if (null == location) {
        throw new IllegalArgumentException("XKMS2 location URL cannot be null");
    }//from www  .ja  va2 s. c  o m
    BindingProvider bindingProvider = (BindingProvider) this.port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);
}

From source file:be.e_contract.dssp.client.DigitalSignatureServiceClient.java

/**
 * Main constructor./*from  ww w .  j a v  a 2 s.  c o m*/
 * 
 * @param address
 *            the location of the DSSP web service.
 */
public DigitalSignatureServiceClient(String address) {
    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.newInstance();
    this.dssPort = digitalSignatureService.getDigitalSignatureServicePort();

    BindingProvider bindingProvider = (BindingProvider) this.dssPort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);

    Binding binding = bindingProvider.getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    this.attachmentsSOAPHandler = new AttachmentsLogicalHandler();
    handlerChain.add(this.attachmentsSOAPHandler);
    this.wsSecuritySOAPHandler = new WSSecuritySOAPHandler();
    handlerChain.add(this.wsSecuritySOAPHandler);
    this.wsTrustSOAPHandler = new WSTrustSOAPHandler();
    handlerChain.add(this.wsTrustSOAPHandler);
    // cannot add LoggingSOAPHandler here, else we break SOAP with
    // attachments on Apache CXF
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.wstObjectFactory = new be.e_contract.dssp.ws.jaxb.wst.ObjectFactory();
    this.dsObjectFactory = new be.e_contract.dssp.ws.jaxb.xmldsig.ObjectFactory();
    this.asyncObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory();
    this.wsseObjectFactory = new be.e_contract.dssp.ws.jaxb.wsse.ObjectFactory();
    this.vrObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.vr.ObjectFactory();

    this.secureRandom = new SecureRandom();
    this.secureRandom.setSeed(System.currentTimeMillis());

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException(e);
    }
}