How can the client code calling Java-backed webscript's execute method get a return value, because the execute method returns void? The method is GET.
I have Java-backed webscript code similar to:
public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException{
// some more code to get argument from the URL
int numOfFiles = myClass.getCountOfFiles(..some args..)
}
The above webscript is called by a client code similar to:
try {
URL url = new URL("https://myhost:myport/alfresco/service/fileNum");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
}catch(Exception e) {
logger.error("Exception in callling web service" + e.toString());
}Inside the execute method, I indeed know the num files. But how do I propagate that value to the response obtained in the Client? The output received by the client can be a simple String value (e.g. 30 where 30 is the numOfFiles), and it does not have to be JSON.
Do I need to write any additional code inside execute method to propagate the value of numOfFiles to the client code? And if yes, how to get that value of numOfFiles in the client code?
Is there a way to add values in the WebScriptResponse inside execute, which can be obtained by the client code?