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

  • Home
  • SEARCH
  • 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 6059649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:07+00:00 2026-05-23T08:44:07+00:00

I’m trying to use Jersey as a client for a RESTful application. Specifically I’d

  • 0

I’m trying to use Jersey as a client for a RESTful application. Specifically I’d like to POST some JSON to the server and get JSON back, so my code looks like this:

final JSONObject config = new JSONObject();
clientConfig.put("fooParam", 60 * 5); /* 5 min timeout */

final JSONObject newClient = client.resource(/* URL */).
                          type(MediaType.APPLICATION_JSON).
                          accept(MediaType.APPLICATION_JSON).
                          post(JSONObject.class, config);

this generates the expected HTTP request with the Content-Type and Accept headers set appropriately. Now the server decides the create the requested resource and redirects there using a HTTP/1.1 303 See Other response (which is good practice as far as I know). The good news is that Jersey happily picks up the Location header and indeed requests the resource it was told to. The bad thing is that it seems to have forgot that I only wanted to get application/json resources and sends a GET with

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

which the server answers happily (with perfectly legal HTML). I verified this using Wireshark. The problem is that Jersey blows up on this as it can not parse this into a JSONObject. So my question is

  • Is that behaviour of Jersey correct or rather a bug?
  • Is there some clever way around this?

I’m aware that I could possibly go through Jersey’s ClientResponse class and see if I was redirected myself, but I think there should be a better way to do this.

  • 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-23T08:44:07+00:00Added an answer on May 23, 2026 at 8:44 am

    After a short conversation with Pavel on a Jersey mailing list, it seems as if the problem lies withing the HttpURLConnection class from the Java libraries. Working around this is easy by using the Apache HTTP Client library binding for Jersey, which works nicely.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.