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.apache.cxf.systest.coloc.AbstractColocTest.java

/**
 * Create client and return the port/*ww  w .ja  va 2 s  . c  om*/
 * @return port for a interface represented by cls.
 */
protected <T> T getPort(QName serviceName, QName portName, String wsdlLocation, Class<T> cls) {
    Service srv = Service.create(AbstractColocTest.class.getResource(wsdlLocation), serviceName);
    T t = srv.getPort(portName, cls);
    ((BindingProvider) t).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getTransportURI());
    return t;
}

From source file:org.apache.cxf.systest.kerberos.wssec.kerberos.KerberosTokenTest.java

private void runKerberosTest(String portName, boolean streaming, String portNumber) throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = KerberosTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = KerberosTokenTest.class.getResource("DoubleItKerberos.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, portName);
    DoubleItPortType kerberosPort = service.getPort(portQName, DoubleItPortType.class);

    TestUtil.updateAddressPort(kerberosPort, portNumber);

    if (streaming) {
        SecurityTestUtil.enableStreaming(kerberosPort);
    }/*from  w w w.j  a v a 2s  .c  o  m*/

    Assert.assertEquals(50, kerberosPort.doubleIt(25));

    ((java.io.Closeable) kerberosPort).close();
    bus.shutdown(true);
}

From source file:org.apache.cxf.systest.kerberos.wssec.kerberos.KerberosTokenTest.java

private void runKerberosSTSTest(String portName, boolean streaming, String portNumber, String stsPortNumber)
        throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = KerberosTokenTest.class.getResource("sts-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = KerberosTokenTest.class.getResource("DoubleItKerberos.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, portName);
    DoubleItPortType kerberosPort = service.getPort(portQName, DoubleItPortType.class);

    TestUtil.updateAddressPort(kerberosPort, portNumber);

    SecurityTestUtil.updateSTSPort((BindingProvider) kerberosPort, stsPortNumber);

    if (streaming) {
        SecurityTestUtil.enableStreaming(kerberosPort);
    }//from   w w  w  . j  a v  a 2 s .c  o  m

    Assert.assertEquals(50, kerberosPort.doubleIt(25));

    ((java.io.Closeable) kerberosPort).close();
    bus.shutdown(true);
}

From source file:org.apache.cxf.systest.kerberos.wssec.spnego.SpnegoTokenTest.java

private void runKerberosTest(String portName, boolean streaming, String portNumber) throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SpnegoTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

    URL wsdl = SpnegoTokenTest.class.getResource("DoubleItSpnego.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, portName);
    DoubleItPortType kerberosPort = service.getPort(portQName, DoubleItPortType.class);

    TestUtil.updateAddressPort(kerberosPort, portNumber);

    if (streaming) {
        SecurityTestUtil.enableStreaming(kerberosPort);
    }/*from ww w  .j  a  v  a 2 s  .co m*/

    Assert.assertEquals(50, kerberosPort.doubleIt(25));

    ((java.io.Closeable) kerberosPort).close();
    bus.shutdown(true);
}

From source file:org.apache.hise.engine.jaxws.HISEJaxWSClient.java

@PostConstruct
public void init() throws Exception {
    evaluator.declareNamespace("wsa", "http://www.w3.org/2005/08/addressing");
    messageFactory = MessageFactory.newInstance();
    destinationService = Service.create(wsdlDocumentLocation, serviceName);
    destinationPort = null;//from  w  ww.j  a  v a 2  s  .c  o  m
    {
        Iterator<QName> it = destinationService.getPorts();
        while (it.hasNext()) {
            QName p = it.next();
            System.out.println(p);
            destinationPort = p;
        }
    }
    Validate.notNull(destinationPort,
            "Can't find port for service " + serviceName + " in " + wsdlDocumentLocation);
}

From source file:org.codice.ddf.security.claims.attributequery.common.AttributeQueryClaimsHandler.java

/**
 * Creates a dynamic service from the provided wsdl location.
 *//*w  w w  .  jav a  2 s. com*/
protected Service createService() {
    Service service = null;
    URL wsdlURL;
    if (StringUtils.isNotBlank(wsdlLocation) && StringUtils.isNotBlank(serviceName)) {
        try {
            URIResolver uriResolver = new URIResolver();
            uriResolver.resolve("", wsdlLocation, this.getClass());
            wsdlURL = uriResolver.isResolved() ? uriResolver.getURL() : new URL(wsdlLocation);
            service = Service.create(wsdlURL, QName.valueOf(serviceName));
        } catch (Exception e) {
            LOGGER.error("Unable to create service from WSDL location.", e);
        }
    }
    return service;
}

From source file:org.jboss.additional.testsuite.jdkall.present.web.classloading.ear.DelegateClassLoaderWSTestCase.java

private static GreeterEJB getClient(URL deploymentUrl) throws MalformedURLException {
    String wsdlUrlString = deploymentUrl.toExternalForm().replace(EAR_NAME, EJB_MODULE_NAME)
            + GreeterEJBImpl.CLASS_NAME + "?wsdl";
    URL wsdlUrl = new URL(wsdlUrlString);
    QName serviceName = new QName(GreeterEJBImpl.NAMESPACE, GreeterEJBImpl.SERVICE_NAME);
    return Service.create(wsdlUrl, serviceName).getPort(GreeterEJB.class);
}

From source file:org.jboss.additional.testsuite.jdkall.present.web.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.web.present.jdkall.testsuite.additional.jboss.org/",
            "ImageServerImplService");

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

    FileInputStream inputStream = new FileInputStream(path + "../" + serverLogPath);
    try {//from w  w  w .j av  a2  s . co 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.jboss.as.jbossws.jbpapp10625.DuplicateServicesGeneratedWsdlIT.java

protected <T> T createServiceProxy(String serviceURL, Class<T> serviceProxyClass, QName serviceName)
        throws MalformedURLException {
    Service service = Service.create(createWsdlUrl(serviceURL), serviceName);
    return service.getPort(serviceProxyClass);
}

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/*www.  j  a  va2 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();
        }
    }
}