Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何Ping返回类型为void的web服务方法_Java_Web Services_Ping - Fatal编程技术网

Java 如何Ping返回类型为void的web服务方法

Java 如何Ping返回类型为void的web服务方法,java,web-services,ping,Java,Web Services,Ping,嗨,我在服务代理中有一个web服务类,它有一个返回void的方法。我必须检查服务是否已启动并处于活动状态。由于该方法返回void,我无法获取服务的状态。有没有办法通过使用或不使用ping来检查此web服务方法的状态 下面是我的webservice方法,返回类型为void。此web服务方法将执行一些验证并触发另一个方法,以便它不会返回任何值 @GET @Path("/triggers/{name}") public void triggerMethod(@Path

嗨,我在服务代理中有一个web服务类,它有一个返回void的方法。我必须检查服务是否已启动并处于活动状态。由于该方法返回void,我无法获取服务的状态。有没有办法通过使用或不使用ping来检查此web服务方法的状态

下面是我的webservice方法,返回类型为void。此web服务方法将执行一些验证并触发另一个方法,以便它不会返回任何值

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

    }
下面是ping函数的代码,但它将从响应中检查状态。这段代码用于webservices方法,它返回ig response并接受APPLICATION_JSON

    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);
        }
    }   

我完全肯定你不能不归还任何东西就这么做。客户端将不知道请求是否完成,除非返回的服务是否正常, 否则,客户端将等待响应。 因此,必须使方法返回Response类型的对象。您不需要在响应中添加任何内容,只要告诉方法返回200即可

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

应返回response.ok