Search in sources :

Example 41 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project eap-additional-testsuite by jboss-set.

the class MtomTestCase method mtomTest.

@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 {
        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();
    }
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) Image(java.awt.Image) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 42 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project csb-sdk by aliyun.

the class Main method testWithProxy.

/**
 * Call MTOM/WS with static proxy client
 *
 * @throws Exception
 */
public void testWithProxy() throws Exception {
    // Create the service client endpoint
    AttachmentWSService service = new AttachmentWSService(new URL(wsdlAddr));
    // Get the proxy port
    AttachmentWS port = service.getAttachmentWSPort(new javax.xml.ws.soap.MTOMFeature());
    // Set enable MTOM
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddr);
    binding.setMTOMEnabled(true);
    // 使用SDK将AK, SK传输的调用client端
    port = WSClientSDK.bind(port, ak, sk);
    String testString = "this is a mtom String";
    String retStr = port.echoBinaryAsString(testString.getBytes());
    System.out.println("return Str=" + retStr);
    // Assert.assertTrue("Not equal", testString.equals(retStr));
    byte[] retBytes = port.echoStringAsBinary(testString);
    // Assert.assertTrue("Not equal", testString.equals(new String(retBytes)));
    System.out.println("return Str=" + retBytes);
    final File f = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "com/alibaba/csb/sdk/ws/mtom/MtomSDKTest.class");
    String upFile = "/tmp/a.class";
    // file upload
    port.fileUpload(upFile, new DataHandler(new FileDataSource(f)));
    // file download
    upFile = "/tmp/b.class";
    DataHandler dh = port.fileDownload(upFile);
    OutputStream os = new FileOutputStream(new File(upFile));
    dh.writeTo(os);
/**/
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) AttachmentWSService(com.alibaba.csb.ws.wsimpl.AttachmentWSService) URL(java.net.URL) AttachmentWS(com.alibaba.csb.ws.wsimpl.AttachmentWS) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) File(java.io.File)

Example 43 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project csb-sdk by aliyun.

the class MtomSDKTest method testWithProxy.

@Test
public /**
 * Call MTOM/WS with static proxy client
 *
 * @throws Exception
 */
void testWithProxy() throws Exception {
    // Create the service client endpoint
    AttachmentWSService service = new AttachmentWSService(new URL(wsdlAddr));
    // Get the proxy port
    AttachmentWS port = service.getAttachmentWSPort(new javax.xml.ws.soap.MTOMFeature());
    // Set enable MTOM
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddr);
    binding.setMTOMEnabled(true);
    // 使用SDK将AK, SK传输的调用client端
    port = WSClientSDK.bind(port, ak, sk, "ci-ws2ws-mtom-import", "1.0.0");
    int times = Integer.getInteger("times", 1);
    for (int i = 0; i < times; i++) {
        System.out.println("----- Execute the test with #" + i + " time");
        String testString = "this is a mtom String";
        String retStr = port.echoBinaryAsString(testString.getBytes());
        System.out.println("return Str=" + retStr);
        Assert.assertTrue("Not equal", testString.equals(retStr));
        byte[] retBytes = port.echoStringAsBinary(testString);
        Assert.assertTrue("Not equal", testString.equals(new String(retBytes)));
        System.out.println("return Str=" + retBytes);
        final File f = new File(MtomSDKTest.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "com/alibaba/csb/sdk/ws/mtom/MtomSDKTest.class");
        String upFile = "/tmp/new.class";
        // file upload
        port.fileUpload(upFile, new DataHandler(new FileDataSource(f)));
        // file download
        DataHandler dh = port.fileDownload(upFile);
        OutputStream os = new FileOutputStream(new File(upFile));
        dh.writeTo(os);
    /**/
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) AttachmentWSService(com.alibaba.csb.ws.wsimpl.AttachmentWSService) URL(java.net.URL) AttachmentWS(com.alibaba.csb.ws.wsimpl.AttachmentWS) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) File(java.io.File) Test(org.junit.Test)

Example 44 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project jbossws-cxf by jbossws.

the class JBWS3250TestCase method testMtomSawpFile.

@Test
@RunAsClient
public void testMtomSawpFile() throws Exception {
    URL wsdlURL = new URL(baseURL + "?wsdl");
    QName serviceName = new QName("http://ws.jboss.org/jbws3250", "TestEndpointService");
    Endpoint port = Service.create(wsdlURL, serviceName).getPort(Endpoint.class);
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    URL url = JBossWSTestHelper.getResourceURL("jaxws/jbws3250/wsf.png");
    URLDataSource urlDatasource = new URLDataSource(url);
    javax.activation.DataHandler dh = new DataHandler(urlDatasource);
    MTOMRequest request = new MTOMRequest();
    request.setContent(dh);
    request.setId("largeSize_mtom_request");
    MTOMResponse mtomResponse = port.echo(request);
    Assert.assertEquals("Response for requestID:largeSize_mtom_request", mtomResponse.getResponse());
    byte[] responseBytes = IOUtils.convertToBytes(mtomResponse.getContent());
    Assert.assertTrue(responseBytes.length > 65536);
}
Also used : URLDataSource(javax.activation.URLDataSource) QName(javax.xml.namespace.QName) SOAPBinding(javax.xml.ws.soap.SOAPBinding) DataHandler(javax.activation.DataHandler) DataHandler(javax.activation.DataHandler) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 45 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project jbossws-cxf by jbossws.

the class BusHolder method configure.

/**
 * Update the Bus held by the this instance using the provided parameters.
 * This basically prepares the bus for being used with JBossWS.
 *
 * @param resolver               The ResourceResolver to configure, if any
 * @param configurer             The JBossWSCXFConfigurer to install in the bus, if any
 * @param wsmd                   The current JBossWebservicesMetaData, if any
 * @param dep                    The current deployment
 */
public void configure(ResourceResolver resolver, Configurer configurer, JBossWebservicesMetaData wsmd, Deployment dep) {
    if (configured) {
        throw Messages.MESSAGES.busAlreadyConfigured(bus);
    }
    bus.setProperty(org.jboss.wsf.stack.cxf.client.Constants.DEPLOYMENT_BUS, true);
    busHolderListener = new BusHolderLifeCycleListener();
    bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(busHolderListener);
    setWSDLManagerStreamWrapper(bus);
    if (configurer != null) {
        bus.setExtension(configurer, Configurer.class);
    }
    Map<String, String> props = getProperties(wsmd);
    setInterceptors(bus, dep, props);
    dep.addAttachment(Bus.class, bus);
    try {
        final JASPIAuthenticationProvider jaspiProvider = SPIProvider.getInstance().getSPI(JASPIAuthenticationProvider.class, ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
        if (jaspiProvider != null && jaspiProvider.enableServerAuthentication(dep, wsmd)) {
            bus.getInInterceptors().add(new AuthenticationMgrSubjectCreatingInterceptor());
        }
    } catch (WSFException e) {
        Loggers.DEPLOYMENT_LOGGER.cannotFindJaspiClasses();
    }
    setResourceResolver(bus, resolver);
    if (bus.getExtension(PolicyEngine.class) != null) {
        bus.getExtension(PolicyEngine.class).setAlternativeSelector(getAlternativeSelector(props));
    }
    // *first* enabled cxf management if required, *then* add anything else which could be manageable (e.g. work queues)
    setCXFManagement(bus, props);
    setAdditionalWorkQueues(bus, props);
    setWSDiscovery(bus, props);
    AnnotationsInfo ai = dep.getAttachment(AnnotationsInfo.class);
    if (ai == null || ai.hasAnnotatedClasses(PolicySets.class.getName())) {
        policySetsListener = new PolicySetsAnnotationListener(dep.getClassLoader());
        bus.getExtension(FactoryBeanListenerManager.class).addListener(policySetsListener);
    }
    // default to USE_ORIGINAL_THREAD = true; this can be overridden by simply setting the property in the endpoint or in the message using an interceptor
    // this forces one way operation to use original thread, which is required for ejb webserivce endpoints to avoid authorization failures from ejb container
    // and is a performance improvement in general when running in-container, as CXF needs to cache the message to free the thread, which is expensive
    // (moreover the user can tune the web container thread pool instead of expecting cxf to fork new threads)
    bus.setProperty(OneWayProcessorInterceptor.USE_ORIGINAL_THREAD, true);
    // [JBWS-3135] enable decoupled faultTo. This is an optional feature in cxf and we need this to be default to make it same behavior with native stack
    bus.setProperty("org.apache.cxf.ws.addressing.decoupled_fault_support", true);
    FeatureUtils.addFeatures(bus, bus, props);
    for (DDEndpoint dde : metadata.getEndpoints()) {
        EndpointImpl endpoint = new EndpointImpl(bus, newInstance(dde.getImplementor()));
        if (dde.getInvoker() != null)
            endpoint.setInvoker(newInvokerInstance(dde.getInvoker(), dep));
        endpoint.setAddress(dde.getAddress());
        endpoint.setEndpointName(dde.getPortName());
        endpoint.setServiceName(dde.getServiceName());
        endpoint.setWsdlLocation(dde.getWsdlLocation());
        setHandlers(endpoint, dde);
        if (dde.getProperties() != null) {
            Map<String, Object> p = new HashMap<String, Object>();
            p.putAll(dde.getProperties());
            endpoint.setProperties(p);
        }
        if (dde.isAddressingEnabled()) {
            WSAddressingFeature addressingFeature = new WSAddressingFeature();
            addressingFeature.setAddressingRequired(dde.isAddressingRequired());
            addressingFeature.setResponses(dde.getAddressingResponses());
            endpoint.getFeatures().add(addressingFeature);
        }
        endpoint.setPublishedEndpointUrl(dde.getPublishedEndpointUrl());
        endpoint.setSOAPAddressRewriteMetadata(dep.getAttachment(SOAPAddressRewriteMetadata.class));
        endpoint.publish();
        endpoints.add(endpoint);
        if (dde.isMtomEnabled()) {
            SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
            binding.setMTOMEnabled(true);
        }
    }
    configured = true;
}
Also used : DDEndpoint(org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint) HashMap(java.util.HashMap) EndpointImpl(org.jboss.wsf.stack.cxf.deployment.EndpointImpl) SOAPAddressRewriteMetadata(org.jboss.wsf.spi.metadata.config.SOAPAddressRewriteMetadata) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) SOAPBinding(javax.xml.ws.soap.SOAPBinding) FactoryBeanListenerManager(org.apache.cxf.service.factory.FactoryBeanListenerManager) PolicySetsAnnotationListener(org.jboss.wsf.stack.cxf.extensions.policy.PolicySetsAnnotationListener) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) JASPIAuthenticationProvider(org.jboss.wsf.spi.security.JASPIAuthenticationProvider) WSFException(org.jboss.wsf.spi.WSFException) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager) AnnotationsInfo(org.jboss.wsf.spi.deployment.AnnotationsInfo) AuthenticationMgrSubjectCreatingInterceptor(org.jboss.wsf.stack.cxf.security.authentication.AuthenticationMgrSubjectCreatingInterceptor)

Aggregations

SOAPBinding (javax.xml.ws.soap.SOAPBinding)51 Test (org.junit.Test)20 URL (java.net.URL)19 BindingProvider (javax.xml.ws.BindingProvider)19 QName (javax.xml.namespace.QName)18 Service (javax.xml.ws.Service)14 DataHandler (javax.activation.DataHandler)13 WebServiceException (javax.xml.ws.WebServiceException)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 JBossWSTest (org.jboss.wsf.test.JBossWSTest)7 ArrayList (java.util.ArrayList)6 Holder (javax.xml.ws.Holder)6 Image (java.awt.Image)5 IOException (java.io.IOException)5 Binding (javax.xml.ws.Binding)5 File (java.io.File)4 Before (org.junit.Before)4 FileDataSource (javax.activation.FileDataSource)3 Handler (javax.xml.ws.handler.Handler)3 MTOMFeature (javax.xml.ws.soap.MTOMFeature)3