Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6855883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:48:53+00:00 2026-05-27T01:48:53+00:00

Clarification: this question was about GZIPping an JAX-WS-based REST service, but I’ve decided to

  • 0

Clarification: this question was about GZIPping an JAX-WS-based REST service, but I’ve decided to change the topic to make it easier to find

I’m implementing a REST service via JAX-WS Provider <Source>, and publishing it with standard Endpoint (the reason is that I want to avoid using a servlet container or application server).

Is there a way to make server to gzip response content, if Accept-Encoding: gzip is present?


HOW-TO

Samples provided by nicore actually works, and it allows you to make JAX-RS-styled server on top of embedded lightweight server without servlet container, but there are few moments to be considered.

If you prefer to manage classes by yourself (and save a time during startup), you may use the following:

Example

JAX-RS hello world class:

@Path("/helloworld")
public class RestServer {

    @GET
    @Produces("text/html")
    public String getMessage(){
        System.out.println("sayHello()");
        return "Hello, world!";
    }
}

Main method:

For Simple Server:

public static void main(String[] args) throws Exception{
    DefaultResourceConfig resourceConfig = new DefaultResourceConfig(RestServer.class);
    // The following line is to enable GZIP when client accepts it
    resourceConfig.getContainerResponseFilters().add(new GZIPContentEncodingFilter());
    Closeable server = SimpleServerFactory.create("http://0.0.0.0:5555", resourceConfig);
    try {
        System.out.println("Press any key to stop the service...");
        System.in.read();
    } finally {
        server.close();
    }
}

For Grizzly2:

public static void main(String[] args) throws Exception{
    DefaultResourceConfig resourceConfig = new DefaultResourceConfig(RestServer.class);
    // The following line is to enable GZIP when client accepts it
    resourceConfig.getContainerResponseFilters().add(new GZIPContentEncodingFilter());
    HttpServer server = GrizzlyServerFactory.createHttpServer("http://0.0.0.0:5555" , resourceConfig);
    try {
        System.out.println("Press any key to stop the service...");
        System.in.read();
    } finally {
        server.stop();
    }
}

Resolved dependencies:

Simple:

  • Simple Framework itself
  • jersey-simple-server

Grizzly:

  • grizzly-framework
  • grizzly-http
  • grizzly-http-server (different repository!)
  • jersey-grizzly2

Jersey:

  • jersey-archive

Notice

Make sure the javax.ws.rs archive didnt get into your classpath, as it conflicts with Jersey’s implementation. The worst thing here is a silent 404 error with no logging – only a small note on FINER level is logged.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:48:53+00:00Added an answer on May 27, 2026 at 1:48 am

    If you really want to do REST with Java I would suggest you to to use a JAX-RS implementation (RESTeasy, Jersey…).

    If your main concern is the dependency on a servlet container, you could use the JAX-RS RuntimeDelegate to register your application as a JAX-RS endpoint.

    // Using grizzly as the underlaying server
    SelectorThread st = RuntimeDelegate.createEndpoint(new MyApplication(), SelectorThread.class);
    
    st.startEndpoint();
    
    // Wait...
    st.stopEndpoint();
    

    Concerning GZIP encoding, each JAX-RS provider has different approaches. Jersey provides a filter to accomplish the encoding transparently. RESTEasy provides an annotation for that.

    EDIT

    I did some small tests. The following two things will definitely work for you, assuming you are using Maven.

    Using Jersey + SimpleServer:

        public static void main( String[] args ) throws Exception {
    
        java.io.Closeable server = null;
    
        try {
            // Creates a server and listens on the address below.
            // Scans classpath for JAX-RS resources
            server = SimpleServerFactory.create("http://localhost:5555");
            System.out.println("Press any key to stop the service...");
            System.in.read();
        } finally {
            try {
                if (server != null) {
                    server.close();
                }
            } finally {
                ;
            }
        }
    }
    

    with maven dependencies

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-simple-server</artifactId>
        <version>1.10</version>
    </dependency>
    

    Or using the Jersey + Grizzly2:

    public static void main(String[] args) throws Exception {
    
        HttpServer server = null;
    
        try {
            server = GrizzlyServerFactory.createHttpServer("http://localhost:5555");
            System.out.println("Press any key to stop the service...");
            System.in.read();
        } finally {
            try {
                if (server != null) {
                    server.stop();
                }
            } finally {
                ;
            }
        }
    }
    

    with maven dependencies

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-grizzly2</artifactId>
        <version>1.10</version>
    </dependency>
    

    Honestly speaking I was not able to get the RuntimeDelegate sample working, too.
    There certainly is a way to start RESTEasy out of the box, too but I cannot recall it at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Clarification: this question is not about access modifier Confirmed that B.m() and b.m() statements
Clarification: this is not about user agent calls to pages, but Classic ASP calling
I feel bad about asking a question so simple, but I can't figure this
This is a clarification question I've got from a Java EE 5 migration. I'm
This might sound stupid, but why doesn't the Java compiler warn about the expression
In response to this question asking about hex to (raw) binary conversion, a comment
This is a brainstorming question about what's possible in Java (or not). I want
That may seem like a broad question, but I'm talking specifically here about apps
EDIT Public health warning - this question includes a false assumption about undefined behaviour.
I have a question about clarification of my homework. http://www.cs.bilkent.edu.tr/~gunduz/teaching/cs201/cs201_homework3.pdf To see the handout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.