我正在开发一个项目来连接测试仪器并使用 web 服务从它获取请求和响应。
我必须从仪器请求多个服务,但是当我@Get
在服务器中使用两个以上的 s 时,我的浏览器中出现错误提示
无法访问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;
}
}
我还附上了错误消息的图像。