summaryrefslogtreecommitdiffstats
path: root/java/sca/samples
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 19:00:30 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-27 19:00:30 +0000
commit4458b23ac9665b4bc3741ef49d649415d911d660 (patch)
treea86f0bedcf0a3720a297444c74e19f0abeb2c056 /java/sca/samples
parent75b62a4217d9d851553419e047a36e4b240f3859 (diff)
Clean up the code
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@779276 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/samples')
-rw-r--r--java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java34
-rw-r--r--java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java57
-rw-r--r--java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java4
-rw-r--r--java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java59
4 files changed, 78 insertions, 76 deletions
diff --git a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java
index f54472b3d7..414c6821ca 100644
--- a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java
+++ b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java
@@ -1,29 +1,29 @@
package helloworldrest;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
-
-import helloworldrest.HelloWorldService;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
/*
* To test, simply run the program
- * Access the service by invoking the getName() method of HelloWorldService
+ * Access the service by invoking the getName() method of HelloWorldService
*/
public class ClientJavaTestService {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- SCADomain scaDomain = SCADomain.newInstance("rest.composite");
- HelloWorldService helloService =
- scaDomain.getService(HelloWorldService.class, "HelloWorldRESTServiceComponent");
-
- //HelloWorldService helloService = new HelloWorldServiceImpl();
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ NodeFactory factory = NodeFactory.newInstance();
+ Node node = factory.createNode("rest.composite", ClientJavaTestService.class.getClassLoader()).start();
+ HelloWorldService helloService = node.getService(HelloWorldService.class, "HelloWorldRESTServiceComponent");
+
+ //HelloWorldService helloService = new HelloWorldServiceImpl();
System.out.println("### Message from REST service " + helloService.getName());
-
- scaDomain.close();
- }
+
+ node.stop();
+ node.destroy();
+ factory.destroy();
+ }
}
diff --git a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java
index ce087d7e53..5f875c1888 100644
--- a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java
+++ b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java
@@ -1,11 +1,13 @@
package helloworldrest;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Formatter;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
/**
*
@@ -14,38 +16,38 @@ import java.io.BufferedReader;
*
*/
public class ClientTestServiceWebapp {
-
- final static String UrlBase = "http://localhost:8080/helloworld-rest-webapp/HelloWorldService";
-
+
+ final static String UrlBase = "http://localhost:8080/helloworld-rest-webapp/HelloWorldService";
+
final static class HttpResponse {
Object content;
int code;
String message;
}
-
+
static HttpResponse makeHttpGetRequest(String method, String url, String contentType) throws Exception {
HttpResponse response = new HttpResponse();
URL urlAddress = new URL(url);
- HttpURLConnection huc = (HttpURLConnection) urlAddress.openConnection();
+ HttpURLConnection huc = (HttpURLConnection)urlAddress.openConnection();
huc.setRequestMethod(method);
huc.setRequestProperty("Content-type", contentType);
huc.connect();
InputStreamReader isr = new InputStreamReader(huc.getInputStream());
-
+
BufferedReader in = new BufferedReader(isr);
String uline = in.readLine();
- response.content = uline;
-
-// huc.disconnect();
-// System.out.println("#### huc disconnected ###");
-
+ response.content = uline;
+
+ // huc.disconnect();
+ // System.out.println("#### huc disconnected ###");
+
return response;
}
static HttpResponse makeHttpRequest(String method, String url, String contentType, InputStream is) throws Exception {
HttpResponse response = new HttpResponse();
URL urlAddress = new URL(url);
- HttpURLConnection huc = (HttpURLConnection) urlAddress.openConnection();
+ HttpURLConnection huc = (HttpURLConnection)urlAddress.openConnection();
huc.setRequestMethod(method);
if (null != is) {
huc.setDoOutput(true);
@@ -55,49 +57,50 @@ public class ClientTestServiceWebapp {
int read;
while ((read = is.read(buf)) != -1) {
os.write(buf, 0, read);
- }
+ }
}
InputStreamReader isr = new InputStreamReader(huc.getInputStream());
BufferedReader in = new BufferedReader(isr);
String uline = in.readLine();
- response.content = uline;
+ response.content = uline;
return response;
}
- static HttpResponse makeHttpGetRequest(String method, String url, String contentType, String content) throws Exception {
+ static HttpResponse makeHttpGetRequest(String method, String url, String contentType, String content)
+ throws Exception {
return makeHttpRequest(method, url, contentType, new ByteArrayInputStream(content.getBytes("UTF-8")));
}
-
+
static HttpResponse makeHttpRequest(String method, String url) throws Exception {
return makeHttpRequest(method, url, null, (InputStream)null);
}
-
+
public static void main(String[] args) {
- try {
+ try {
HttpResponse response;
-
+
System.out.println("Getting the name *BEFORE* setting it:");
response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain");
System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString()));
-
+
System.out.println("Setting the name:");
String newText = "Morpheus";
InputStream inputStream = new ByteArrayInputStream(newText.getBytes());
response = makeHttpRequest("PUT", UrlBase + "/helloworld/setname", "text/plain", inputStream);
-
+
System.out.println("Getting the name *AFTER* setting it:");
response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain");
System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString()));
-
+
System.out.println("POST Operation:");
response = makeHttpGetRequest("POST", UrlBase + "/helloworld/postoperation/prateek", "text/plain");
//System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString()));
-
+
System.out.println("Getting the name *AFTER* the POST operation:");
response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain");
System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString()));
- } catch (Exception e){
+ } catch (Exception e) {
System.out.println("TEST FAILED! :-(");
e.printStackTrace(System.out);
}
diff --git a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java
index 072a26e3d0..9c678d4bd1 100644
--- a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java
+++ b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java
@@ -1,11 +1,13 @@
package helloworldrest;
-import org.osoa.sca.annotations.Remotable;
+import org.oasisopen.sca.annotation.Remotable;
@Remotable
public interface HelloWorldService {
public void setName(String name);
+
public String getName();
+
public void postOperationTest(String name);
}
diff --git a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java
index 6489bfaabc..25e0ba7efb 100644
--- a/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java
+++ b/java/sca/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java
@@ -1,47 +1,44 @@
package helloworldrest;
-import org.osoa.sca.annotations.Scope;
-import org.osoa.sca.annotations.Service;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.Path;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
@Service(HelloWorldService.class)
@Scope("Composite")
@Path("/helloworld")
-
public class HelloWorldServiceImpl implements HelloWorldService {
-
- private String name = new String("original!");
-
- @Path("/setname")
- @PUT
- @Consumes("text/plain")
-
- public void setName(String name){
- this.name = name;
-
- }
-
- //http://<host>:<port>/helloworld-rest-webapp/HelloWorldService/helloworld/getname
- @Path("/getname")
- @GET
- @Produces("text/plain")
- public String getName(){
- return this.name;
- }
-
- @POST
- @Path("/postoperation/{name}/")
- @Consumes("text/plain")
- public void postOperationTest(@PathParam("name")String name){
- this.name = name;
- }
+
+ private String name = new String("original!");
+
+ @Path("/setname")
+ @PUT
+ @Consumes("text/plain")
+ public void setName(String name) {
+ this.name = name;
+
+ }
+
+ //http://<host>:<port>/helloworld-rest-webapp/HelloWorldService/helloworld/getname
+ @Path("/getname")
+ @GET
+ @Produces("text/plain")
+ public String getName() {
+ return this.name;
+ }
+
+ @POST
+ @Path("/postoperation/{name}/")
+ @Consumes("text/plain")
+ public void postOperationTest(@PathParam("name") String name) {
+ this.name = name;
+ }
}