Example usage for javax.xml.ws BindingProvider SESSION_MAINTAIN_PROPERTY

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

Introduction

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

Prototype

String SESSION_MAINTAIN_PROPERTY

To view the source code for javax.xml.ws BindingProvider SESSION_MAINTAIN_PROPERTY.

Click Source Link

Document

Standard property: This boolean property is used by a service client to indicate whether or not it wants to participate in a session with a service endpoint.

Usage

From source file:org.bimserver.client.soap.SoapChannel.java

public void connect(TokenHolder tokenHolder) {
    for (Class<? extends PublicInterface> interface1 : interfaces) {
        JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
        cpfb.setServiceClass(interface1);
        cpfb.setAddress(address + "/" + interface1.getSimpleName());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("mtom-enabled", Boolean.TRUE);
        cpfb.setProperties(properties);//from   ww w .j  a v a2s .  c om

        PublicInterface serviceInterface = (PublicInterface) cpfb.create();

        client = ClientProxy.getClient(serviceInterface);
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.getClient().setConnectionTimeout(360000);
        http.getClient().setAllowChunking(false);
        http.getClient().setReceiveTimeout(320000);

        if (!useSoapHeaderSessions) {
            ((BindingProvider) serviceInterface).getRequestContext()
                    .put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
        }
        add(interface1.getName(), serviceInterface);
    }
    tokenHolder.registerTokenChangeListener(this);
    notifyOfConnect();
}

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   w  w w.  ja  va 2 s . c o  m*/

    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:org.apache.axis2.jaxws.core.MessageContext.java

/**
 * Used to determine whether or not session state has been enabled.
 *
 * @return/*from   w  ww .  ja v  a  2 s.  com*/
 */
public boolean isMaintainSession() {
    boolean maintainSession = false;

    Boolean value = (Boolean) getProperty(BindingProvider.SESSION_MAINTAIN_PROPERTY);
    if (value != null && value.booleanValue()) {
        maintainSession = true;
    }

    return maintainSession;
}

From source file:org.mule.module.netsuite.api.DefaultCxfPortProvider.java

public NetSuitePortType getAuthenticatedPort() throws Exception {
    NetSuitePortType port = getPort();//from  w w w . j a  v a  2 s  .c  o  m
    ((BindingProvider) port).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    port.login(new LoginRequest(new Passport(email, password, account, new RecordRef(null, roleId, null))));
    return port;
}

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

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

    try {/* ww w .  j a  va 2s  .  c om*/
        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.nuxeo.adullact.service.AdullactServiceImpl.java

private InterfaceParapheur serviceSOAPFactory() throws ClientException {
    // in wsdl definitions target name space
    QName qname = new QName("http://www.adullact.org/spring-ws/iparapheur/1.0", "InterfaceParapheurService");
    URL wsdlUrl = AdullactServiceImpl.class.getResource("/wsdl/iparapheur.xml.wsdl");
    Service service = Service.create(wsdlUrl, qname);

    InterfaceParapheurService ifParapheurService = new InterfaceParapheurService(wsdlUrl, qname);

    InterfaceParapheur ifParapheur = ifParapheurService.getInterfaceParapheurSoap11();

    Map<String, Object> requestContext = ((BindingProvider) ifParapheur).getRequestContext();

    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, webServiceBaseURL.toString());
    requestContext.put(BindingProvider.USERNAME_PROPERTY, login);
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
    return ifParapheur;
}

From source file:org.pentaho.di.repository.pur.WebServiceManager.java

@Override
@SuppressWarnings("unchecked")
public <T> T createService(final String username, final String password, final Class<T> clazz)
        throws MalformedURLException {
    final Future<Object> resultFuture;
    synchronized (serviceCache) {
        // if this is true, a coder did not make sure that clearServices was called on disconnect
        if (lastUsername != null && !lastUsername.equals(username)) {
            throw new IllegalStateException();
        }/*from w ww .  j a  v a 2s . c om*/

        final WebServiceSpecification webServiceSpecification = serviceNameMap.get(clazz);
        final String serviceName = webServiceSpecification.getServiceName();
        if (serviceName == null) {
            throw new IllegalStateException();
        }

        if (webServiceSpecification.getServiceType().equals(ServiceType.JAX_WS)) {
            // build the url handling whether or not baseUrl ends with a slash
            // String baseUrl = repositoryMeta.getRepositoryLocation().getUrl();
            final URL url = new URL(
                    baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "webservices/" + serviceName + "?wsdl"); //$NON-NLS-1$ //$NON-NLS-2$

            String key = url.toString() + '_' + serviceName + '_' + clazz.getName();
            if (!serviceCache.containsKey(key)) {
                resultFuture = executor.submit(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Service service = Service.create(url, new QName(NAMESPACE_URI, serviceName));
                        T port = service.getPort(clazz);
                        // add TRUST_USER if necessary
                        if (StringUtils
                                .isNotBlank(System.getProperty("pentaho.repository.client.attemptTrust"))) {
                            ((BindingProvider) port).getRequestContext().put(
                                    MessageContext.HTTP_REQUEST_HEADERS,
                                    Collections.singletonMap(TRUST_USER, Collections.singletonList(username)));
                        } else {
                            // http basic authentication
                            ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
                                    username);
                            ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
                                    password);
                        }
                        // accept cookies to maintain session on server
                        ((BindingProvider) port).getRequestContext()
                                .put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
                        // support streaming binary data
                        // TODO mlowery this is not portable between JAX-WS implementations (uses com.sun)
                        ((BindingProvider) port).getRequestContext()
                                .put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
                        SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
                        binding.setMTOMEnabled(true);
                        return port;
                    }
                });
                serviceCache.put(key, resultFuture);
            } else {
                resultFuture = serviceCache.get(key);
            }
        } else {
            if (webServiceSpecification.getServiceType().equals(ServiceType.JAX_RS)) {

                String key = baseUrl.toString() + '_' + serviceName + '_' + clazz.getName();
                if (!serviceCache.containsKey(key)) {

                    resultFuture = executor.submit(new Callable<Object>() {

                        @Override
                        public Object call() throws Exception {
                            ClientConfig clientConfig = new DefaultClientConfig();
                            Client client = Client.create(clientConfig);
                            client.addFilter(new HTTPBasicAuthFilter(username, password));

                            Class<?>[] parameterTypes = new Class<?>[] { Client.class, URI.class };
                            String factoryClassName = webServiceSpecification.getServiceClass().getName();
                            factoryClassName = factoryClassName.substring(0, factoryClassName.lastIndexOf("$"));
                            Class<?> factoryClass = Class.forName(factoryClassName);
                            Method method = factoryClass.getDeclaredMethod(
                                    webServiceSpecification.getServiceName(), parameterTypes);
                            T port = (T) method.invoke(null,
                                    new Object[] { client, new URI(baseUrl + "/plugin") });

                            return port;
                        }
                    });
                    serviceCache.put(key, resultFuture);
                } else {
                    resultFuture = serviceCache.get(key);
                }
            } else {
                resultFuture = null;
            }
        }

        try {
            if (clazz.isInterface()) {
                return UnifiedRepositoryInvocationHandler.forObject((T) resultFuture.get(), clazz);
            } else {
                return (T) resultFuture.get();
            }

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause != null) {
                if (cause instanceof RuntimeException) {
                    throw (RuntimeException) cause;
                } else if (cause instanceof MalformedURLException) {
                    throw (MalformedURLException) cause;
                }
            }
            throw new RuntimeException(e);
        }
    }
}

From source file:org.pentaho.platform.plugin.services.importexport.CommandLineProcessor.java

/**
 * Why does this return a web service? Going directly to the IUnifiedRepository requires the following:
 * <p/>//from  w w w .  jav a  2s .  c o m
 * <ul>
 * <li>PentahoSessionHolder setup including password and tenant ID. (The server doesn't even process passwords today--
 * it assumes that Spring Security processed it. This would require code changes.)</li>
 * <li>User must specify path to Jackrabbit files (i.e. system/jackrabbit).</li>
 * </ul>
 */
protected synchronized IUnifiedRepository getRepository() throws ParseException {
    if (repository != null) {
        return repository;
    }

    final String NAMESPACE_URI = "http://www.pentaho.org/ws/1.0"; //$NON-NLS-1$
    final String SERVICE_NAME = "unifiedRepository"; //$NON-NLS-1$

    String urlString = getOptionValue(
            Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_URL_KEY"),
            Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_URL_NAME"), true, false).trim();
    if (urlString.endsWith("/")) {
        urlString = urlString.substring(0, urlString.length() - 1);
    }
    urlString = urlString + "/webservices/" + SERVICE_NAME + "?wsdl";

    URL url;
    try {
        url = new URL(urlString);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }

    Service service = Service.create(url, new QName(NAMESPACE_URI, SERVICE_NAME));
    IUnifiedRepositoryJaxwsWebService port = service.getPort(IUnifiedRepositoryJaxwsWebService.class);
    // http basic authentication
    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
            getOptionValue(Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_USERNAME_KEY"),
                    Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_USERNAME_NAME"), true,
                    false));
    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
            getOptionValue(Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_PASSWORD_KEY"),
                    Messages.getInstance().getString("CommandLineProcessor.INFO_OPTION_PASSWORD_NAME"), true,
                    true));
    // accept cookies to maintain session on server
    ((BindingProvider) port).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    // support streaming binary data
    // TODO mlowery this is not portable between JAX-WS implementations
    // (uses com.sun)
    ((BindingProvider) port).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    final UnifiedRepositoryToWebServiceAdapter unifiedRepositoryToWebServiceAdapter = new UnifiedRepositoryToWebServiceAdapter(
            port);
    repository = unifiedRepositoryToWebServiceAdapter;
    return unifiedRepositoryToWebServiceAdapter;
}

From source file:org.pentaho.platform.repository2.unified.webservices.jaxws.DefaultUnifiedRepositoryJaxwsWebServiceIT.java

@Before
public void setUp() throws Exception {
    super.setUp();

    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);

    SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);

    String address = "http://localhost:9000/repo";
    Endpoint.publish(address, new DefaultUnifiedRepositoryJaxwsWebService(repo));

    Service service = Service.create(new URL("http://localhost:9000/repo?wsdl"),
            new QName("http://www.pentaho.org/ws/1.0", "unifiedRepository"));

    IUnifiedRepositoryJaxwsWebService repoWebService = service.getPort(IUnifiedRepositoryJaxwsWebService.class);

    // accept cookies to maintain session on server
    ((BindingProvider) repoWebService).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    // support streaming binary data
    ((BindingProvider) repoWebService).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,
            8192);//from   w  w w .  j ava2 s. c  om
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) repoWebService).getBinding();
    binding.setMTOMEnabled(true);

    repo = new UnifiedRepositoryToWebServiceAdapter(repoWebService);

}

From source file:org.talend.components.netsuite.v2014_2.client.NetSuiteClientServiceImpl.java

protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {//from   www  .  j  a v a  2 s  .  co m
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2014.2/netsuite.wsdl");

        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);

        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service
                .getNetSuitePort(features.toArray(new WebServiceFeature[features.size()]));

        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);

        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                    NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain",
                            defaultEndpointUrl));
        }

        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());

        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

        return port;
    } catch (WebServiceException | MalformedURLException | UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR),
                NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()),
                e);
    }
}