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 9205723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:01:07+00:00 2026-06-18T00:01:07+00:00

I am using REST-Jersey in my project. All the POST data is send in

  • 0

I am using REST-Jersey in my project. All the POST data is send in JSON format and unmarshalled at server-side into respective beans. Something like this:

Sending request to server:

    $('a#sayHelloPost').click(function(event){
        event.preventDefault();
        var mangaData = {
            title:'Bleach',
            author:'Kubo Tite'
        }
        var formData=JSON.stringify(mangaData);
        console.log(formData);
        $.ajax({
                url:'rest/cred/sayposthello',
                type: 'POST',
                data: formData,
                dataType: 'json',
                contentType:'application/json'
        })
});

Payload:

{"title":"Bleach","author":"Kubo Tite"}

Server-end:

@POST
@Path("/sayposthello")
@Produces(MediaType.APPLICATION_JSON)
public Response sayPostHello(MangaBean mb){
    System.out.println(mb);
    return Response.status(200).build();
}

MangaBean:

public class MangaBean {
    private String title;
    private String author;
    @Override
    public String toString() {
        return "MangaBean [title=" + title + ", author=" + author + "]";
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}

Output on console:

MangaBean [title=Bleach, author=Kubo Tite]

I got the REST-interceptor implementation from here.

public class JerseyFilter implements ContainerRequestFilter{

    @Override
    public ContainerRequest filter(ContainerRequest req) {
        return req;
    }

} 

I want to access the payload(request body) in the interceptor. As the data is in JSON format, its not accessible as request parameters. Is there a way I can get the request body in the interceptor method? Please advice.

  • 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-06-18T00:01:08+00:00Added an answer on June 18, 2026 at 12:01 am

    Here is one way you can implement, very similar to how Jersey implements its logging filters. You can read the entity and stick it back to the request, so you accidentally do not consume it in your filter.

    import com.sun.jersey.api.container.ContainerException;
    import com.sun.jersey.core.util.ReaderWriter;
    import com.sun.jersey.spi.container.ContainerRequest;
    import com.sun.jersey.spi.container.ContainerRequestFilter;
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    public class JerseyFilter implements ContainerRequestFilter {
    
        @Override
        public ContainerRequest filter(ContainerRequest request) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            InputStream in = request.getEntityInputStream();
            final StringBuilder b = new StringBuilder();
            try {
                if (in.available() > 0) {
                    ReaderWriter.writeTo(in, out);
    
                    byte[] requestEntity = out.toByteArray();
                    printEntity(b, requestEntity);
    
                    request.setEntityInputStream(new ByteArrayInputStream(requestEntity));
                }
                return request;
            } catch (IOException ex) {
                throw new ContainerException(ex);
            }
    
        }
    
        private void printEntity(StringBuilder b, byte[] entity) throws IOException {
            if (entity.length == 0)
                return;
            b.append(new String(entity)).append("\n");
            System.out.println("#### Intercepted Entity ####");
            System.out.println(b.toString());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jetty web server, and Jersey for REST handling. I defined: @POST
I have a REST- Server here using JERSEY. I must log the IP (better
I'm currently building a simple REST interface using Jersey with embedded Jetty. Server server
I've written a simple REST server using JAX-RS, Jersey and Grizzly. This is how
I have an REST service, using jersey, and dont want to need to send
I have a REST service that produces a JSON output. I'm using Jersey. I
I'm trying to debug a rest/json service that i build using Jersey and Amazon
I am using jersey for a REST WS. How do I enable jersey logs
I am using Jersey/Java to develop my REST services. I need to return an
I am creating a REST Web Service using Java and Jersey API. The basic

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.