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:be.e_contract.dssp.client.DigitalSignatureServiceClient.java

private String addAttachment(String mimetype, byte[] data) {
    String contentId = UUID.randomUUID().toString();
    LOG.debug("adding attachment: " + contentId);
    DataSource dataSource = new ByteArrayDataSource(data, mimetype);
    DataHandler dataHandler = new DataHandler(dataSource);
    BindingProvider bindingProvider = (BindingProvider) this.dssPort;
    Map<String, Object> requestContext = bindingProvider.getRequestContext();
    Map<String, DataHandler> outputMessageAttachments = new HashMap<String, DataHandler>();
    requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, outputMessageAttachments);
    outputMessageAttachments.put(contentId, dataHandler);
    return contentId;
}

From source file:be.fedict.eid.dss.client.DigitalSignatureServiceClient.java

private DigitalSignatureServicePortType getPort() {

    DigitalSignatureService digitalSignatureService = DigitalSignatureServiceFactory.getInstance();
    DigitalSignatureServicePortType digitalSignatureServicePort = digitalSignatureService
            .getDigitalSignatureServicePort();

    BindingProvider bindingProvider = (BindingProvider) digitalSignatureServicePort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.endpointAddress);
    return digitalSignatureServicePort;
}

From source file:com.checkmarx.jenkins.CxWebService.java

private void setClientTimeout(BindingProvider provider, int seconds) {
    logger.debug("Setting connection timeout to " + seconds + " seconds");
    int milliseconds = seconds * 1000;
    Map<String, Object> requestContext = provider.getRequestContext();
    // see https://java.net/jira/browse/JAX_WS-1166
    requestContext.put("com.sun.xml.internal.ws.connect.timeout", milliseconds);
    requestContext.put("com.sun.xml.internal.ws.request.timeout", milliseconds);
    requestContext.put("com.sun.xml.ws.request.timeout", milliseconds);
    requestContext.put("com.sun.xml.ws.connect.timeout", milliseconds);
    requestContext.put("javax.xml.ws.client.connectionTimeout", milliseconds);
    requestContext.put("javax.xml.ws.client.receiveTimeout", milliseconds);
    requestContext.put("timeout", milliseconds); // IBM
}

From source file:be.agiv.security.AGIVSecurity.java

/**
 * Enable the AGIV security on the given JAX-WS binding provider. Each
 * JAX-WS port can be casted to a JAX-WS binding provider. The JAX-WS port
 * will also be configured to use the service at the given service location.
 * /*ww  w . jav a  2 s .  com*/
 * @param bindingProvider
 *            the JAX-WS binding provider on which to enable the AGIV
 *            security framework.
 * @param serviceLocation
 *            the location of the web service.
 * @param useWsSecureConversation
 *            set to <code>true</code> if WS-SecureConversation should be
 *            used.
 * @param serviceRealm
 *            the optional service realm.
 * @see AGIVSecurity#enable(BindingProvider)
 * @see AGIVSecurity#disable(BindingProvider)
 */
public void enable(BindingProvider bindingProvider, String serviceLocation, boolean useWsSecureConversation,
        String serviceRealm) {
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceLocation);
    enable(bindingProvider, useWsSecureConversation, serviceRealm);
}

From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java

private UserGroupSoap getConnection(URL url) throws Exception {
    UserGroup ss = new UserGroup(wsdl.toURI().toURL(), SERVICE);
    UserGroupSoap port = ss.getUserGroupSoap12();

    BindingProvider provider = (BindingProvider) port;

    if (authType == AuthType.UnisonLastMile) {
        DateTime now = new DateTime();
        DateTime future = now.plusMillis(this.skew);
        now = now.minusMillis(skew);//  w  ww .  j ava 2  s  . co  m
        com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile(
                url.getPath(), now, future, 0, "chainName");
        lastmile.getAttributes().add(new Attribute("userPrincipalName", this.administratorUPN));

        SecretKey sk = this.cfg.getSecretKey(this.keyAlias);
        Map<String, List<String>> headers = (Map<String, List<String>>) provider.getRequestContext()
                .get(MessageContext.HTTP_REQUEST_HEADERS);
        if (headers == null) {
            headers = new HashMap<String, List<String>>();
        }

        headers.put(this.headerName, Collections.singletonList(lastmile.generateLastMileToken(sk)));

        provider.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    } else if (authType == AuthType.NTLM) {
        NtlmAuthenticator authenticator = new NtlmAuthenticator(this.administratorUPN,
                this.administratorPassword);
        Authenticator.setDefault(authenticator);

    }

    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());

    return port;
}

From source file:com.evolveum.midpoint.testing.model.client.sample.AbstractTestForExchangeConnector.java

public ModelPortType createModelPort(String[] args) {
    String endpointUrl = DEFAULT_ENDPOINT_URL;

    if (args.length > 0) {
        endpointUrl = args[0];//  w  ww.  ja va2  s .c o m
    }

    System.out.println("Endpoint URL: " + endpointUrl);

    // uncomment this if you want to use Fiddler or any other proxy
    //        ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));

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

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

    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setReceiveTimeout(300000L);
    http.setClient(httpClientPolicy);

    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, ADM_USERNAME);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
    // enable the following to get client-side logging of outgoing requests and incoming responses
    //cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
    //cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());

    return modelPort;
}

From source file:com.evolveum.midpoint.testing.model.client.sample.TestExchangeConnector.java

public ModelPortType createModelPort(String[] args) {
    String endpointUrl = DEFAULT_ENDPOINT_URL;

    if (args.length > 0) {
        endpointUrl = args[0];/*from   w w w. j  av a2  s.co m*/
    }

    System.out.println("Endpoint URL: " + endpointUrl);

    // uncomment this if you want to use Fiddler or any other proxy
    //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));

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

    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, ADM_USERNAME);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
    // enable the following to get client-side logging of outgoing requests and incoming responses
    //cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
    //cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());

    return modelPort;
}

From source file:com.amalto.workbench.utils.Util.java

public static TMDMService getMDMService(URL url, final String username, final String password,
        boolean showMissingJarDialog) throws XtentisException {
    url = checkAndAddSuffix(url);/*from ww w .ja  v  a2  s  .  c om*/

    boolean needCheck = true;
    TMDMService service = (TMDMService) cachedMDMService.get(url, username, password);
    if (service == null) {
        needCheck = false;

        boolean checkResult = MissingJarService.getInstance().checkMissingJar(showMissingJarDialog);
        if (!checkResult) {
            throw new MissingJarsException("Missing dependency libraries."); //$NON-NLS-1$
        }

        try {

            TMDMService_Service service_service = new TMDMService_Service(url);

            service = service_service.getTMDMPort();

            BindingProvider stub = (BindingProvider) service;

            // Do not maintain session via cookies
            stub.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, false);

            Map<String, Object> context = stub.getRequestContext();
            // // dynamic set endpointAddress
            // context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);

            // authentication
            context.put(BindingProvider.USERNAME_PROPERTY, username);
            context.put(BindingProvider.PASSWORD_PROPERTY, password);

            IWebServiceHook wsHook = getWebServiceHook();
            if (wsHook != null) {
                wsHook.preRequestSendingHook(stub, username);
            }

            cachedMDMService.put(url, username, password, service);
        } catch (WebServiceException e) {
            XtentisException ex = convertWebServiceException(e);
            log.error(Messages.bind(Messages.UnableAccessEndpoint, url, e.getMessage()), e);
            if (ex != null) {
                throw ex;
            }
        }

    }

    if (needCheck) {
        try {
            service.ping(new WSPing());
        } catch (WebServiceException e) {
            cachedMDMService.remove(url, username, password);

            XtentisException ex = convertWebServiceException(e);
            log.error(Messages.bind(Messages.UnableAccessEndpoint, url, e.getMessage()), e);
            if (ex != null) {
                throw ex;
            }
        }
    }

    return service;
}

From source file:edu.ku.kuali.kra.award.sapintegration.SapIntegrationServiceImpl.java

/**
 * Configures the service endpoint by configuring basic http authentication
 * on the service as well as setting a custom value for the service endpoint
 * if one has been configured./*ww  w.  j a va2s  .  com*/
 */
protected void configureServiceEndpoint(SIKCRMPROCESSOUTBOUND serviceEndpoint, PrintWriter sendWriter,
        PrintWriter receiveWriter) {

    Client client = ClientProxy.getClient(serviceEndpoint);
    client.getOutInterceptors().add(new LoggingOutInterceptor(sendWriter));
    client.getInInterceptors().add(new LoggingInInterceptor(receiveWriter));

    String connectionTimeout = ConfigContext.getCurrentContextConfig()
            .getProperty(SAP_SERVICE_CONNECTION_TIMEOUT_PARAM);
    String receiveTimeout = ConfigContext.getCurrentContextConfig()
            .getProperty(SAP_SERVICE_RECEIVE_TIMEOUT_PARAM);
    if (!StringUtils.isBlank(connectionTimeout) || !StringUtils.isBlank(receiveTimeout)) {
        Conduit conduit = client.getConduit();
        if (conduit instanceof HTTPConduit) {
            HTTPConduit httpConduit = (HTTPConduit) conduit;
            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
            if (!StringUtils.isBlank(connectionTimeout)) {
                httpClientPolicy.setConnectionTimeout(Long.parseLong(connectionTimeout));
            }
            if (!StringUtils.isBlank(receiveTimeout)) {
                httpClientPolicy.setReceiveTimeout(Long.parseLong(receiveTimeout));
            }
            httpConduit.setClient(httpClientPolicy);
        }
    }

    if (!(serviceEndpoint instanceof BindingProvider)) {
        throw new IllegalArgumentException(
                "The given service endpoint should be an instance of BindingProvider but was not.");
    }
    BindingProvider provider = (BindingProvider) serviceEndpoint;
    Map<String, Object> requestContext = provider.getRequestContext();

    String username = ConfigContext.getCurrentContextConfig().getProperty(SAP_SERVICE_USERNAME_PARAM);
    String password = ConfigContext.getCurrentContextConfig().getProperty(SAP_SERVICE_PASSWORD_PARAM);

    if (StringUtils.isBlank(username)) {
        throw new IllegalStateException(
                "No username was configured for the SAP service, please ensure that the following configuration parameter is set: "
                        + SAP_SERVICE_USERNAME_PARAM);
    }
    if (StringUtils.isBlank(password)) {
        throw new IllegalStateException(
                "No passwrod was configured for the SAP service, please ensure that the following configuration parameter is set: "
                        + SAP_SERVICE_PASSWORD_PARAM);
    }

    requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);

    // next check if a custom endpoint url has been configured
    String endpointUrl = ConfigContext.getCurrentContextConfig().getProperty(SAP_SERVICE_URL_PARAM);
    if (!StringUtils.isBlank(endpointUrl)) {
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    }

}

From source file:org.apache.juddi.adminconsole.hub.UddiAdminHub.java

private String GetToken() {
    EnsureConfig();//from   w  ww  . ja v a2  s  .co m
    if (style != AuthStyle.UDDI_AUTH) {
        BindingProvider bp = null;
        if (WS_Transport) {
            Map<String, Object> context = null;
            bp = (BindingProvider) juddi;
            context = bp.getRequestContext();
            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.USERNAME_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
        }
        return null;
    } else {
        if (token != null) {
            return token;
        }
        GetAuthToken req = new GetAuthToken();
        if (session.getAttribute("username") != null && session.getAttribute("password") != null) {
            req.setUserID((String) session.getAttribute("username"));
            req.setCred(AES.Decrypt((String) session.getAttribute("password"), (String) properties.get("key")));
            try {
                AuthToken authToken = security.getAuthToken(req);
                token = authToken.getAuthInfo();
            } catch (Exception ex) {
                return HandleException(ex);
            }
        }
    }
    return token;
}