2017-12-14 8 views
0

REST 서비스로 테스트 중이므로 HttpServletResponse 개체를 가져와야합니다.HttpServletResponse 받기가 능숙하지 않은 서비스

나는이 같은 함수를 호출 : 내가 부족 뭔가

http://localhost:8080/wsService/api/servicetest/testify

내가 얻는 HttpServletResponse 항상

@Path("/testify") 
@GET 
@Produces(MediaType.APPLICATION_JSON) 
public Response Testify(HttpServletResponse response) throws Exception { 
    try { 
     return Utilities.getSvc(true, "OK"); 

    } catch (Exception e) { 
     return Utilities.getSvc(false, "ERROR"); 
    } 
} 

널 있습니까?

+1

[이]를 (https://stackoverflow.com/questions/20937362/what- 컨텍스트 주석을 사용하여 객체 주입 가능)이 도움이 될 수 있습니다. –

답변

0

드디어 해냈어, 단지 HttpServletRequest 매개 변수 HttpServletResponse 객체에 @Context 주석을 넣고 추가하는 데 필요한 :

@Path("/testify") 
@GET 
@Produces(MediaType.APPLICATION_JSON) 
public Response Testify(@Context HttpServletResponse response, 
         @Context HttpServletRequest request) throws Exception { 
    try { 
     return Utilities.getSvc(true, "OK"); 

    } catch (Exception e) { 
     return Utilities.getSvc(false, "ERROR"); 
    } 
}