wood burning stoves 2.0*
The moose likes Web Services and the fly likes Having more than one Get in Restful webservice. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Having more than one Get in Restful webservice." Watch "Having more than one Get in Restful webservice." New topic
Author

Having more than one Get in Restful webservice.

Balkishore pandey
Greenhorn

Joined: Apr 19, 2012
Posts: 19
Dear Javaranch members,
I am new to java and Webservices.
I am working on a university project to connect test instruments and get request and response from it using webservice.

I have to request more than one service from the instrument, but when i use more than two @Get in the server, i get an error in browser saying "Cannot access WADL, please restart your restful webservice"

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:\\Users\\Balkishore\\Documents\\NetBeansProjects\\DemoApp1\\build\\web"));//excuting python file



BufferedReader stdInput = new BufferedReader(new

InputStreamReader(p.getInputStream()));//geting the vaue from python file



BufferedReader stdError = new BufferedReader(new

InputStreamReader(p.getErrorStream()));// reading the error




ins_name = stdInput.readLine();//reading the output from the pyhton file




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"));//excuting python file



BufferedReader stdInput = new BufferedReader(new

InputStreamReader(p.getInputStream()));//geting the vaue from python file



BufferedReader stdError = new BufferedReader(new

InputStreamReader(p.getErrorStream()));// reading the error




check= stdInput.readLine();//reading the output from the pyhton 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 agruments

Process p = Runtime.getRuntime().exec(callAndArgs,env,
new java.io.File("C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\DemoApp1\\build\\web"));//excuting 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.
Any help would be very much appreciated.
Thank you very much in advance.

Cheers,
Kishore.



[Thumbnail for Untitled.jpg]

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
As a RESTful service, each resource should have a different URL, right?

How are you addressing (ie the URL used) these resources.

Bill
Balkishore pandey
Greenhorn

Joined: Apr 19, 2012
Posts: 19
@williams

Thank you very much for replying.
Please excuse my stupidity as i am very much new to java and netbeans, i couldn't get what you meant there?
What can i do in the code to create a new URL? do i have to create a new path? if so how would i do it?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I'd say you're missing a couple of @Path annotations. As it is, how is the WS engine supposed to decide between the two methods handling GET?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
What I was talking about is a REST concept, not a Java and certainly not a NetBeans concept.

You might take a look at this Wikipedia article and/or articles mentioned in the ranch FAQ on web services.

It is really important that you absorb RESTful architecture principles before coding any more.

The basic idea is that in a GET operation, the URL specifies a "resource" and the response is the current state of that resource - so:

http://somehost/therestservice/instrumentName/status - would return the status of the instrument
http://somehost/therestservice/instrumentName/value - would return the current reading

The servlet addressed by "therestservice" looks at the URL to decide which resource is desired.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Having more than one Get in Restful webservice.
 
Similar Threads
Connecting to a router
Running java program from another java program
DOS command in java program question..
Is there any need to close the streams which are opened while executing a process?
java program run external command on Unix