calling a java backed webscript
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2014 05:29 PM
hi everybody,
I made a java backed web script that extends AbstractWebScript(with a java class and a description file, no .ftl) and I want to know how to call it from another java project, one more qquestion: how to return a JSONArray from the overrided method execute in that kind of webscript
thank you
I made a java backed web script that extends AbstractWebScript(with a java class and a description file, no .ftl) and I want to know how to call it from another java project, one more qquestion: how to return a JSONArray from the overrided method execute in that kind of webscript
thank you
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2014 12:06 AM
You can call your webscript using apache commons httpclient,like below
HttpClient client = new HttpClient(); client.getState().setCredentials( new AuthScope("localhost", 8080, "Alfresco"), new UsernamePasswordCredentials("admin", "admin")); String apiurl = "your webscript url"; PostMethod post = new PostMethod(apiurl); JSONObject data = new JSONObject(); data.put("title", "this is a test title"); data.put("content", "this is a test content"); post.setDoAuthentication(true); post.setRequestHeader("Content-Type", "application/json"); post.setRequestEntity(new StringRequestEntity(data.toString(), "application/json", "UTF-8")); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { System.err.println("Method failed: " + post.getStatusLine()); } String resultString = post.getResponseBodyAsString(); System.out.println(resultString);
