Java Code Examples for javax.xml.ws.soap.SOAPBinding#setMTOMEnabled()

The following examples show how to use javax.xml.ws.soap.SOAPBinding#setMTOMEnabled() . 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: ClientMtomXopWithJMSTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startServers() throws Exception {
    Object implementor = new TestMtomJMSImpl();
    bus = BusFactory.getDefaultBus();

    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    PooledConnectionFactory cfp = new PooledConnectionFactory(cf);
    cff = new ConnectionFactoryFeature(cfp);

    EndpointImpl ep = (EndpointImpl)Endpoint.create(implementor);
    ep.getFeatures().add(cff);
    ep.getInInterceptors().add(new TestMultipartMessageInterceptor());
    ep.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    //ep.getInInterceptors().add(new LoggingInInterceptor());
    //ep.getOutInterceptors().add(new LoggingOutInterceptor());
    SOAPBinding jaxWsSoapBinding = (SOAPBinding)ep.getBinding();
    jaxWsSoapBinding.setMTOMEnabled(true);
    ep.publish();
}
 
Example 2
Source File: ClientMtomXopWithJMSTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface,
                                boolean enableMTOM) throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceName(serviceName);
    factory.setServiceClass(serviceEndpointInterface);
    factory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl").toExternalForm());
    factory.setFeatures(Collections.singletonList(cff));
    factory.getInInterceptors().add(new TestMultipartMessageInterceptor());
    factory.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    @SuppressWarnings("unchecked")
    T proxy = (T)factory.create();
    BindingProvider bp = (BindingProvider)proxy;
    SOAPBinding binding = (SOAPBinding)bp.getBinding();
    binding.setMTOMEnabled(true);
    return proxy;
}
 
Example 3
Source File: ClientMtomXopTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run() {
    Object implementor = new TestMtomImpl();
    String address = "http://localhost:" + PORT + "/mime-test";
    String addressProvider = "http://localhost:" + PORT + "/mime-test-provider";
    try {
        jaxep = (EndpointImpl) javax.xml.ws.Endpoint.publish(address, implementor);
        Endpoint ep = jaxep.getServer().getEndpoint();
        ep.getInInterceptors().add(new TestMultipartMessageInterceptor());
        ep.getOutInterceptors().add(new TestAttachmentOutInterceptor());
        jaxep.getInInterceptors().add(new LoggingInInterceptor());
        jaxep.getOutInterceptors().add(new LoggingOutInterceptor());
        SOAPBinding jaxWsSoapBinding = (SOAPBinding) jaxep.getBinding();
        jaxep.getProperties().put("schema-validation-enabled", "true");
        jaxWsSoapBinding.setMTOMEnabled(true);
        EndpointImpl endpoint =
            (EndpointImpl)javax.xml.ws.Endpoint.publish(addressProvider, new TestMtomProviderImpl());
        endpoint.getProperties().put("schema-validation-enabled", "true");
        endpoint.getInInterceptors().add(new LoggingInInterceptor());
        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());

    } catch (Exception e) {
        Thread.currentThread().interrupt();
    }
}
 
Example 4
Source File: MTOMBindingTypeTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDetail() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    ByteArrayOutputStream output = setupOutLogging();

    Holder<byte[]> photo = new Holder<>("CXF".getBytes());
    Holder<Image> image = new Holder<>(getImage("/java.jpg"));

    Hello port = getPort();

    SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
    binding.setMTOMEnabled(true);


    port.detail(photo, image);

    String expected = "<xop:Include ";
    assertTrue(output.toString().indexOf(expected) != -1);
    assertTrue(input.toString().indexOf(expected) != -1);

    assertEquals("CXF", new String(photo.value));
    assertNotNull(image.value);
}
 
Example 5
Source File: JaxWsClient.java    From spring-boot-cxf-integration-example with MIT License 5 votes vote down vote up
/**
 * Sends the specified content file to the WebService
 * 
 * @param name The name of the content to be stored
 * @param content The content to be stored
 * @return The message that tthe server sent back
 */
public String storeContent(String name, DataHandler content) throws Exception {
    ContentStoreHttpPortService contentStoreService = new ContentStoreHttpPortService();
    ContentStoreHttpPort contentStorePort = contentStoreService.getContentStoreHttpPortSoap11();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) contentStorePort).getBinding();
    binding.setMTOMEnabled(true);

    StoreContentRequest request = objectFactory.createStoreContentRequest();
    request.setName(name);
    request.setContent(content);
    
    StoreContentResponse response = contentStorePort.storeContent(request);
    return response.getMessage();
}
 
Example 6
Source File: JaxWsClient.java    From spring-boot-cxf-integration-example with MIT License 5 votes vote down vote up
/**
 * Loads the content with the specified name from the WebService
 * 
 * @param name The name of the content
 * @return The loaded content
 * @throws IOException If an IO error occurs
 */
public DataHandler loadContent(String name) throws IOException {
    ContentStoreHttpPortService service = new ContentStoreHttpPortService();
    ContentStoreHttpPort loadContentPort = service.getContentStoreHttpPortSoap11();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) loadContentPort).getBinding();
    binding.setMTOMEnabled(true);

    LoadContentRequest request = objectFactory.createLoadContentRequest();
    request.setName(name);
    LoadContentResponse response = loadContentPort.loadContent(request);
    DataHandler content = response.getContent();
    return content;
}
 
Example 7
Source File: ClientMtomXopTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface,
                                boolean enableMTOM, boolean installInterceptors) throws Exception {
    ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
    Bus bus = getStaticBus();
    serviceFactory.setBus(bus);
    serviceFactory.setServiceName(serviceName);
    serviceFactory.setServiceClass(serviceEndpointInterface);
    serviceFactory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl"));
    Service service = serviceFactory.create();
    EndpointInfo ei = service.getEndpointInfo(portName);
    JaxWsEndpointImpl jaxwsEndpoint = new JaxWsEndpointImpl(bus, service, ei);
    SOAPBinding jaxWsSoapBinding = new SOAPBindingImpl(ei.getBinding(), jaxwsEndpoint);
    jaxWsSoapBinding.setMTOMEnabled(enableMTOM);

    if (installInterceptors) {
        //jaxwsEndpoint.getBinding().getInInterceptors().add(new TestMultipartMessageInterceptor());
        jaxwsEndpoint.getBinding().getOutInterceptors().add(new TestAttachmentOutInterceptor());
    }

    jaxwsEndpoint.getBinding().getInInterceptors().add(new LoggingInInterceptor());
    jaxwsEndpoint.getBinding().getOutInterceptors().add(new LoggingOutInterceptor());

    Client client = new ClientImpl(bus, jaxwsEndpoint);
    InvocationHandler ih = new JaxWsClientProxy(client, jaxwsEndpoint.getJaxwsBinding());
    Object obj = Proxy
        .newProxyInstance(serviceEndpointInterface.getClassLoader(),
                          new Class[] {serviceEndpointInterface, BindingProvider.class}, ih);
    updateAddressPort(obj, PORT);
    return serviceEndpointInterface.cast(obj);
}
 
Example 8
Source File: MTOMBindingTypeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@org.junit.Ignore
public void testEcho() throws Exception {
    byte[] bytes = ImageHelper.getImageBytes(getImage("/java.jpg"), "image/jpeg");
    Holder<byte[]> image = new Holder<>(bytes);

    Hello port = getPort();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
    binding.setMTOMEnabled(true);

    port.echoData(image);
    assertNotNull(image);
}
 
Example 9
Source File: ValidationWithAttachmentTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void initClient() {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(AttachmentService.class);
    clientFactory.setAddress(ADDRESS);
    client = (AttachmentService) clientFactory.create();

    //enable MTOM in client
    BindingProvider bp = (BindingProvider) client;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);
}
 
Example 10
Source File: WebServiceListener.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws ListenerException {
	if (StringUtils.isNotEmpty(getAddress())) {
		Bus cxfBus = BusFactory.getDefaultBus(false);
		if(cxfBus == null) {
			throw new ListenerException("unable to find SpringBus");
		}
		log.debug("registering listener ["+getName()+"] with JAX-WS CXF Dispatcher on SpringBus ["+cxfBus.getId()+"]");
		endpoint = new EndpointImpl(cxfBus, new MessageProvider(this, getMultipartXmlSessionKey()));
		endpoint.publish("/"+getAddress());
		SOAPBinding binding = (SOAPBinding)endpoint.getBinding();
		binding.setMTOMEnabled(isMtomEnabled());

		if(endpoint.isPublished()) {
			log.debug("published listener ["+getName()+"] on CXF endpoint ["+getAddress()+"]");
		} else {
			log.error("unable to publish listener ["+getName()+"] on CXF endpoint ["+getAddress()+"]");
		}
	}

	//Can bind on multiple endpoints
	if (StringUtils.isNotEmpty(getServiceNamespaceURI())) {
		log.debug("registering listener ["+getName()+"] with ServiceDispatcher by serviceNamespaceURI ["+getServiceNamespaceURI()+"]");
		ServiceDispatcher.getInstance().registerServiceClient(getServiceNamespaceURI(), this);
	}
	else {
		log.debug("registering listener ["+getName()+"] with ServiceDispatcher");
		ServiceDispatcher.getInstance().registerServiceClient(getName(), this); //Backwards compatibility
	}

	super.open();
}
 
Example 11
Source File: AttachmentTest.java    From tomee with 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 12
Source File: JAXWSEnvironment.java    From dropwizard-jaxws with Apache License 2.0 4 votes vote down vote up
/**
 * JAX-WS client factory
 * @param clientBuilder ClientBuilder.
 * @param <T> Service interface type.
 * @return JAX-WS client proxy.
 */
public <T> T getClient(ClientBuilder<T> clientBuilder) {

    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(clientBuilder.getServiceClass());
    proxyFactory.setAddress(clientBuilder.getAddress());

    // JAX-WS handlers
    if (clientBuilder.getHandlers() != null) {
        for (Handler h : clientBuilder.getHandlers()) {
            proxyFactory.getHandlers().add(h);
        }
    }

    // ClientProxyFactoryBean bindingId
    if (clientBuilder.getBindingId() != null) {
        proxyFactory.setBindingId(clientBuilder.getBindingId());
    }

    // CXF interceptors
    if (clientBuilder.getCxfInInterceptors() != null) {
        proxyFactory.getInInterceptors().addAll(clientBuilder.getCxfInInterceptors());
    }
    if (clientBuilder.getCxfInFaultInterceptors() != null) {
        proxyFactory.getInFaultInterceptors().addAll(clientBuilder.getCxfInFaultInterceptors());
    }
    if (clientBuilder.getCxfOutInterceptors() != null) {
        proxyFactory.getOutInterceptors().addAll(clientBuilder.getCxfOutInterceptors());
    }
    if (clientBuilder.getCxfOutFaultInterceptors() != null) {
        proxyFactory.getOutFaultInterceptors().addAll(clientBuilder.getCxfOutFaultInterceptors());
    }

    T proxy = clientBuilder.getServiceClass().cast(proxyFactory.create());

    // MTOM support
    if (clientBuilder.isMtomEnabled()) {
        BindingProvider bp = (BindingProvider)proxy;
        SOAPBinding binding = (SOAPBinding)bp.getBinding();
        binding.setMTOMEnabled(true);
    }

    HTTPConduit http = (HTTPConduit)ClientProxy.getClient(proxy).getConduit();
    HTTPClientPolicy client = http.getClient();
    client.setConnectionTimeout(clientBuilder.getConnectTimeout());
    client.setReceiveTimeout(clientBuilder.getReceiveTimeout());

    return proxy;
}