From 341c4ce5d1cf4803fabed4499ae27f546a594562 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 16 Jul 2010 16:06:41 +0000 Subject: [PATCH] Added an example client to invoke example web-service Update license files --- wsexample/client/pom.xml | 234 ++++++++++++++++++ .../gson/example/client/ExampleClient.java | 65 +++++ .../com/google/gson/example/model/Cart.java | 17 +- .../google/gson/example/model/LineItem.java | 17 +- .../com/google/gson/example/model/Order.java | 17 +- .../google/gson/example/model/TypedKeys.java | 17 +- .../example/service/SampleJsonService.java | 17 +- 7 files changed, 374 insertions(+), 10 deletions(-) create mode 100644 wsexample/client/pom.xml create mode 100644 wsexample/client/src/main/java/com/google/gson/example/client/ExampleClient.java diff --git a/wsexample/client/pom.xml b/wsexample/client/pom.xml new file mode 100644 index 00000000..f78a4ad9 --- /dev/null +++ b/wsexample/client/pom.xml @@ -0,0 +1,234 @@ + + + + + 4.0.0 + com.google.code.gson + wsexampleclient + jar + 0.1 + Gson Web Service Example Client + An example for Writing Clients for JSON based Web-services + + + local.repo + file repository to svn + file://${basedir}/../../../mavenrepo + + + + + gson + http://google-gson.googlecode.com/svn/mavenrepo + + true + + + true + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:svn:http://google-gson.googlecode.com/svn/trunk/wsexample/client + scm:svn:https://google-gson.googlecode.com/svn/trunk/wsexample/client + http://google-gson.codegoogle.com/svn/trunk/wsexample/client + + + Google Code Issue Tracking + http://code.google.com/p/google-gson/issues/list + + + + + + + com.google.code.gson + gson + 1.5 + compile + + + com.google.code.gson + wsdef + 0.1 + compile + + + com.google.code.gson + wsclient + 0.1 + compile + + + com.google.code.gson + wsexampledef + 0.1 + compile + + + + junit + junit + 3.8.2 + test + + + + + wsexampleclient + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.5.1 + + true + true + ../../eclipse-ws + file:///${basedir}/../../lib/gson-formatting-styles.xml + 1.5 + + + + org.apache.maven.plugins + maven-install-plugin + 2.2 + + + + org.mortbay.jetty + maven-jetty-plugin + 6.0.1 + + 10 + + + + org.apache.maven.plugins + maven-jxr-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + src/main/resources/javadoc-descriptor.xml + + http://java.sun.com/j2se/1.5.0/docs/api/ + + true + true + public + + + + org.apache.maven.plugins + maven-pmd-plugin + + 1.5 + + /rulesets/basic.xml + /rulesets/imports.xml + /rulesets/unusedcode.xml + /rulesets/finalizers.xml + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + config/maven_checks.xml + + + + org.codehaus.mojo + taglist-maven-plugin + + + TODO + @todo + FIXME + XXX + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + clean + + clean + + + + + + org.apache.maven.plugins + maven-release-plugin + + -DenableCiProfile=true + + + + maven-assembly-plugin + 2.2-beta-2 + + src/main/resources/assembly-descriptor.xml + wsexampledef-${version} + target/dist + target/assembly/work + + + + + + + Inderjeet Singh + Google Inc. + + + diff --git a/wsexample/client/src/main/java/com/google/gson/example/client/ExampleClient.java b/wsexample/client/src/main/java/com/google/gson/example/client/ExampleClient.java new file mode 100644 index 00000000..85875876 --- /dev/null +++ b/wsexample/client/src/main/java/com/google/gson/example/client/ExampleClient.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.gson.example.client; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +import com.google.gson.example.model.Cart; +import com.google.gson.example.model.LineItem; +import com.google.gson.example.model.Order; +import com.google.gson.example.model.TypedKeys; +import com.google.gson.example.service.SampleJsonService; +import com.google.gson.webservice.client.WebServiceClient; +import com.google.gson.webservice.client.WebServiceConfig; +import com.google.gson.webservice.definition.HeaderMap; +import com.google.gson.webservice.definition.HttpMethod; +import com.google.gson.webservice.definition.RequestBody; +import com.google.gson.webservice.definition.WebServiceCallSpec; +import com.google.gson.webservice.definition.WebServiceRequest; +import com.google.gson.webservice.definition.WebServiceResponse; + +public class ExampleClient { + + private final WebServiceClient wsClient; + public ExampleClient() { + WebServiceConfig serverConfig = new WebServiceConfig("http://localhost"); + wsClient = new WebServiceClient(serverConfig, Level.INFO); + } + + public Order placeOrder(Cart cart, String authToken) { + WebServiceCallSpec spec = SampleJsonService.PLACE_ORDER; + HeaderMap requestHeaders = new HeaderMap.Builder(spec.getRequestSpec().getHeadersSpec()) + .put(TypedKeys.Request.AUTH_TOKEN, authToken) + .build(); + RequestBody requestBody = new RequestBody.Builder(spec.getRequestSpec().getBodySpec()) + .put(TypedKeys.RequestBody.CART, cart) + .build(); + WebServiceRequest request = new WebServiceRequest(HttpMethod.POST, requestHeaders, requestBody); + WebServiceResponse response = wsClient.getResponse(spec, request); + return response.getBody().get(TypedKeys.ResponseBody.ORDER); + } + + public static void main(String[] args) { + ExampleClient client = new ExampleClient(); + List lineItems = new ArrayList(); + lineItems.add(new LineItem("item1", 2, 1000000L, "USD")); + Cart cart = new Cart(lineItems, "first last", "4111-1111-1111-1111"); + String authToken = "authToken"; + client.placeOrder(cart, authToken ); + } +} diff --git a/wsexample/definition/src/main/java/com/google/gson/example/model/Cart.java b/wsexample/definition/src/main/java/com/google/gson/example/model/Cart.java index 50333c63..61b6c434 100644 --- a/wsexample/definition/src/main/java/com/google/gson/example/model/Cart.java +++ b/wsexample/definition/src/main/java/com/google/gson/example/model/Cart.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.gson.example.model; import java.util.List; diff --git a/wsexample/definition/src/main/java/com/google/gson/example/model/LineItem.java b/wsexample/definition/src/main/java/com/google/gson/example/model/LineItem.java index 1d1b02d9..992ed9bb 100644 --- a/wsexample/definition/src/main/java/com/google/gson/example/model/LineItem.java +++ b/wsexample/definition/src/main/java/com/google/gson/example/model/LineItem.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.gson.example.model; /** diff --git a/wsexample/definition/src/main/java/com/google/gson/example/model/Order.java b/wsexample/definition/src/main/java/com/google/gson/example/model/Order.java index 7674eb27..2ff17a99 100644 --- a/wsexample/definition/src/main/java/com/google/gson/example/model/Order.java +++ b/wsexample/definition/src/main/java/com/google/gson/example/model/Order.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.gson.example.model; /** diff --git a/wsexample/definition/src/main/java/com/google/gson/example/model/TypedKeys.java b/wsexample/definition/src/main/java/com/google/gson/example/model/TypedKeys.java index 7f6f0163..bc03fcb7 100644 --- a/wsexample/definition/src/main/java/com/google/gson/example/model/TypedKeys.java +++ b/wsexample/definition/src/main/java/com/google/gson/example/model/TypedKeys.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.gson.example.model; import com.google.gson.webservice.definition.TypedKey; diff --git a/wsexample/definition/src/main/java/com/google/gson/example/service/SampleJsonService.java b/wsexample/definition/src/main/java/com/google/gson/example/service/SampleJsonService.java index 5a513f81..a21ba713 100644 --- a/wsexample/definition/src/main/java/com/google/gson/example/service/SampleJsonService.java +++ b/wsexample/definition/src/main/java/com/google/gson/example/service/SampleJsonService.java @@ -1,5 +1,18 @@ -// Copyright 2010 Google Inc. All Rights Reserved. - +/* + * Copyright (C) 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.google.gson.example.service; import com.google.gson.example.model.TypedKeys; import com.google.gson.webservice.definition.CallPath;