Java Code Examples for javax.xml.ws.Service

The following examples show how to use javax.xml.ws.Service. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cxf   Source File: HTTPGetTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSOAPClientSecurityPolicy() throws Exception {
    if (!TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        return;
    }

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

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

    URL wsdl = HTTPGetTest.class.getResource("DoubleItHTTPGet.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItKeyIdentifierPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, PORT);
    int result = x509Port.doubleIt(25);
    assertEquals(result, 50);

    bus.shutdown(true);
}
 
Example 2
public <T> Dispatch<T> createDispatch(QName portName, WSEndpointReference wsepr, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    PortInfo port = safeGetPort(portName);

    ComponentFeature cf = features.get(ComponentFeature.class);
    if (cf != null && !Target.STUB.equals(cf.getTarget())) {
        throw new IllegalArgumentException();
    }
    ComponentsFeature csf = features.get(ComponentsFeature.class);
    if (csf != null) {
        for (ComponentFeature cfi : csf.getComponentFeatures()) {
            if (!Target.STUB.equals(cfi.getTarget()))
                throw new IllegalArgumentException();
        }
    }
    features.addAll(this.features);

    BindingImpl binding = port.createBinding(features, null, null);
    binding.setMode(mode);
    Dispatch<T> dispatch = Stubs.createDispatch(port, this, binding, aClass, mode, wsepr);
    serviceInterceptor.postCreateDispatch((WSBindingProvider) dispatch);
    return dispatch;
}
 
Example 3
Source Project: cxf   Source File: WSSCUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEndorsingSecureConverationSP12() throws Exception {

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

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

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

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

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

    ((java.io.Closeable)port).close();
}
 
Example 4
Source Project: mwsc   Source File: Invoker.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a classloader for loading JAXB/WS 2.1 jar and tools.jar
 */
private static URL[] findIstackAPIs(ClassLoader cl) throws ClassNotFoundException, MalformedURLException, ToolsJarNotFoundException {
    List<URL> urls = new ArrayList<URL>();

    if(Service.class.getClassLoader()==null) {
        // JAX-WS API is loaded from bootstrap classloader
        URL res = cl.getResource("javax/xml/ws/EndpointReference.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAX-WS 2.1 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));

        res = cl.getResource("javax/xml/bind/annotation/XmlSeeAlso.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAXB 2.1 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));
    }

    findToolsJar(cl, urls);

    return urls.toArray(new URL[urls.size()]);
}
 
Example 5
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAsymmetricEncryption() throws Exception {

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

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

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

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

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 6
Source Project: cxf   Source File: STSClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testDefaultSTSClient() throws Exception {

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

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

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

    doubleIt(transportSaml1Port, 25);

    ((java.io.Closeable)transportSaml1Port).close();
    bus.shutdown(true);
}
 
Example 7
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAsymmetricSignatureSP11() throws Exception {

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

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

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

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

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 8
Source Project: cxf   Source File: SecondClient.java    License: Apache License 2.0 6 votes vote down vote up
public static SecondServiceAT newInstance() throws Exception {
    URL wsdlLocation = new URL("http://localhost:8082/Service/SecondServiceAT?wsdl");
    QName serviceName = new QName("http://service.ws.sample", "SecondServiceATService");
    QName portName = new QName("http://service.ws.sample", "SecondServiceAT");

    Service service = Service.create(wsdlLocation, serviceName);
    SecondServiceAT client = service.getPort(portName, SecondServiceAT.class);


    List<Handler> handlerChain = new ArrayList<>();
    JaxWSTxOutboundBridgeHandler txOutboundBridgeHandler = new JaxWSTxOutboundBridgeHandler();
    EnabledWSTXHandler wstxHandler = new EnabledWSTXHandler();

    handlerChain.add(txOutboundBridgeHandler);
    handlerChain.add(wstxHandler);

    ((BindingProvider)client).getBinding().setHandlerChain(handlerChain);

    return client;
}
 
Example 9
Source Project: jdk8u60   Source File: WSServiceDelegate.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected Dispatch<Object> createDispatch(QName portName, WSEndpointReference wsepr, JAXBContext jaxbContext, Service.Mode mode, WebServiceFeatureList features) {
    PortInfo port = safeGetPort(portName);

    ComponentFeature cf = features.get(ComponentFeature.class);
    if (cf != null && !Target.STUB.equals(cf.getTarget())) {
        throw new IllegalArgumentException();
    }
    ComponentsFeature csf = features.get(ComponentsFeature.class);
    if (csf != null) {
        for (ComponentFeature cfi : csf.getComponentFeatures()) {
            if (!Target.STUB.equals(cfi.getTarget()))
                throw new IllegalArgumentException();
        }
    }
    features.addAll(this.features);

    BindingImpl binding = port.createBinding(features, null, null);
    binding.setMode(mode);
    Dispatch<Object> dispatch = Stubs.createJAXBDispatch(
            port, binding, jaxbContext, mode,wsepr);
     serviceInterceptor.postCreateDispatch((WSBindingProvider)dispatch);
     return dispatch;
}
 
Example 10
Source Project: cxf   Source File: ClaimsTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSaml2ChildClaims() throws Exception {

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

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

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

    doubleIt(transportClaimsPort, 25);

    ((java.io.Closeable)transportClaimsPort).close();
    bus.shutdown(true);
}
 
Example 11
Source Project: cxf   Source File: DispatchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSOAPPBindingNullMessage() throws Exception {
    d.setMessageObserver(new MessageReplayObserver("/org/apache/cxf/jaxws/sayHiResponse.xml"));

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_soap_http.types");
    Dispatch<Object> disp = service.createDispatch(PORT_NAME, jc, Service.Mode.PAYLOAD);
    try {
        // Send a null message
        disp.invoke(null);
    } catch (SOAPFaultException e) {
        //Passed
        return;
    }

    fail("SOAPFaultException was not thrown");
}
 
Example 12
Source Project: cxf   Source File: StaxTransformFeatureTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testTransformFeature() throws Exception {

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

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

    URL wsdl = StaxTransformFeatureTest.class.getResource("DoubleItTransform.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort2");
    DoubleItPortType2 port =
            service.getPort(portQName, DoubleItPortType2.class);
    updateAddressPort(port, PORT);

    assertEquals(50, port.doubleIt2(25));

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

    bus.shutdown(true);
}
 
Example 13
protected Dispatch<Object> createDispatch(QName portName, JAXBContext jaxbContext, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, jaxbContext, mode, features);
}
 
Example 14
Source Project: jdk8u60   Source File: Invoker.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar
 */
private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
    List<URL> urls = new ArrayList<URL>();

    if(Service.class.getClassLoader()==null) {
        // JAX-WS API is loaded from bootstrap classloader
        URL res = cl.getResource("javax/xml/ws/EndpointContext.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));
        res = cl.getResource("javax/xml/bind/JAXBPermission.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));
    }

    findToolsJar(cl, urls);

    return urls.toArray(new URL[urls.size()]);
}
 
Example 15
Source Project: openjdk-jdk8u-backup   Source File: Invoker.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar
 */
private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
    List<URL> urls = new ArrayList<URL>();

    if(Service.class.getClassLoader()==null) {
        // JAX-WS API is loaded from bootstrap classloader
        URL res = cl.getResource("javax/xml/ws/EndpointContext.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));
        res = cl.getResource("javax/xml/bind/JAXBPermission.class");
        if(res==null)
            throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath");
        urls.add(ParallelWorldClassLoader.toJarUrl(res));
    }

    findToolsJar(cl, urls);

    return urls.toArray(new URL[urls.size()]);
}
 
Example 16
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAsymmetricSHA512() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509TokenTest.class.getResource("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, "DoubleItAsymmetricSHA512Port");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

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

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 17
Source Project: hottub   Source File: WSEndpointReference.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} 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 Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 18
Source Project: openjdk-8   Source File: DispatchImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void checkValidDataSourceDispatch(WSBinding binding, Service.Mode mode) {
    // Dispatch<DataSource> is only valid with xml/http binding and in Service.Mode.MESSAGE
    if (!DispatchImpl.isXMLHttp(binding))
        throw new WebServiceException(DispatchMessages.INVALID_DATASOURCE_DISPATCH_BINDING("SOAP/HTTP", HTTPBinding.HTTP_BINDING));
    if (DispatchImpl.isPAYLOADMode(mode))
        throw new WebServiceException(DispatchMessages.INVALID_DATASOURCE_DISPATCH_MSGMODE(mode.name(), Service.Mode.MESSAGE.toString()));
}
 
Example 19
Source Project: tomee   Source File: AttachmentTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a webservice client using wsdl url
 *
 * @throws Exception
 */
//START SNIPPET: webservice
public void testAttachmentViaWsInterface() throws Exception {
    Service service = Service.create(
            new URL("http://localhost:" + port + "/webservice-attachments/AttachmentImpl?wsdl"),
            new QName("http://superbiz.org/wsdl", "AttachmentWsService"));
    assertNotNull(service);

    AttachmentWs ws = service.getPort(AttachmentWs.class);

    // retrieve the SOAPBinding
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) ws).getBinding();
    binding.setMTOMEnabled(true);

    String request = "[email protected]";

    // Byte array
    String response = ws.stringFromBytes(request.getBytes());
    assertEquals(request, response);

    // Data Source
    DataSource source = new ByteArrayDataSource(request.getBytes(), "text/plain; charset=UTF-8");

    // not yet supported !
    //        response = ws.stringFromDataSource(source);
    //        assertEquals(request, response);

    // Data Handler
    response = ws.stringFromDataHandler(new DataHandler(source));
    assertEquals(request, response);

}
 
Example 20
Source Project: jdk8u60   Source File: WSEndpointReference.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} 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 Dispatch<Object> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull JAXBContext context,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),context,mode,features);
}
 
Example 21
Source Project: cxf   Source File: BinarySecurityTokenTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testBinarySecurityToken() throws Exception {

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

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

    URL wsdl = BinarySecurityTokenTest.class.getResource("DoubleItTokens.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    // Successful invocation
    QName portQName = new QName(NAMESPACE, "DoubleItBinarySecurityTokenPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);

    // Mock up a BinarySecurityToken to add
    SecurityToken securityToken = new SecurityToken();
    securityToken.setId("_" + UUID.randomUUID().toString());

    Document doc = DOMUtils.newDocument();
    BinarySecurity binarySecurity = new BinarySecurity(doc);
    binarySecurity.setValueType("http://custom-value-type");
    binarySecurity.setToken("This is a token".getBytes());

    securityToken.setToken(binarySecurity.getElement());

    ((BindingProvider)port).getRequestContext().put(SecurityConstants.TOKEN, securityToken);

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

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 22
Source Project: cxf   Source File: FaultTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUnsecuredSoap11Action() throws Exception {

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

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

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

    try {
        utPort.doubleIt(25);
        fail("Expected failure on bob");
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("This is a fault"));
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 23
Source Project: cxf   Source File: PartsTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSOAPFaultError() throws Exception {

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

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

    URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    // This should fail, as the service requires a (bad) header
    QName portQName = new QName(NAMESPACE, "DoubleItRequiredPartsPort2");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        port.doubleIt(25);
        fail("Failure expected on a required header which isn't present");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "RequiredParts: No header element";
        assertTrue(ex.getMessage().contains(error)
                   || ex.getMessage().contains("ToTo must be present"));
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 24
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testTransportSignedEndorsing() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509TokenTest.class.getResource("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, "DoubleItTransportSignedEndorsingPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    String port = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        port = STAX_PORT2;
    }
    updateAddressPort(x509Port, port);

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

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 25
Source Project: cxf   Source File: GCMTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAESGCM256MGFSHA256() throws Exception {
    if (!unrestrictedPoliciesInstalled) {
        return;
    }

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

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

    URL wsdl = GCMTest.class.getResource("DoubleItGCM.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItGCM256MGFSHA256Port");
    DoubleItPortType gcmPort =
            service.getPort(portQName, DoubleItPortType.class);

    String port = MGF_PORT;
    if (STAX_PORT.equals(test.getPort())) {
        port = MGF_STAX_PORT;
    }
    updateAddressPort(gcmPort, port);

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

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

    ((java.io.Closeable)gcmPort).close();
    bus.shutdown(true);
}
 
Example 26
@Override
@SuppressWarnings("unchecked")
public Class<? extends Service> value() {
    if (value == null) {
        return Service.class;
    }
    return (Class<Service>) findClass(value);
}
 
Example 27
Source Project: cxf   Source File: DispatchXMLClientServerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamSourceMESSAGE() throws Exception {
    /*URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService(wsdl, serviceName);
    assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat",
                    "http://localhost:"
                    + port
                    + "/XMLService/XMLDispatchPort");

    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    StreamSource reqMsg = new StreamSource(is);
    assertNotNull(reqMsg);

    Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
    Source source = disp.invoke(reqMsg);
    assertNotNull(source);

    String streamString = StaxUtils.toString(source);
    Document doc = StaxUtils.read(new StringReader(streamString));
    assertEquals("greetMeResponse", doc.getFirstChild().getLocalName());
    assertEquals("Hello tli", doc.getFirstChild().getTextContent());
}
 
Example 28
Source Project: tomee   Source File: CalculatorTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testCalculatorViaWsInterfaceWithSign() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplSign?wsdl"),
            new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);

    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl",
                    "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
            "http://127.0.0.1:8204/CalculatorImplSign");

    //      CalculatorWs calc = calcService.getPort(
    //	new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    //	CalculatorWs.class);

    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);

    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());

    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    outProps.put(WSHandlerConstants.USER, "clientalias");
    outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {

        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
            final WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
            pc.setPassword("clientPassword");
        }
    });
    outProps.put(WSHandlerConstants.SIG_PROP_FILE, "META-INF/CalculatorImplSign-client.properties");
    outProps.put(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");

    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);

    assertEquals(24, calc.multiply(4, 6));
}
 
Example 29
Source Project: cxf   Source File: JaxwsBasicAuthTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testBadBasicAuth() throws Exception {

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

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

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

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

    try {
        doubleIt(port, 30);
        fail("Expected failure on a bad password");
    } catch (javax.xml.ws.soap.SOAPFaultException fault) {
        String message = fault.getMessage();
        assertTrue(message.contains("STS Authentication failed")
            || message.contains("Validation of security token failed"));
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 30
Source Project: cxf   Source File: TemplateTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSAML1PublicKey() throws Exception {

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

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

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

    // Setup STSClient
    STSClient stsClient = createSTSClient(bus);
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);

    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.STS_CLIENT, stsClient
    );

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

    doubleIt(port, 25);

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