Java Code Examples for javax.xml.ws.Service#getPort()

The following examples show how to use javax.xml.ws.Service#getPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSPortConnector.java    From development with Apache License 2.0 6 votes vote down vote up
public <T> T getPort(Service service, Class<T> serviceClass)
        throws ParserConfigurationException {
    // and determine the real endpoint belonging to the provisioning
    // URL, and create the port based on it. Doing so, we omit
    // parsing the remote WSDL twice and also related authentication
    // problems
    EndpointReference epr = determineEndpointReference();
    T port = service.getPort(epr, serviceClass);
    if (requiresUserAuthentication(userName, password)) {
        BindingProvider bindingProvider = (BindingProvider) port;
        Map<String, Object> clientRequestContext = bindingProvider
                .getRequestContext();
        clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,
                userName);
        clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,
                password);
    }
    return port;
}
 
Example 2
Source File: JarResolverTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolver() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    createBus();
    assertNotNull(bus);
    ServiceContractResolverRegistryImpl registry =
        new ServiceContractResolverRegistryImpl();
    registry.setBus(bus);
    assertNotNull(bus.getExtension(ServiceContractResolverRegistry.class));

    JarServiceContractResolver resolver = new JarServiceContractResolver();
    registry.register(resolver);

    Service service = Service.create(serviceName);
    //service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
    //                "http://localhost:9000/SoapContext/SoapPort");
    Greeter greeter = service.getPort(portName,  Greeter.class);
    updateAddressPort(greeter, PORT);

    String resp = greeter.sayHi();
    assertNotNull(resp);
}
 
Example 3
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testPlaintext() throws Exception {

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

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

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }

    assertEquals(50, utPort.doubleIt(25));

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 4
Source File: ActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void test3DESEncryptionGivenKey() throws Exception {

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

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

    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleIt3DESEncryptionPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    assertEquals(50, port.doubleIt(25));

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 5
Source File: SWAActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSWASignatureContentAction() throws Exception {

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

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

    URL wsdl = SWAActionTest.class.getResource("DoubleItSwa.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSWASignatureContentActionPort");
    DoubleItSwaPortType port =
            service.getPort(portQName, DoubleItSwaPortType.class);
    updateAddressPort(port, PORT);

    DoubleIt3 doubleIt = new DoubleIt3();
    doubleIt.setNumberToDouble(25);
    DoubleItResponse response = port.doubleIt3(doubleIt, "12345".getBytes());
    assertEquals(50, response.getDoubledNumber());

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 6
Source File: UsernameTokenDerivedTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Here the key derived from a UsernameToken is used to sign the message signature over the
 * Symmetric binding. The UsernameToken is encrypted.
 */
@org.junit.Test
public void testSymmetricEndorsingEncrypted() throws Exception {

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

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

    URL wsdl = UsernameTokenDerivedTest.class.getResource("DoubleItUtDerived.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricEndorsingEncryptedPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT);

    assertEquals(50, utPort.doubleIt(25));

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 7
Source File: KerberosTokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testKerberosViaCustomTokenAction() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = KerberosTokenTest.class.getResource("client.xml");

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

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

    TestUtil.updateAddressPort(kerberosPort, PORT2);

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

    ((java.io.Closeable)kerberosPort).close();
    bus.shutdown(true);
}
 
Example 8
Source File: SamlTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAudienceRestrictionServiceName() throws Exception {

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

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

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort2");
    DoubleItPortType saml2Port =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml2Port, portNumber);

    // Create a SAML Token with an AudienceRestrictionCondition
    ConditionsBean conditions = new ConditionsBean();
    List<AudienceRestrictionBean> audienceRestrictions = new ArrayList<>();
    AudienceRestrictionBean audienceRestriction = new AudienceRestrictionBean();
    audienceRestriction.setAudienceURIs(Collections.singletonList(
        service.getServiceName().toString()));
    audienceRestrictions.add(audienceRestriction);
    conditions.setAudienceRestrictions(audienceRestrictions);

    SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
    callbackHandler.setConditions(conditions);
    ((BindingProvider)saml2Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );

    saml2Port.doubleIt(25);
}
 
Example 9
Source File: SamlTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml1Supporting() throws Exception {

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

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

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml1SupportingPort");
    DoubleItPortType saml1Port =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml1Port, portNumber);

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml1Port);
    }

    SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(false, true);
    samlCallbackHandler.setConfirmationMethod(SAML1Constants.CONF_BEARER);
    ((BindingProvider)saml1Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler
    );

    int result = saml1Port.doubleIt(25);
    assertTrue(result == 50);

    ((java.io.Closeable)saml1Port).close();
    bus.shutdown(true);
}
 
Example 10
Source File: BasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testNoBasicAuthCredentials() throws Exception {

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

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

    URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort2");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT);

    try {
        utPort.doubleIt(25);
        fail("Failure expected on no basic auth creds");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 11
Source File: MeetingPlannerTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void bookPort() throws Exception {
    final Service service = Service.create(
            new URL("http://127.0.0.1:" + JAX_WS_PORT + "/demo/meeting-planner?wsdl"),
            new QName("http://jaxws.example.superbiz.org/", "MeetingPlannerImplService"));
    final MeetingPlanner planner = service.getPort(MeetingPlanner.class);
    assertTrue(planner.book(new Date(System.currentTimeMillis() + 1000000)));
}
 
Example 12
Source File: SoapUDPTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSOAPUDP() {
    BusFactory.setThreadDefaultBus(staticBus);
    Service service = Service.create(serviceName);
    service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/",
                    "soap.udp://localhost:" + PORT);
    Greeter greeter = service.getPort(localPortName, Greeter.class);

    String reply = greeter.greetMe("test");
    assertEquals("Hello test", reply);
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals("Bonjour", reply);
}
 
Example 13
Source File: SamlSubjectConfTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testHOKNonMatchingCert() throws Exception {

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

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

    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );

    try {
        port.doubleIt(25);
        fail("Failure expected on a non matching cert (SAML -> TLS)");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
    }

    ((java.io.Closeable)port).close();

    bus.shutdown(true);
}
 
Example 14
Source File: X509TokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testKeyIdentifierJaxwsClient() throws Exception {

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

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

    URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItKeyIdentifierPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(x509Port);
    }

    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
            "bob.properties");
    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");

    assertEquals(50, x509Port.doubleIt(25));

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 15
Source File: ClaimsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml2ClaimsCallbackHandler() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ClaimsTest.class.getResource("cxf-client-cbhandler.xml");

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

    URL wsdl = ClaimsTest.class.getResource("DoubleItNoClaims.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2ClaimsPort");
    DoubleItPortType transportClaimsPort =
        service.getPort(portQName, DoubleItPortType.class);

    updateAddressPort(transportClaimsPort, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider)transportClaimsPort, test.getStsPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportClaimsPort);
    }

    doubleIt(transportClaimsPort, 25);

    ((java.io.Closeable)transportClaimsPort).close();
    bus.shutdown(true);
}
 
Example 16
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUsernameTokenAuthorization() throws Exception {
    // Token transformation is not supported for the streaming code
    if (STAX_PORT.equals(test.getPort())) {
        return;
    }

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

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

    URL wsdl = UsernameTokenTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportUTAuthorizationPort");
    DoubleItPortType transportUTPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportUTPort, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportUTPort);
    }

    doubleIt(transportUTPort, 25);

    ((java.io.Closeable)transportUTPort).close();
    bus.shutdown(true);
}
 
Example 17
Source File: SamlSubjectConfTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUnknownCustomMethod() throws Exception {

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

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

    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, false);
    callbackHandler.setConfirmationMethod("urn:oasis:names:tc:SAML:2.0:cm:custom");

    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );

    try {
        port.doubleIt(25);
        fail("Failure expected on an unknown custom subject confirmation method");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 18
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * 2.1.4 (WSS 1.1), User Name with Certificates, Sign, Encrypt
 */
@org.junit.Test
public void testSymmetricSESupporting() throws Exception {

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

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

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSESupportingPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }

    utPort.doubleIt(25);

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 19
Source File: JAASTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUnsuccessfulAuthentication() throws Exception {

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

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

    URL wsdl = JAASTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItUTPort");
    DoubleItPortType utPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT);

    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.USERNAME, "alice");
    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.PASSWORD, "clarinet2");

    try {
        doubleIt(utPort, 25);
        fail("Failure expected on an incorrect password");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 20
Source File: WSEndpointReference.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a proxy that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> T getPort(@NotNull Service jaxwsService,
                 @NotNull Class<T> serviceEndpointInterface,
                 WebServiceFeature... features)     {
    // TODO: implement it in a better way
    return jaxwsService.getPort(toSpec(),serviceEndpointInterface,features);
}