2017-10-11 5 views
1

안녕하세요 저는 서비스 프록시에서 void를 반환하는 웹 서비스 클래스가 있습니다. 서비스가 정상적으로 작동하는지 확인해야합니다. 이 메소드는 void를 반환하기 때문에 서비스의 상태를 가져올 수 없습니다. ping을 사용하거나 사용하지 않고이 웹 서비스 메서드의 상태를 확인할 수있는 방법이 있습니까?리턴 타입이 void 인 웹 서비스 메소드를 핑 (ping)하는 방법

다음은 반환 유형 void가있는 나의 webservice 방법입니다. 이 웹 서비스 메서드는 일부 유효성 검사를 수행하고 다른 값을 반환하지 않도록 다른 메서드를 트리거합니다.

@GET 
     @Path("/triggers/{name}") 
     public void triggerMethod(@PathParam("name") String triggername, @Context HttpServletRequest aHttpRequest){ 
      //code 

    } 

아래 코드는 핑 기능에 이미 존재하지만 응답으로부터 상태를 점검합니다. 이 코드는 returnig 응답이며 APPLICATION_JSON을 허용하는 webservices 메소드에서 작동합니다.

private void invoketrigger(ServiceDataDTO myData){ 

      try{ 
     target.request().headers(getRequestHeaders()).accept(MediaType.APPLICATION_JSON).get(); 
      Client client = ClientBuilder.newClient(); 
        WebTarget target = client.target(myData.getServiceURI()); 
        Response response = target.request().headers(getRequestHeaders()).accept(MediaType.APPLICATION_JSON).get(); 
        if(response.getStatus() == 200){ 
         status = "green"; 
      } 
    } 




The code which I tried for my method is given below. 

private void invoketrigger(ServiceDataDTO myData){ 

     try{ 
    target.request().headers(getRequestHeaders()).accept(MediaType.APPLICATION_JSON).get(); 
     URL url = new URL(myData.getServiceURI()); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
     connection.setConnectTimeout(10000); 
     connection.setReadTimeout(10000); 
     connection.setRequestMethod("GET"); 
     connection.connect(); 
     int response = connection.getResponseCode(); 

     if(response == 200){ 
      myData.setServiceStatus(ServicesDashboardConstants.STATUS_OK); 
     } 
     }catch(Exception e){ 
      System.out.println(e); 
     } 
    } 
+0

response.ok를 반환해야합니다. –

답변

1

나는 아무것도 반환하지 않고서는 그렇게 할 수 없다고 확신합니다. 클라이언트 측은 반환 된 서비스가 OK 인 경우가 아니면 요청이 완료되었는지 여부를 알 수 없으므로 이 아니면 클라이언트 측에서 응답을 기다립니다. 메소드가 Response 유형의 오브젝트를 리턴하도록해야합니다. 응답에 아무 것도 추가 할 필요가 없습니다. 메소드를 반환하여 012를 반환하도록

response.ok (200) ; // this will tell the method what is the status code response