GZIP Using CXF

GZIP Using CXF explains about How to use GZIP compression with CXF framework

GZIP is a text-based encoding protocol which will compress the size of response dramatically

You can configure GZIP encoding with cxf framework according to the following configuration

You can also see the FastInfoset Using CXF, FastInfoset will result in a much better compression rate than gzip because FastInfoset optimize both size and performance, while gzip only deals with size

You can see the below example, which is demonstrating the usage of GZIP With CXF Framework

Note

I am going to re-use CXF Web Service Tutorial

In order to run the client, you need to add cxf libraries to class path, you can see this on below article

Create CXF Client Example

GZIP Using CXF

For enabling GZIP, just change the service interface, For this you need to add the below annotations on service interface class

@GZIP

package com.student;

import javax.jws.WebService;

import org.apache.cxf.annotations.GZIP;

@GZIP
@WebService

public interface ChangeStudentDetails {
 
Student changeName(Student student);
}

Run Client

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.student.ChangeStudentDetails;
import com.student.Student;

// GZIP Compression Using CXF

public final class StudentClient {

   
public static void main(String args[]) throws Exception {

     
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

      factory.setServiceClass
(ChangeStudentDetails.class);
      factory.setAddress
("http://localhost:8080/CXFTutorial/ChangeStudent?wsdl");
      factory.getInInterceptors
().add(new LoggingInInterceptor());
      factory.getOutInterceptors
().add(new LoggingOutInterceptor());
      ChangeStudentDetails client =
(ChangeStudentDetails) factory.create();
      Student student =
new Student();
      student.setName
("Rockey");
      Student changeName = client.changeName
(student);
      System.out.println
("Server said: " + changeName.getName());
      System.exit
(0);
   
}
}

Output
Note

CXF LoggingInInterceptor is not showing the Encoding as gzip, that's why I am reproducing the response using TCPMon tool

You can view a good tutorial about TCPMon Tutorial,

Here you can see that TCPMon tool to show the request / response structure, and see Content-Encoding as gzip

GZIP Using CXF






2 Responses to "GZIP Using CXF"
  1. vrkmurali 2012-03-15 07:46:37.0
  1. admin 2012-03-16 07:46:37.0

Your email address will not be published. Required fields are marked *