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:Main.java

public static void setSoapEndpointUrl(Object wsProxy, String soapUrl) {
    javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider) wsProxy /*port*/;
    Map<String, Object> context = bp.getRequestContext();
    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapUrl);
}

From source file:Main.java

public static void setBasicHttpAuth(Object wsProxy, String username, String password) {
    javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider) wsProxy /*port*/;
    Map<String, Object> context = bp.getRequestContext();
    context.put(BindingProvider.USERNAME_PROPERTY, username);
    context.put(BindingProvider.PASSWORD_PROPERTY, password);
}

From source file:com.netsteadfast.greenstep.util.WsServiceUtils.java

public static Object getService(String wsClientBeanId, String wsdlAddress) throws Exception {
    if (StringUtils.isBlank(wsClientBeanId)) {
        throw new IllegalArgumentException("error, bean-Id is required!");
    }/*w ww . j  a v a 2 s .  c  om*/
    Object serviceObj = AppContext.getBean(wsClientBeanId);
    if (!StringUtils.isBlank(wsdlAddress)) { // wsdl?, ?xmlwsdl? 
        BindingProvider bindingProvider = (BindingProvider) serviceObj;
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlAddress);
    }
    return serviceObj;
}

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

public static ModelPortType createModelPort(CommandLine cmdLine) {
    String endpointUrl = cmdLine.getOptionValue(OPT_URL, DEFAULT_ENDPOINT_URL);
    String user = cmdLine.getOptionValue(OPT_USER, ADM_USERNAME);
    ClientPasswordHandler.setPassword(cmdLine.getOptionValue(OPT_PASSWORD, ADM_PASSWORD));
    System.out.println("Endpoint URL: " + endpointUrl);

    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<>();

    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, user);
    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);

    return modelPort;
}

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

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

    if (args.length > 0) {
        endpointUrl = args[0];/*w w w . j  a v  a2  s. c om*/
    }

    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:codesample.AuthenticationSample.java

/*****************************************************************************************************************
 *
 * Initialize the BWS and BWSUtil services.
 *
 * @return Returns true when the setup is successful, and false otherwise.
 *
 *****************************************************************************************************************
 *//* ww w .  ja  v  a 2s .  c  om*/
private static boolean setup(String hostname, String bwsPort, String username, String password,
        String authenticatorName, CredentialType credentialType, String domain) {
    final String METHOD_NAME = "setup()";
    logMessage("Entering %s", METHOD_NAME);
    boolean returnValue = false;
    REQUEST_METADATA.setClientVersion(CLIENT_VERSION);
    REQUEST_METADATA.setLocale(LOCALE);
    REQUEST_METADATA.setOrganizationUid(ORG_UID);

    URL bwsServiceUrl = null;
    URL bwsUtilServiceUrl = null;

    try {
        // These are the URLs that point to the web services used for all calls.
        // e.g. with no port:
        // https://server01.example.net/enterprise/admin/ws
        // e.g. with port:
        // https://server01.example.net:38443/enterprise/admin/ws
        String port = "";

        if (bwsPort != null) {
            port = ":" + bwsPort;
        }

        bwsServiceUrl = new URL("https://" + hostname + port + "/enterprise/admin/ws");
        bwsUtilServiceUrl = new URL("https://" + hostname + port + "/enterprise/admin/util/ws");

    } catch (MalformedURLException e) {
        logMessage("Cannot initialize web service URLs");
        logMessage("Exiting %s with value \"%s\"", METHOD_NAME, returnValue);
        return returnValue;
    }

    // Initialize the BWS web service stubs that will be used for all calls.
    logMessage("Initializing BWS web service stub");
    QName serviceBWS = new QName("http://ws.rim.com/enterprise/admin", "BWSService");
    QName portBWS = new QName("http://ws.rim.com/enterprise/admin", "BWS");
    _bwsService = new BWSService(null, serviceBWS);
    _bwsService.addPort(portBWS, "http://schemas.xmlsoap.org/soap/", bwsServiceUrl.toString());
    _bws = _bwsService.getPort(portBWS, BWS.class);
    logMessage("BWS web service stub initialized");

    logMessage("Initializing BWSUtil web service stub");
    QName serviceUtil = new QName("http://ws.rim.com/enterprise/admin", "BWSUtilService");
    QName portUtil = new QName("http://ws.rim.com/enterprise/admin", "BWSUtil");
    _bwsUtilService = new BWSUtilService(null, serviceUtil);
    _bwsUtilService.addPort(portUtil, "http://schemas.xmlsoap.org/soap/", bwsUtilServiceUrl.toString());
    _bwsUtil = _bwsUtilService.getPort(portUtil, BWSUtil.class);
    logMessage("BWSUtil web service stub initialized");
    // Set the connection timeout to 60 seconds.
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(60000);

    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(60000);

    Client client = ClientProxy.getClient(_bws);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setClient(httpClientPolicy);

    client = ClientProxy.getClient(_bwsUtil);
    http = (HTTPConduit) client.getConduit();
    http.setClient(httpClientPolicy);

    Authenticator authenticator = getAuthenticator(authenticatorName);
    if (authenticator != null) {
        String encodedUsername = getEncodedUserName(username, authenticator, credentialType, domain);
        if (encodedUsername != null && !encodedUsername.isEmpty()) {
            /*
             * Set the HTTP basic authentication on the BWS service. BWSUtilService is a utility web service that
             * does not require authentication.
             */
            BindingProvider bp = (BindingProvider) _bws;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, encodedUsername);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

            returnValue = true;
        } else {
            logMessage("\"encodedUsername\" is null or empty");
        }
    } else {
        logMessage("\"authenticator\" is null");
    }

    logMessage("Exiting %s with value \"%s\"", METHOD_NAME, returnValue);
    return returnValue;
}

From source file:com.evolveum.midpoint.testing.wstest.AbstractWebserviceTest.java

/**
 * Creates webservice client connecting to midpoint
 * *///from   www  .  j a va 2s . com
protected static ModelPortType createModelPort(String username, String password, String passwordType) {

    String endpoint = ENDPOINT;
    if (System.getProperty("midpoint.endpoint") != null) {
        endpoint = System.getProperty("midpoint.endpoint");
    }
    LOGGER.info("Creating model client endpoint: {} , username={}, password={}",
            new Object[] { endpoint, username, password });

    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>();
    if (username != null) {
        outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        outProps.put(WSHandlerConstants.USER, username);
        outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordType);
        ClientPasswordHandler.setPassword(password);
        outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());

        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        cxfEndpoint.getOutInterceptors().add(wssOut);
    }

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

    return modelPort;
}

From source file:Java_BWS_Sample.SampleBwsClient.java

/*******************************************************************************************************************
 *
 * Initialize the BWS and BWSUtil services.
 *
 * @return Returns true when the setup is successful, and false otherwise.
 *
 *******************************************************************************************************************
 *//*from w  w  w  .  j  a va  2s.co  m*/
private static boolean setup() {
    final String METHOD_NAME = "setup()";
    logMessage("Entering %s", METHOD_NAME);
    boolean returnValue = false;
    REQUEST_METADATA.setClientVersion(CLIENT_VERSION);
    REQUEST_METADATA.setLocale(LOCALE);
    REQUEST_METADATA.setOrganizationUid(ORG_UID);

    URL bwsServiceUrl = null;
    URL bwsUtilServiceUrl = null;

    try {
        // These are the URLs that point to the web services used for all calls.
        bwsServiceUrl = new URL("https://" + BWS_HOST_NAME + "/enterprise/admin/ws");
        bwsUtilServiceUrl = new URL("https://" + BWS_HOST_NAME + "/enterprise/admin/util/ws");
    } catch (MalformedURLException e) {

        logMessage("Cannot initialize web service URLs");
        logMessage("Exiting %s with value \"%s\"", METHOD_NAME, returnValue);
        return returnValue;
    }

    // Initialize the BWS web service stubs that will be used for all calls.
    logMessage("Initializing BWS web service stub");
    QName serviceBWS = new QName("http://ws.rim.com/enterprise/admin", "BWSService");
    QName portBWS = new QName("http://ws.rim.com/enterprise/admin", "BWS");
    _bwsService = new BWSService(null, serviceBWS);
    _bwsService.addPort(portBWS, "http://schemas.xmlsoap.org/soap/", bwsServiceUrl.toString());
    _bws = _bwsService.getPort(portBWS, BWS.class);
    logMessage("BWS web service stub initialized");

    logMessage("Initializing BWSUtil web service stub");
    QName serviceUtil = new QName("http://ws.rim.com/enterprise/admin", "BWSUtilService");
    QName portUtil = new QName("http://ws.rim.com/enterprise/admin", "BWSUtil");
    _bwsUtilService = new BWSUtilService(null, serviceUtil);
    _bwsUtilService.addPort(portUtil, "http://schemas.xmlsoap.org/soap/", bwsUtilServiceUrl.toString());
    _bwsUtil = _bwsUtilService.getPort(portUtil, BWSUtil.class);
    logMessage("BWSUtil web service stub initialized");
    // Set the connection timeout to 60 seconds.
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(60000);

    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(60000);

    Client client = ClientProxy.getClient(_bws);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setClient(httpClientPolicy);

    client = ClientProxy.getClient(_bwsUtil);
    http = (HTTPConduit) client.getConduit();
    http.setClient(httpClientPolicy);

    Authenticator authenticator = getAuthenticator(AUTHENTICATOR_NAME);
    if (authenticator != null) {
        String encodedUsername = getEncodedUserName(USERNAME, authenticator);
        if (encodedUsername != null && !encodedUsername.isEmpty()) {
            /*
             * Set the HTTP basic authentication on the BWS service.
             * BWSUtilService is a utility web service that does not require
             * authentication.
             */
            BindingProvider bp = (BindingProvider) _bws;
            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, encodedUsername);
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);

            returnValue = true;
        } else {
            logMessage("'encodedUsername' is null or empty");
        }
    } else {
        logMessage("'authenticator' is null");
    }

    logMessage("Exiting %s with value \"%s\"", METHOD_NAME, returnValue);
    return returnValue;
}

From source file:com.evolveum.liferay.usercreatehook.ws.ModelPortWrapper.java

private static ModelPortType createModelPort() {

    String endpointUrl = WSConfig.getEndPointUrl();
    String username = WSConfig.getUser();

    LOG.info("Endpoint URL: " + endpointUrl);

    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;

    // make request context thread safe
    ((BindingProvider) modelPort).getRequestContext().put("thread.local.request.context", "true");

    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, 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);

    return modelPort;
}

From source file:de.extra.extraClientLight.util.SendWebService.java

/**
 * /*from   w  ww  . ja  va2 s  . c o  m*/
 * @param extraRequest
 * @param url
 * @param mtomActive
 * @return
 */
public TransportResponseType sendRequest(TransportRequestType extraRequest, String url, boolean mtomActive) {
    TransportResponseType response = new TransportResponseType();

    Extra_Service extraService = new Extra_Service(null, SERVICE_NAME);

    Extra extraPort = extraService.getPort(Extra.class);
    BindingProvider bp = (BindingProvider) extraPort;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

    SOAPBinding soapBinding = (SOAPBinding) bp.getBinding();
    soapBinding.setMTOMEnabled(mtomActive);

    try {
        LOGGER.debug("Versand gestartet...");
        response = extraPort.execute(extraRequest);
        LOGGER.debug("...Empfang Response");

        if (mtomActive) {
            Collection<Attachment> attachmentList = (Collection<Attachment>) bp.getResponseContext()
                    .get(Message.ATTACHMENTS);

            LOGGER.debug("Attachments: " + attachmentList.size());

        }
    } catch (SOAPFaultException e) {
        SOAPFault soapFault = e.getFault();

        LOGGER.error(soapFault.getTextContent(), e);

    } catch (ExtraFault e) {
        ExtraErrorHelper.printExtraError(e);
    }

    return response;

}