简体   繁体   English

拥有多个Get in Restful Web服务

[英]Having more than one Get in Restful webservice

I am working on a project to connect test instruments and get request and response from it using webservice. 我正在开发一个项目,以连接测试仪器,并使用webservice从中获取请求和响应。

I have to request more than one service from the instrument, but when I use more than two @Get s in the server, I get an error in my browser saying 我必须从仪器请求多个服务,但是当我在服务器中使用两个以上的@Get ,浏览器提示错误

Cannot access WADL, please restart your restful webservice 无法访问WADL,请重新启动宁静的Web服务

This is my code, 这是我的代码

GET 
@Produces("text/html") 
public String getHtml(){ 
   String ins_name=null; 

   try { 
      String [] env=null; 
      //setting the environment variable. 
      String[]callAndArgs= {"python","instrument_name.py"};//Python and file name 

      Process p = Runtime.getRuntime().exec(callAndArgs,env, 
         new java.io.File("C:\\fakepath\\NetBeansProjects\\DemoApp1\\build\\web"));//executing Python file 


      BufferedReader stdInput = new BufferedReader(new   
      InputStreamReader(p.getInputStream()));//getting the value from Python file    
      BufferedReader stdError = new BufferedReader(new     
      InputStreamReader(p.getErrorStream()));// reading the error     
      ins_name = stdInput.readLine();//reading the output from the Pythonfile     
      System.out.println(ins_name); 
   } 
   catch (IOException e) {//catching the exception 

      System.out.println("exception occured"); 
      e.printStackTrace(); 
      System.exit(-1); 
   } 


   return ins_name;//returning the instrument name 
} 

@GET 
@Produces("text/html") 
public String getHtml1() { 
   String check=null; 
   String c1="hjhj"; 
   String [] env=null; 
   //setting the environment variable. 
   try{ 
      String[] callAndArgs= {"python","check_connection.py",c1};//Python and file name 

      Process p = Runtime.getRuntime().exec(callAndArgs,env, 
      new java.io.File("C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\DemoApp1\\build\\web"));//executing Python file 


      BufferedReader stdInput = new BufferedReader(new 
      InputStreamReader(p.getInputStream()));//getting the value from Python file 

      BufferedReader stdError = new BufferedReader(new 
         InputStreamReader(p.getErrorStream()));// reading the error 

      check= stdInput.readLine();//reading the output from the Python file 
      System.out.println(); 
   } 
   catch (IOException e) {//catching the exception 

      System.out.println("exception occured"); 
      e.printStackTrace(); 
      System.exit(-1); 
   } 
   return check; 
} 

/** 
* Web service operation 

} 

/** 
* PUT method for updating or creating an instance of GenericResource 
* @param content representation for the resource 
* @return an HTTP response with content of the updated or created resource. 
*/ 
@PUT 
@Consumes("text/html") 
public String putHtml(String interface_name) { 

   try { 
      String [] env=null; 
      String [] callAndArgs= {"python","connection.py",this.interface_name=interface_name};//Python file with arguments 

      Process p = Runtime.getRuntime().exec(callAndArgs,env, 
         new java.io.File("C:\\fakepath\\NetBeansProjects\\DemoApp1\\build\\web"));//executing the Python file 



      BufferedReader stdInput = new BufferedReader(new  
         InputStreamReader(p.getInputStream()));//getting the input 


      BufferedReader stdError = new BufferedReader(new 
         InputStreamReader(p.getErrorStream()));//getting the error 


      interface_name = stdInput.readLine();//reading the output 
      System.out.println(interface_name); 
   } 
   catch (IOException e) {//catching the exception  
      System.out.println("exception occured"); 
      e.printStackTrace(); 
      System.exit(-1); 

   } 
   return interface_name; 
} 
} 

I have also attached the image of the error message. 我还附有错误消息的图像。

错误信息

You can't define distinct "GET" for a resource unless you specify distinct Path for your methods @Path("/mypath") in addition to your resource path 除非您为资源@Path(“ / mypath”)指定了不同的路径,否则无法为资源定义不同的“ GET”

@Path("/myRes")
public class myResource{

   @GET @Path("/myAttr")
   public void getAttr(...)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM