泽西岛Response.seeOther()未提供HTTP 303状态代码 [英] Jersey Response.seeOther() not giving HTTP 303 status code

查看:103
本文介绍了泽西岛Response.seeOther()未提供HTTP 303状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个社交网站,其中有一个受限制的社区.

当来宾用户应用成员资格请求时,将生成成员资格请求.我正在通过REST API执行此任务.

我在firefox中使用 RESTClient插件发送请求.

当我发送POST请求以将自己添加到受限社区时,响应就是为此生成的成员资格请求.因此,底层的HTTP状态代码为303 See Other POST/GET.

我得到与会员请求相同的正确响应,但状态代码为200 OK(我认为这是会员请求上GET的代码).

但是,我需要将其设为303.我也尝试过调试 .我的发现是球衣Response.seeOther()没有返回303.

请帮助.

代码段如下:

addUserToCommunity方法:

MembershipRequestModel membershipRequest = null;
membershipRequest = communityService.addUserToCommunity(communityId, userId);
if(membershipRequest != null) {
  // Add code 303 if returning membershiprequest
  return seeOther( membershipRequest, 
                   String.valueOf(membershipRequest.getId()), 
                   MembershipRequestRestHandlerImpl.class);
} else {
  return ok(null);
}

seeOther method which in turn calls Response.seeOther() :

public Response seeOther(Object model, String id, Class<?> resource){

  URI location = buildLocation(resource, id);

  return Response.seeOther(location).entity(createResponseItems(model)).build();
}

解决方案

303-请参阅其他本质上是重定向"-浏览器将自动遵循位置标头中提供的URL.您确定这不是您看到的内容吗? IE.也许您正在使用的firefox插件只是跟随重定向(在幕后)并在该位置URL上返回GET方法的结果.尝试使用FireBug,它会向您显示确切的请求-您应该能够在其中看到重定向.

I have a social networking site in which we have a restricted community.

When a guest user applies requests for membership, a membership request is generated. I am performing this task through a REST API.

I am using RESTClient plugin in firefox to send requests.

When I send a POST resquest for adding self to the restricted community, the response is the memebership request generated for the same. Hence, the underlying HTTP status code is 303 See Other POST/GET.

I get proper response for the same with the membership request in response but the status code is 200 OK(which I think is the code for the GET on the membership request).

But, I need the same to be 303. I have tried debugging also. My finding is that the Jersey Response.seeOther() is not returning 303.

Please help.

The code snippets are as follows :

addUserToCommunity method :

MembershipRequestModel membershipRequest = null;
membershipRequest = communityService.addUserToCommunity(communityId, userId);
if(membershipRequest != null) {
  // Add code 303 if returning membershiprequest
  return seeOther( membershipRequest, 
                   String.valueOf(membershipRequest.getId()), 
                   MembershipRequestRestHandlerImpl.class);
} else {
  return ok(null);
}

seeOther method which in turn calls Response.seeOther() :

public Response seeOther(Object model, String id, Class<?> resource){

  URI location = buildLocation(resource, id);

  return Response.seeOther(location).entity(createResponseItems(model)).build();
}

解决方案

303 - See Other is essentially a redirect - browser would automatically follow the URL provided in location header. Are you sure this is not what you see? I.e. maybe the firefox plugin you are using is simply following the redirect (behind the scenes) and returning the result of a GET method on that location URL. Try FireBug which shows you exact requests that went on the wire - you should be able to see the redirect there.

这篇关于泽西岛Response.seeOther()未提供HTTP 303状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆