Example usage for javax.xml.ws Service create

List of usage examples for javax.xml.ws Service create

Introduction

In this page you can find the example usage for javax.xml.ws Service create.

Prototype

public static Service create(QName serviceName, WebServiceFeature... features) 

Source Link

Document

Creates a Service instance.

Usage

From source file:org.jboss.qa.management.ws.cli.CLIWebServicesEndPointConfigIT.java

protected AnnotatedServiceWithTestEndpointConfigIface createServiceProxy(String serviceURL)
        throws MalformedURLException {
    QName serviceName = new QName(Constants.NAMESPACE, Constants.SERVICE_NAME_ENDPOINT_CONFIG_TEST);
    URL wsdlURL = new URL(serviceURL + "?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    return service.getPort(AnnotatedServiceWithTestEndpointConfigIface.class);
}

From source file:org.jboss.test.integration.mtom.MtomTestCase.java

@Test
public void mtomTest() throws Exception {
    URL url = new URL("http://localhost:8080/war-mtom?wsdl");
    QName qname = new QName("http://mtom.integration.test.jboss.org/", "ImageServerImplService");

    String path = this.getClass().getClassLoader().getResource("").getPath();

    FileInputStream inputStream = new FileInputStream(path + serverLogPath);
    try {//w  ww .ja va  2 s . c  o  m
        String everything = IOUtils.toString(inputStream);
        assertFalse("Testing archive has enabled mtom feature", everything.contains("mtomEnabled=true"));
    } finally {
        inputStream.close();
    }

    Service service = Service.create(url, qname);
    ImageServer imageServer = service.getPort(ImageServer.class);

    //enable MTOM in client
    BindingProvider bp = (BindingProvider) imageServer;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);

    Image im = imageServer.downloadImage(path + "rss.png");

    if (im == null) {
        fail();
    }

}

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.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory.java

/**
 * Returns a client stub for the web-service.
 * <p>/*w ww . j a  v a 2s .  c  o m*/
 * This method reuses the last stub created by the current thread. 
 * @return the client stub.
 */
public synchronized Object getClient() {
    if (threadLocalPort.get() == null) {
        URL wsdlURL = getClass().getClassLoader().getResource(wsTransactionConfiguration.getWsdlLocation());
        Service service = Service.create(wsdlURL, wsTransactionConfiguration.getServiceName());
        Object port = service.getPort(wsTransactionConfiguration.getSei());
        Client client = ClientProxy.getClient(port);
        configureBinding(port);
        configureInterceptors(client);

        threadLocalPort.set(port);
        LOG.debug("Created client adapter for: " + wsTransactionConfiguration.getServiceName());
    }
    return threadLocalPort.get();
}

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

@Override
public boolean test() {
    String repoUrl = repositoryMeta.getRepositoryLocation().getUrl();
    final String url = repoUrl + (repoUrl.endsWith("/") ? "" : "/") + "webservices/unifiedRepository?wsdl";
    Service service;/* ww w  .j a  v  a  2  s. co m*/
    try {
        service = Service.create(new URL(url), new QName("http://www.pentaho.org/ws/1.0", "unifiedRepository"));
        if (service != null) {
            IUnifiedRepositoryJaxwsWebService repoWebService = service
                    .getPort(IUnifiedRepositoryJaxwsWebService.class);
            if (repoWebService != null) {
                return true;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

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  www  .  j a  v  a 2 s.c  o m*/

        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. j ava2 s. co  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  www . ja v a  2s  .  co m*/
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) repoWebService).getBinding();
    binding.setMTOMEnabled(true);

    repo = new UnifiedRepositoryToWebServiceAdapter(repoWebService);

}

From source file:org.viafirma.cliente.ViafirmaClient.java

public FirmaClienteRMI getRemoteObject() {
    try {/* w  w w  .j a  v  a2  s . co m*/
        if (urlRMI.startsWith("rmi")) {
            if (log.isDebugEnabled())
                log.debug("Recuperando el cliente rmi desde: " + urlRMI);
            return (FirmaClienteRMI) java.rmi.Naming.lookup(urlRMI);
        } else if (urlRMI.startsWith("http")) {
            if (log.isDebugEnabled())
                log.debug("Recuperando el cliente WS desde: " + urlRMI);

            // QName qNamePort=new
            // QName("http://viafirma.org/client/","clientPort");
            QName qNameService = new QName("http://viafirma.org/client", "ConectorFirmaRMIService");
            URL wsdl = new URL(urlRMI + "?wsdl");
            Service service = Service.create(wsdl, qNameService);
            FirmaClienteRMI clienteProxy = service.getPort(FirmaClienteRMI.class);
            // probando la conexin web service.
            // utilizamos el conector WebServices.
            // Service serviceModel = new
            // ObjectServiceFactory().create(FirmaClienteRMI.class);
            // serviceModel.setProperty(SoapConstants.MTOM_ENABLED, "true");
            // recuperamos la interfaz webservice.
            // return (FirmaClienteRMI) new
            // XFireProxyFactory().create(serviceModel, urlRMI);
            return clienteProxy;
        } else {
            throw new ExceptionInInitializerError(
                    "Protocolo no soportado para '" + Constantes.PARAM_URL_CONECTOR_FIRMA_RMI + "'= " + urlRMI);
        }
    } catch (MalformedURLException e) {
        throw new ExceptionInInitializerError("La url indicada en '" + Constantes.PARAM_URL_CONECTOR_FIRMA_RMI
                + "'= " + urlRMI + " no es correcta." + e.getMessage());
    } catch (RemoteException e) {
        throw new ExceptionInInitializerError("Error al conectar con '"
                + Constantes.PARAM_URL_CONECTOR_FIRMA_RMI + "'= " + urlRMI + " ," + e.getMessage());
    } catch (NotBoundException e) {
        throw new ExceptionInInitializerError("Error al conectar con '"
                + Constantes.PARAM_URL_CONECTOR_FIRMA_RMI + "'= " + urlRMI + " ," + e.getMessage());
    }
}

From source file:org.webcurator.core.archive.dps.DPSArchive.java

private ProducerWebServices getProducerWebServices() {
    synchronized (this) {
        if (producerWsdlUrl == null) {
            if (this.depositServerBaseUrl != null && producerWsdlRelativePath != null) {
                producerWsdlUrl = this.depositServerBaseUrl + producerWsdlRelativePath;
            }//  w ww. ja  va 2s.co  m
        }
    }
    /*
     * Ideally, we should be using the following call:
     * return WebServiceLocator.getInstance().lookUp(ProducerWebServices.class, producerWsdlUrl);
     * which uses the DPS SDK class com.exlibris.digitool.locator.WebServiceLocator.
     * 
     * However, the WebServiceLocator class from DPS SDK seems to be caching the web service
     * handle and this handle, when not used for several hours, seems to become stale, throwing
     * up exceptions.
     * 
     * So instead of using the DPS SDK's WebServiceLocator class, we are forced to use the 
     * following low-level logic to bind to the Producer web service. The following code 
     * has been created by copying the required code segment from the
     * WebServiceLocator.lookUp() method by ExLibris.
     */
    String serviceEndpointInterfaceName = ProducerWebServices.class.getSimpleName();
    URL wsdlUrl = null;
    String wsdlUrlStr = producerWsdlUrl;
    try {
        wsdlUrl = new URL(wsdlUrlStr);
    } catch (Exception e) {
        log.error("Failed to build WSDL URL from " + wsdlUrlStr + " - Web service lookup of "
                + serviceEndpointInterfaceName + " will fail", e);
        e.printStackTrace();
    }
    QName serviceName = new QName("http://dps.exlibris.com/", serviceEndpointInterfaceName);
    Service service = Service.create(wsdlUrl, serviceName);
    QName portName = new QName("http://dps.exlibris.com/",
            (new StringBuilder()).append(serviceEndpointInterfaceName).append("Port").toString());
    return service.getPort(portName, ProducerWebServices.class);
}