Hi,
What do you mean by "redirect without informing the user".
Do you want to call the equivalent functionality of the @GET annotated
resource method to produce a response entity that is returned as a
response to the @POST annotated resource method. i.e. you want to
avoid an HTTP redirect ? and thus another request/response being
performed by the client?
The redirect support of ResponseBuilder generates an HTTP response
with redirection information in the response. It does not perform an
*internal* redirect in the application itself.
Currently there is no support for an internal redirect mechanism.
Internal redirection is easy in servlet where by the semantics of the
request are easily ignored. But for JAX-RS when there is a @POST
request you essentially want to redirect internally to perform an @GET
request with a certain URI. Note that HTTP redirection does not inform
the client what HTTP method should be invoked on the redirected on the
URI in the HTTP response. In the case of an internal redirection with
a URI one would either have to assume that a redirection to a @GET is
being performed.
It is certainly possible to support some form of internal re-direction
where a POST restrict is manipulated into a GET request to another
URI. For example we could support an explicit type:
public PostToGetInternalRedirection post(@FormParam .....) {
...
URI u = ...
return new PostToGetInternalRedirection(u);
}
There of course could be issues if the request meta-data of the POST
request is utilized by the GET for intentions that were not expected.
Another, perhaps better, way to resolve this is to design your
resource classes, so that the @GET and @POST functionality are related
and the latter can easily reuse the former by invoking a Java method.
Paul.
On Jul 20, 2009, at 8:14 AM, muruganandan.chenniappan_at_wipro.com wrote:
> Hi,
>
> I am new to Jersey. I tried a lot with the following
> problem but could not resolve it. May be it is naïve for you people.
>
> Requirement:
>
> I have a resource class with 2 methods. One method
> has an annotation of @Get and another method @Post.
> The URI of the of GET method will be
>
> http://................../42341.
>
> The last number 42341 is treated as PathParam in the
> method. This method returns an XML object. This XML is then showed
> in the browser.
>
> Now with respect second method @Post, I send 4
> parameters as @FormParam. Some logic is executed.
> In this logic, I am trying to a build a number lets say 4555. Then I
> need to call 1st method.
>
> For this I am a contructing a URI like
> http://...................................../4555.
>
> The execution is then should be redirected. The
> request in redirected to the first method with input as 4555.
> Now the final XML object / schema shows up on the screen.
>
>
> Issue:
>
> The issue lies in the last part, that is, trying to
> redirect. I tried with following code. Both did not work.
>
> Option1 :
> After contructing the URI, Response.temporaryRedirect(uri).build();
>
> Option 2:
> Using ResponseBuilder.contentLocation() then ResponseBuilder.Build()
>
>
> Could any one please let me how to do redirect without informing the
> user
>
>
>
> Regards and thanks,
> Muruganandan
>
> 'When you want something badly enough, the whole world conspires to
> give it to you'
>
> Please do not print this email unless it is absolutely necessary.
>
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of
> the addressee(s) and may contain proprietary, confidential or
> privileged information. If you are not the intended recipient, you
> should not disseminate, distribute or copy this e-mail. Please
> notify the sender immediately and destroy all copies of this message
> and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The
> recipient should check this email and any attachments for the
> presence of viruses. The company accepts no liability for any damage
> caused by any virus transmitted by this email.
>
> www.wipro.com
>