• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Having more than one Get in Restful webservice.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Untitled.jpg
[Thumbnail for Untitled.jpg]
Error message.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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?
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic