org.apache.cxf.transport.common.gzip.GZIPOutInterceptor Java Examples

The following examples show how to use org.apache.cxf.transport.common.gzip.GZIPOutInterceptor. 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: SoapClient.java    From document-management-software with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Standard service initialization. Concrete implementations can change the
 * client initialization logic
 */
@SuppressWarnings("unchecked")
protected void initClient(Class<T> serviceClass, int gzipThreshold, boolean log) {
	// Needed to get rig of CXF exception
	// "Cannot create a secure XMLInputFactory"
	System.setProperty("org.apache.cxf.stax.allowInsecureParser", "true");

	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
	if (log) {
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
	}

	if (gzipThreshold >= 0) {
		factory.getInInterceptors().add(new GZIPInInterceptor());
		factory.getOutInterceptors().add(new GZIPOutInterceptor(gzipThreshold));
	}

	factory.setServiceClass(serviceClass);
	factory.setAddress(endpoint);
	client = (T) factory.create();
}
 
Example #2
Source File: RestApiSetup.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static void installRest(ServletContextHandler context, Object... providers) {
    initSwagger();

    BrooklynRestApp app = new BrooklynRestApp();
    for (Object o : providers) {
        app.singleton(o);
    }

    CXFNonSpringJaxrsServlet servlet = new CXFNonSpringJaxrsServlet(app);
    servlet.setBus(BusFactory.newInstance().createBus());
    servlet.getBus().getInInterceptors().add(new GZIPInInterceptor());
    servlet.getBus().getInFaultInterceptors().add(new GZIPInInterceptor());
    servlet.getBus().getOutInterceptors().add(new GZIPOutInterceptor());
    final ServletHolder servletHolder = new ServletHolder(servlet);

    context.addServlet(servletHolder, "/v1/*");
}
 
Example #3
Source File: SyncopeClient.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of the given service class, with configured content type and authentication.
 *
 * @param <T> any service class
 * @param serviceClass service class reference
 * @return service instance of the given reference class
 */
public <T> T getService(final Class<T> serviceClass) {
    synchronized (restClientFactory) {
        restClientFactory.setServiceClass(serviceClass);
        T serviceInstance = restClientFactory.create(serviceClass);

        Client client = WebClient.client(serviceInstance);
        client.type(mediaType).accept(mediaType);
        if (serviceInstance instanceof AnyService || serviceInstance instanceof ExecutableService) {
            client.accept(RESTHeaders.MULTIPART_MIXED);
        }

        ClientConfiguration config = WebClient.getConfig(client);
        config.getRequestContext().put(HEADER_SPLIT_PROPERTY, true);
        config.getRequestContext().put(URLConnectionHTTPConduit.HTTPURL_CONNECTION_METHOD_REFLECTION, true);
        if (useCompression) {
            config.getInInterceptors().add(new GZIPInInterceptor());
            config.getOutInterceptors().add(new GZIPOutInterceptor());
        }
        if (tlsClientParameters != null) {
            HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
            httpConduit.setTlsClientParameters(tlsClientParameters);
        }

        return serviceInstance;
    }
}
 
Example #4
Source File: WSDLGetInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void cleanUpOutInterceptors(Message outMessage) {
    // TODO - how can I improve this to provide a specific interceptor chain that just has the
    // stax, gzip and message sender components, while also ensuring that GZIP is only provided
    // if its already configured for the endpoint.
    Iterator<Interceptor<? extends Message>> iterator = outMessage.getInterceptorChain().iterator();
    while (iterator.hasNext()) {
        Interceptor<? extends Message> inInterceptor = iterator.next();
        if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
                && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
                && !inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
            outMessage.getInterceptorChain().remove(inInterceptor);
        }
    }

}
 
Example #5
Source File: Server.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void run() {
    URL url = getClass().getResource("fault-stack-trace.xml");
    if (url != null) {
        System.setProperty("cxf.config.file.url", url.toString());
    }
    Object implementor;
    String address;

    implementor = new AsyncGreeter();
    address = "http://localhost:" + PORT + "/SoapContext/AsyncSoapPort";
    eps.add(Endpoint.publish(address, implementor));

    implementor = new AsyncEchoProvider();
    address = "http://localhost:" + PORT + "/SoapContext/AsyncEchoProvider";
    eps.add(Endpoint.publish(address, implementor));

    implementor = new GreeterImplMultiPort();
    address = "http://localhost:" + PORT + "/MultiPort/GreeterPort";
    eps.add(Endpoint.publish(address, implementor));

    implementor = new DocLitBareGreeterMultiPort();
    address = "http://localhost:" + PORT + "/MultiPort/DocBarePort";
    eps.add(Endpoint.publish(address, implementor));

    implementor = new GreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    Endpoint ep = Endpoint.publish(address, implementor);
    eps.add(ep);

    implementor = new GreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPortWithGzip";
    Endpoint ep2 = Endpoint.publish(address, implementor);
    ((EndpointImpl)ep2).getService().getInInterceptors().add(new GZIPInInterceptor());
    ((EndpointImpl)ep2).getService().getOutInterceptors().add(new GZIPOutInterceptor());
    eps.add(ep2);

    implementor = new RefGreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort2";
    eps.add(Endpoint.publish(address, implementor));

    //publish port with soap12 binding
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort";


    EndpointImpl e = (EndpointImpl) Endpoint.create(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING,
                                                    new Greeter12Impl());
    e.publish(address);
    eps.add(e);

    implementor = new DocLitBareGreeterImpl();
    address = "http://localhost:" + BARE_PORT + "/SoapContext/SoapPort";
    eps.add(Endpoint.publish(address, implementor));


    implementor = new GreeterImplBogus();
    address = "http://localhost:" + BOGUS_REAL_PORT + "/SoapContext/SoapPort";
    eps.add(Endpoint.publish(address, implementor));
}
 
Example #6
Source File: RetransmissionInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public RetransmissionInterceptor() {
    super(Phase.PREPARE_SEND);
    addAfter(MessageSenderInterceptor.class.getName());
    addBefore(GZIPOutInterceptor.class.getName());
}