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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:36:04+00:00 2026-06-08T11:36:04+00:00

I have pretty simple JAX-RS WS: @Stateless @Path(/foo) public class FooFacadeBean { @GET @Produces(MediaType.TEXT_HTML)

  • 0

I have pretty simple JAX-RS WS:

@Stateless
@Path("/foo")
public class FooFacadeBean {     

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String performFooCall(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        response.setStatus(500);
        return "Hello";
    }
}

After deployment I execute: curl -v localhost:8080/foo,
the result was:

About to connect() to localhost port 8080
Trying 127.0.0.1...
connected
Connected to localhost (127.0.0.1) port 8080
GET /foo HTTP/1.1
User-Agent: curl/7.26.0
Host: localhost:8080
Accept: */

HTTP/1.1 200 OK
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2 Java/Sun Microsystems Inc./1.6)
Server: GlassFish Server Open Source Edition 3.1.2
Content-Type: text/html
Transfer-Encoding: chunked
Date: Thu, 26 Jul 2012 13:52:10 GMT

Hello 

Connection to host localhost left intact
Closing connection

As you can see status code in HTTP hasn’t changed at all, despite of it was set manually.
Why does this happen? I’ve spent a lot of hours googling without any results.

Such workaround as returning Response object, something like this:

Response.status(404).entity("Hello").build();

works perfectly!

Glassfish uses JERSEY as JAX-RS implementation. I use embedded variant of Glassfish.

  • 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-08T11:36:07+00:00Added an answer on June 8, 2026 at 11:36 am

    Basically, that’s not how you should use Jersey.

    Here’s what’s happening:

    • The method executes, and you interact with the ServletResponse and set the status code to 500. But since you don’t write any data, the response isn’t committed.

    • Then the method returns a String value. Since Jersey has no way of knowing if you’ve interacted with the ServletResponse or not, it behaves normally.

    • A String method that returns implies a 200 response code (void implies 204, etc). Jersey tries to set the response code to the default, ultimately by calling setStatus(200) on the response instance. Since the response hasn’t been committed yet, this isn’t a problem, and the response of 500 is changed to 200.

    • The HttpServletResponse is committed and is sent back to the client.

    I’m assuming that what you want to do is return a different status code, but in an exceptional case only. The way to do that is to return a String in the normal case, and then throw a WebApplicationException in the exceptional case.

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String performFooCall() {
        if (isNormal()) {
            return "Hello";
        }
        throw new WebApplicationException(Response.status(500).entity("Hello").build());
    }
    

    Alternatively, you can throw a standard exception, and control how it is rendered as a response with a separate ExceptionMapper.

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

Sidebar

Related Questions

I have a pretty simple class hierarchy: public class DropdownOption<T> /* does NOT implement
I have a pretty simple HABTM set of models class Tag < ActiveRecord::Base has_and_belongs_to_many
I have a pretty simple general programming problem, yet I can't quite get the
I have a pretty simple form: from django import forms class InitialSignupForm(forms.Form): email =
I have a pretty simple block of C# code here... static void ReadMSOfficeWordFile(string file)
I have a pretty simple add class in jquery that changes the opacity of
I have a pretty simple file upload form class in django: class UploadFileForm(forms.Form): category
I have a pretty simple setup that I cannot get to work in silverlight.
I have a pretty simple set up for a messaging application. I simply get
I have a pretty simple mysql request, 1. request calls to table to get

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.