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.juddi.adminconsole.hub.UddiAdminHub.java

public String verifyLogin() {
    EnsureConfig();//from   ww  w. j  av a  2s .  c om
    if (style != AuthStyle.UDDI_AUTH) {
        if (WS_Transport) {
            BindingProvider bp = null;
            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"))));
        }
        FindBusiness fb = new FindBusiness();
        fb.setListHead(0);
        fb.setMaxRows(1);
        fb.setFindQualifiers(new FindQualifiers());
        fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
        fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
        try {
            GetPublisherDetail publisherDetail = new GetPublisherDetail();
            publisherDetail.getPublisherId().add((String) session.getAttribute("username"));
            juddi.getPublisherDetail(publisherDetail);

        } catch (Exception ex) {
            return HandleException(ex);
        }
        /*
         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;
        }
        if (WS_Transport) {
            BindingProvider bp = null;
            Map<String, Object> context = null;

            bp = (BindingProvider) juddi;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);
        }
        GetAuthToken req = new GetAuthToken();
        try {
            if (security == null) {
                security = transport.getUDDISecurityService();
            }
        } catch (Exception ex) {
            return HandleException(ex);
        }
        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")));
            log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is "
                    + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
            try {
                AuthToken authToken = security.getAuthToken(req);
                token = authToken.getAuthInfo();
                return null;
            } catch (Exception ex) {
                return HandleException(ex);
            }
        }
    }
    return "Unexpected error";
}

From source file:org.apache.juddi.webconsole.hub.UddiHub.java

public String verifyLogin() {
    EnsureConfig();/*from  ww w . j a  v  a2 s  .  c o m*/
    token = null;
    if (style != AuthStyle.UDDI_AUTH) {
        if (WS_Transport) {
            BindingProvider bp = null;
            Map<String, Object> context = null;
            bp = (BindingProvider) inquiry;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) publish;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) custody;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) subscription;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
        }
        FindBusiness fb = new FindBusiness();
        fb.setListHead(0);
        fb.setMaxRows(1);
        fb.setFindQualifiers(new FindQualifiers());
        fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
        fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
        try {
            inquiry.findBusiness(fb);
        } catch (Exception ex) {
            return HandleException(ex);
        }
        /*
         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 (WS_Transport) {
            BindingProvider bp = null;
            Map<String, Object> context = null;

            bp = (BindingProvider) inquiry;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) publish;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) custody;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) subscription;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);
        }
        GetAuthToken req = new GetAuthToken();
        try {
            if (security == null) {
                security = transport.getUDDISecurityService();
            }
        } catch (Exception ex) {
            return HandleException(ex);
        }
        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")));
            log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is "
                    + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
            try {
                AuthToken authToken = security.getAuthToken(req);
                token = authToken.getAuthInfo();
                return null;
            } catch (Exception ex) {
                return HandleException(ex);
            }
        }
    }
    return "Unexpected error";
}

From source file:org.apache.juddi.webconsole.hub.UddiHub.java

private String GetToken() {
    EnsureConfig();/*from ww w. j  a v  a 2s. com*/
    if (style != AuthStyle.UDDI_AUTH) {
        if (WS_Transport) {
            BindingProvider bp = null;
            Map<String, Object> context = null;
            bp = (BindingProvider) inquiry;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) publish;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) custody;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));

            bp = (BindingProvider) subscription;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
            context.put(BindingProvider.PASSWORD_PROPERTY,
                    session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
        }
        /*
         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;
        }
        if (WS_Transport) {
            BindingProvider bp = null;
            Map<String, Object> context = null;

            bp = (BindingProvider) inquiry;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) publish;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) custody;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);

            bp = (BindingProvider) subscription;
            context = bp.getRequestContext();
            context.remove(BindingProvider.USERNAME_PROPERTY);
            context.remove(BindingProvider.PASSWORD_PROPERTY);
        }
        GetAuthToken req = new GetAuthToken();
        try {
            if (security == null) {
                security = transport.getUDDISecurityService();
            }
        } catch (Exception ex) {
            log.error(ex);
        }
        if (session != null && 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")));
            log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is "
                    + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
            try {
                AuthToken authToken = security.getAuthToken(req);
                token = authToken.getAuthInfo();
            } catch (Exception ex) {
                return HandleException(ex);
            }
        }
    }
    return token;
}

From source file:org.apache.metamodel.sugarcrm.SugarCrmDataContext.java

/**
 * /*from  w w w  .  j  av  a2s.  c om*/
 * @param sugarCrmBaseUrl
 *            the base URL of the SugarCRM system, e.g.
 *            http://127.0.0.1:9090/sugarcrm
 * @param username
 * @param password
 * @param applicationName
 */
public SugarCrmDataContext(String sugarCrmBaseUrl, final String username, String password,
        final String applicationName) {
    if (sugarCrmBaseUrl.endsWith("/")) {
        // remove trailing slashes
        sugarCrmBaseUrl = sugarCrmBaseUrl.substring(0, sugarCrmBaseUrl.length() - 1);
    }

    final String endpointAddress = sugarCrmBaseUrl + "/service/v4/soap.php";
    final String wsdlAddress = endpointAddress + "?wsdl";

    logger.info("Connecting to SugarCRM SOAP service using WSDL URL: {}", wsdlAddress);

    final URL wsdlUrl;
    try {
        wsdlUrl = new URL(wsdlAddress);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid SugarCRM base URL: " + e.getMessage(), e);
    }

    final Sugarsoap soap = new Sugarsoap(wsdlUrl, new QName("http://www.sugarcrm.com/sugarcrm", "sugarsoap"));
    _service = soap.getSugarsoapPort();

    assert _service instanceof BindingProvider;
    final BindingProvider bindingProvider = (BindingProvider) _service;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);

    final String md5password = DigestUtils.md5Hex(password);
    _sessionId = new LazyRef<String>() {
        @Override
        protected String fetch() {
            UserAuth userAuth = new UserAuth();
            userAuth.setUserName(username);
            userAuth.setPassword(md5password);
            logger.debug("Logging in as '{}', with application name '{}'", username, applicationName);
            EntryValue response = _service.login(userAuth, applicationName, new NameValueList());
            String sessionId = response.getId();
            logger.info("Started session with SugarCRM. Session ID: {}", sessionId);
            return sessionId;
        }
    };
}

From source file:org.jboss.as.test.integration.ws.authentication.policy.AuthenticationPolicyContextTestCase.java

/**
 * Test gets SAML assertion by token using the web service in deployment picketlink-sts.war.
 * Afterwards web service EchoService from the deployment picketlink-sts-ws.war is called using role testRole and
 * security domain sp created during test initialization.
 *
 * @throws Exception/*from w  ww  .  j  av a  2  s . c o  m*/
 */
@Test
@RunAsClient
public void test() throws Exception {
    Element assertion = null;
    try {
        LOGGER.debug("Invoking token service to get SAML assertion for " + USERNAME);
        assertion = wsClient.issueToken(SAMLUtil.SAML2_TOKEN_TYPE);
        String domElementAsString = DocumentUtil.getDOMElementAsString(assertion);
        LOGGER.debug("assertion: " + domElementAsString);
        LOGGER.debug("SAML assertion for " + USERNAME + " successfully obtained!");
    } catch (WSTrustException wse) {
        LOGGER.error("Unable to issue assertion: " + wse.getMessage());
        wse.printStackTrace();
        System.exit(1);
    }

    try {
        URL wsdl = new URL("http://" + TestSuiteEnvironment.getServerAddress() + ":"
                + TestSuiteEnvironment.getHttpPort() + "/picketlink-sts-ws/EchoService?wsdl");
        QName serviceName = new QName("http://ws.picketlink.sts.jboss.org/", "EchoServiceService");
        Service service = Service.create(wsdl, serviceName);
        EchoServiceRemote port = service.getPort(
                new QName("http://ws.picketlink.sts.jboss.org/", "EchoServicePort"), EchoServiceRemote.class);

        BindingProvider bp = (BindingProvider) port;
        ClientConfigUtil.setConfigHandlers(bp, "standard-jaxws-client-config.xml", "SAML WSSecurity Client");
        bp.getRequestContext().put(SAML2Constants.SAML2_ASSERTION_PROPERTY, assertion);

        port.echo("Test");
    } finally {
        if (wsClient != null) {
            wsClient.close();
        }
    }
}

From source file:org.josso.gateway.jaxws.JAXWSWebserviceGatewayServiceLocator.java

private void setEndpointAddress(Object port, String newAddress) {

    assert port instanceof BindingProvider : "Doesn't appear to be a valid port";
    assert newAddress != null : "Doesn't appear to be a valid address";

    BindingProvider bp = (BindingProvider) port;

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

    Object oldAddress = context.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);

    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, newAddress);

}

From source file:org.miloss.fgsms.presentation.Helper.java

public static String ShowOpStat(SecurityWrapper c,
            org.miloss.fgsms.services.interfaces.status.OpStatusService ss, String url) {
        StringBuilder out = new StringBuilder();
        String[] urls = url.split("|");
        for (int i = 0; i < urls.length; i++) {
            try {

                BindingProvider bp = (BindingProvider) ss;
                bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urls[i]);

                GetOperatingStatusRequestMessage req = new GetOperatingStatusRequestMessage();
                req.setClassification(c);
                GetOperatingStatusResponseMessage res = ss.getOperatingStatus(req);
                if (res.isStatus()) {
                    out.append("<h2>OK</h2>");

                } else {
                    out.append("<h2>BAD</h2>");
                }//ww  w. j a  v a2  s.  c o  m
                out.append("Started at: ").append(res.getStartedAt().toString()).append("<br>");
                out.append("Status Message:").append(Utility.encodeHTML(res.getStatusMessage())).append("<br>");
                out.append("Version Data: ").append(Utility.encodeHTML(res.getVersionInfo().getVersionData()))
                        .append("<br>");
                out.append("Version Source: ").append(Utility.encodeHTML(res.getVersionInfo().getVersionSource()))
                        .append("<br>");
                out.append("Data Sent Failure: ").append(res.getDataNotSentSuccessfully()).append("<br>");
                out.append("Data Sent Success: ").append(res.getDataSentSuccessfully()).append("<br>");
            } catch (Exception ex) {
                out.append("Error caught checking stats on ").append(urls[i]).append(" ").append(ex.getMessage());
            }
        }
        return out.toString();
    }

From source file:org.mule.modules.taleo.client.TaleoCxfClientImpl.java

@Override
public void connect(String username, String password, String companyCode) throws ConnectionException {

    try {//from   ww w  . ja v  a  2  s  .com
        endpoint = this.getUrl(companyCode);
    } catch (TaleoException e) {
        throw new ConnectionException(null, e.getLocalizedMessage(), e.getMessage(), e);
    }
    rpc = serviceClient.getPort(IWebAPI.class);

    BindingProvider bindingProvider = ((BindingProvider) this.rpc);
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

    Client cxfClient = ClientProxy.getClient(rpc);
    cxfClient.getInInterceptors().add(new CustomMessageReaderInterceptor());
    String loginResult;
    try {
        loginResult = this.rpc.login(companyCode, username, password);
    } catch (WebServicesException_Exception e) {
        throw new ConnectionException(null, e.getLocalizedMessage(), e.getMessage(), e);
    }

    sessionId = loginResult;

    bindingProvider.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, sessionId);

    sessionId = loginResult;

}

From source file:org.mule.modules.zuora.zuora.api.CxfZuoraClient.java

public CxfZuoraClient(@NotNull String username, @NotNull String password, @NotNull String endpoint)
        throws UnexpectedErrorFault, LoginFault {
    Validate.notNull(username);//from w ww .j a v  a  2 s  .c o  m
    Validate.notNull(password);
    Validate.notNull(endpoint);
    this.username = username;
    this.password = password;
    this.endpoint = endpoint;

    // @EL if multiple clients are created at the same time this JAXB code can
    // generate race condiitons on the ClassLoader when it searches for the
    // ObjectFactory:
    //
    // 1. Could not create a validated object, cause: loader (instance of
    // org/mule/module/launcher/MuleApplicationClassLoader): attempted  duplicate class
    // definition for name: "com/zuora/api/object/ObjectFactory" (java.util.NoSuchElementException)
    //
    // So I'm locking it so it can happen only one at a time
    synchronized (CxfZuoraClient.class) {
        try {
            jSessionDataBinding = new JAXBDataBinding(SessionHeader.class);
        } catch (JAXBException e) {
            throw new AssertionError(e);
        }
    }

    ZuoraService serviceLocator = new ZuoraService(getClass().getResource("/zuora-32.wsdl"));
    this.soap = serviceLocator.getPort(Soap.class);

    BindingProvider bindingProvider = ((BindingProvider) this.soap);
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

    LoginResult loginResult;
    loginResult = this.soap.login(username, password);

    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            loginResult.getServerUrl());
    bindingProvider.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
            new HashMap<String, List<String>>());

    sessionId = loginResult.getSession();

    SessionHeader sh = new SessionHeader();
    sh.setSession(loginResult.getSession());

    bindingProvider.getRequestContext().put(Header.HEADER_LIST, Arrays.asList(
            new Header(new QName("urn:partner.soap.sforce.com", "SessionHeader"), sh, jSessionDataBinding)));

}

From source file:org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory.java

/**
 * Configures SOAP binding of the given SOAP port.
 *///from  ww w .j a  v  a  2s  . c o  m
private void configureBinding(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;

    Map<String, Object> reqContext = bindingProvider.getRequestContext();
    reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);

    Binding binding = bindingProvider.getBinding();
    SOAPBinding soapBinding = (SOAPBinding) binding;
    soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom());
}