我正在开发一个项目来连接测试仪器并使用webservice从中获取请求和响应。
我必须从仪器请求多个服务,但是当我在服务器中使用两个以上@Get
时,我在浏览器中收到错误
无法访问WADL,请重新启动您的restful webservice
这是我的代码,
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;
}
}
我还附上了错误信息的图片。
答案 0 :(得分:1)
您不能为资源定义不同的“GET”,除非您为方法@Path(“/ mypath”)指定了除资源路径之外的不同路径
@Path("/myRes")
public class myResource{
@GET @Path("/myAttr")
public void getAttr(...)
}