Example usage for javax.xml.ws.soap SOAPBinding setMTOMEnabled

List of usage examples for javax.xml.ws.soap SOAPBinding setMTOMEnabled

Introduction

In this page you can find the example usage for javax.xml.ws.soap SOAPBinding setMTOMEnabled.

Prototype

public void setMTOMEnabled(boolean flag);

Source Link

Document

Enables or disables use of MTOM.

Usage

From source file:org.apache.chemistry.opencmis.server.impl.webservices.CmisWebServicesServlet.java

private Endpoint publish(String adress, Object implementor) {
    Endpoint endpoint = Endpoint.publish(adress, implementor);
    SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
    binding.setMTOMEnabled(true);

    return endpoint;
}

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 {/* ww  w .j av  a  2s. 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.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  w  w.  j a v  a  2s . c  om*/
        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.ecm.platform.api.ws.WSEndpointDescriptor.java

public void configurePostPublishing(Endpoint ep) throws IllegalAccessException, InstantiationException {
    if (handlers != null) {
        List<Handler> handlerChain = ep.getBinding().getHandlerChain();
        for (Class<? extends Handler> handler : handlers) {
            handlerChain.add(handler.newInstance());
        }/*from ww w . j  a  v a  2s. c  om*/
        ep.getBinding().setHandlerChain(handlerChain);
    }

    if (mtom && ep.getBinding() instanceof SOAPBinding) {
        SOAPBinding binding = (SOAPBinding) ep.getBinding();
        binding.setMTOMEnabled(mtom);
    }
}

From source file:org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory.java

/**
 * Configures SOAP binding of the given SOAP port.
 *///  w w w  . jav  a2s.  co m
private void configureBinding(Object port) {
    BindingProvider bindingProvider = (BindingProvider) port;

    Map<String, Object> reqContext = bindingProvider.getRequestContext();
    reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl);

    Binding binding = bindingProvider.getBinding();
    SOAPBinding soapBinding = (SOAPBinding) binding;
    soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom());
}

From source file:org.openehealth.ipf.platform.camel.lbs.cxf.process.LbsCxfHugeFileTest.java

@Before
public void setUp() throws Exception {
    File temp = new File("target/store");
    temp.delete();//w  ww .j  ava  2 s.c o  m
    baseDir = new File(temp.getAbsolutePath());
    baseDir.mkdir();

    URL wsdlResource = getClass().getClassLoader().getResource("hello_world.wsdl");
    SOAPService service = new SOAPService(wsdlResource);
    greeter = service.getSoapOverHttp();
    provider = (BindingProvider) greeter;
    SOAPBinding binding = (SOAPBinding) provider.getBinding();
    binding.setMTOMEnabled(true);
    provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ENDPOINT);

    camelContext.addRoutes(createRouteBuilder());
}

From source file:org.openehealth.tutorial.imagebin.ImageBinServer.java

public void start() {
    File directory = new File("target/store");
    directory.mkdir();//from  w ww .  j  a  va  2  s. co m

    log.debug("Starting ImageBin Server");

    // Publish the service
    Object imageBin = new ImageBinImpl(directory.getAbsolutePath());
    String address = "http://localhost:8413/ImageBin/ImageBinPort";
    imageBinEndpoint = Endpoint.publish(address, imageBin);

    // Enable MTOM attachments
    SOAPBinding binding = (SOAPBinding) imageBinEndpoint.getBinding();
    binding.setMTOMEnabled(true);

    log.debug("ImageBin ready");
}

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();
        }/* w  w w. jav  a2s  .co 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.jav  a  2  s  .  c om
 * <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;
}