@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; } } );
//Enable MTOM SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true);
final void createJaxwsBinding() { if (getBinding() instanceof SoapBinding) { jaxwsBinding = new SOAPBindingImpl(getEndpointInfo().getBinding(), this); MTOMFeature mtomFeature = getMTOMFeature(); if (mtomFeature != null && mtomFeature.isEnabled()) { ((SOAPBinding)jaxwsBinding).setMTOMEnabled(true); } } else if (getBinding() instanceof XMLBinding) { jaxwsBinding = new HTTPBindingImpl(getEndpointInfo().getBinding(), this); } else { //REVISIT: Should not get here, though some bindings like JBI //did not implement their own Binding type. jaxwsBinding = new DefaultBindingImpl(this); } }
//codes enable MTOM in client BindingProvider bp = (BindingProvider) imageServer; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true);
private Endpoint publish(String address, Object implementor) { Provider provider = Provider.provider(); if (provider.getClass().getName().startsWith("weblogic.")) { // workaround for WebLogic address = address + "/"; } Endpoint endpoint = Endpoint.publish(address, implementor); SOAPBinding binding = (SOAPBinding) endpoint.getBinding(); binding.setMTOMEnabled(true); return endpoint; } }
public void addService(String serviceSuburl, Object serviceImplementor) { Endpoint ep = Endpoint.publish("http://" + hostName + ":" + port + "/" + serviceSuburl, serviceImplementor); SOAPBinding soap = (SOAPBinding) ep.getBinding(); soap.setMTOMEnabled(false); }
Service service = Service.create(url, qname); Greeting greeting = service.getPort(Greeting.class); BindingProvider bp = (BindingProvider) greeting; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true); List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new RGBSOAPHandler()); binding.setHandlerChain(handlerList);
/** * Configures SOAP binding of the given SOAP port. */ 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()); }
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()); } ep.getBinding().setHandlerChain(handlerChain); } if (mtom && ep.getBinding() instanceof SOAPBinding) { SOAPBinding binding = (SOAPBinding) ep.getBinding(); binding.setMTOMEnabled(mtom); } } }
/** * Configures the port with the default handlers, endpoint and mtom.<br/> * <br/> * <b>ATTENTION:</b> If <i>mtom</i> is enabled, you need to provide a handler that forces MTOM * to be done manually. There is a bug in the JDK classes which prevents MTOM and handlers to * work at the same time. For more information about this issue, see <a * href="https://java.net/jira/browse/WSIT-1320">this link</a>. * * @param bindingProvider the current binding provider * @param endpointAddress the target address * @param mtom enables mtom * @param mustUnderstand sets the must understand flag in certain headers, see {@link EnsureMustUnderstandHandler} * @param addLogHandler add the log handler using default directory <JBOSS_LOG_DIR>/xdslog/sentMessages */ public static void configurePort(BindingProvider bindingProvider, String endpointAddress, boolean mtom, boolean mustUnderstand, boolean addLogHandler) { SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding(); binding.setMTOMEnabled(mtom); if (mustUnderstand) { addHandler(bindingProvider, new EnsureMustUnderstandHandler()); } if (addLogHandler) { addHandler(bindingProvider, new SentSOAPLogHandler()); } Map<String, Object> reqCtx = bindingProvider.getRequestContext(); reqCtx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress); }
@Test public void testMTOM() throws Exception { QName serviceName = new QName("http://cxf.apache.org/jms_mtom", "JMSMTOMService"); QName portName = new QName("http://cxf.apache.org/jms_mtom", "MTOMPort"); URL wsdl = getWSDLURL("/wsdl/jms_test_mtom.wsdl"); JMSMTOMService service = new JMSMTOMService(wsdl, serviceName); JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class); Binding binding = ((BindingProvider)mtom).getBinding(); ((SOAPBinding)binding).setMTOMEnabled(true); Holder<String> name = new Holder<>("Sam"); URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class"); Holder<DataHandler> handler1 = new Holder<>(); handler1.value = new DataHandler(fileURL); int size = handler1.value.getInputStream().available(); mtom.testDataHandler(name, handler1); byte[] bytes = IOUtils.readBytesFromStream(handler1.value.getInputStream()); Assert.assertEquals("The response file is not same with the sent file.", size, bytes.length); ((Closeable)mtom).close(); }
@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); }
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; } }
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); } }
final void createJaxwsBinding() { if (getBinding() instanceof SoapBinding) { jaxwsBinding = new SOAPBindingImpl(getEndpointInfo().getBinding(), this); MTOMFeature mtomFeature = getMTOMFeature(); if (mtomFeature != null && mtomFeature.isEnabled()) { ((SOAPBinding)jaxwsBinding).setMTOMEnabled(true); } } else if (getBinding() instanceof XMLBinding) { jaxwsBinding = new HTTPBindingImpl(getEndpointInfo().getBinding(), this); } else { //REVISIT: Should not get here, though some bindings like JBI //did not implement their own Binding type. jaxwsBinding = new DefaultBindingImpl(this); } }
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(); 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(); } } public void tearDown() {
protected void doPublish(String baseAddress) { // XXX: assume port 8080 by default since we don't know the actual port at startup String address = (baseAddress == null) ? "http://localhost:8080" : baseAddress; JaxWsServerFactoryBean svrFactory = new GeronimoJaxWsServerFactoryBean(); svrFactory.setBus(bus); svrFactory.setAddress(address + this.portInfo.getLocation()); svrFactory.setServiceFactory(serviceFactory); svrFactory.setStart(false); svrFactory.setServiceBean(implementor); if (HTTPBinding.HTTP_BINDING.equals(implInfo.getBindingType())) { svrFactory.setTransportId("http://cxf.apache.org/bindings/xformat"); } server = svrFactory.create(); init(); //org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint(); if (getBinding() instanceof SOAPBinding && this.portInfo.getMtomFeatureInfo() != null) { ((SOAPBinding) getBinding()).setMTOMEnabled(this.portInfo.getMtomFeatureInfo().isEnabled()); } server.start(); }
@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(); }
@BeforeClass public static void startServers() throws Exception { broker = new EmbeddedJMSBrokerLauncher(); broker.startInProcess(); bus = BusFactory.getDefaultBus(); broker.updateWsdl(bus, "testutils/jms_test_mtom.wsdl"); Object mtom = new JMSMTOMImpl(); EndpointImpl ep = (EndpointImpl)Endpoint .publish("jms:jndi:dynamicQueues/test.cxf.jmstransport.queue&receiveTimeout=10000", mtom); Binding binding = ep.getBinding(); ((SOAPBinding)binding).setMTOMEnabled(true); }
@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); }