Added an example client to invoke example web-service
Update license files
This commit is contained in:
parent
8d24fe61f2
commit
341c4ce5d1
234
wsexample/client/pom.xml
Normal file
234
wsexample/client/pom.xml
Normal file
|
@ -0,0 +1,234 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsexampleclient</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1</version>
|
||||
<name>Gson Web Service Example Client</name>
|
||||
<description>An example for Writing Clients for JSON based Web-services</description>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>local.repo</id>
|
||||
<name>file repository to svn</name>
|
||||
<url>file://${basedir}/../../../mavenrepo</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gson</id>
|
||||
<url>http://google-gson.googlecode.com/svn/mavenrepo</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<connection>scm:svn:http://google-gson.googlecode.com/svn/trunk/wsexample/client</connection>
|
||||
<developerConnection>scm:svn:https://google-gson.googlecode.com/svn/trunk/wsexample/client</developerConnection>
|
||||
<url>http://google-gson.codegoogle.com/svn/trunk/wsexample/client</url>
|
||||
</scm>
|
||||
<issueManagement>
|
||||
<system>Google Code Issue Tracking</system>
|
||||
<url>http://code.google.com/p/google-gson/issues/list</url>
|
||||
</issueManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Gson: Java to Json conversion -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsclient</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsexampledef</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>wsexampleclient</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
<workspace>../../eclipse-ws</workspace>
|
||||
<workspaceCodeStylesURL>file:///${basedir}/../../lib/gson-formatting-styles.xml</workspaceCodeStylesURL>
|
||||
<wtpversion>1.5</wtpversion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<!-- configuration>
|
||||
<updateReleaseInfo>true</updateReleaseInfo>
|
||||
<createChecksum>true</createChecksum>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<classifier>sources</classifier>
|
||||
<file>target/wsexampleclient-sources.jar</file>
|
||||
</configuration -->
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>maven-jetty-plugin</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jxr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- TODO(inder): add manifest entry for maven group, artifact, and classifier ids -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- TODO(inder): add manifest entry for maven group, artifact, and classifier ids -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>src/main/resources/javadoc-descriptor.xml</archive>
|
||||
<links>
|
||||
<link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
|
||||
</links>
|
||||
<version>true</version>
|
||||
<useDefaultManifestFile>true</useDefaultManifestFile>
|
||||
<show>public</show>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<configuration>
|
||||
<targetJdk>1.5</targetJdk>
|
||||
<rulesets>
|
||||
<ruleset>/rulesets/basic.xml</ruleset>
|
||||
<ruleset>/rulesets/imports.xml</ruleset>
|
||||
<ruleset>/rulesets/unusedcode.xml</ruleset>
|
||||
<ruleset>/rulesets/finalizers.xml</ruleset>
|
||||
</rulesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- configLocation>config/sun_checks.xml</configLocation -->
|
||||
<configLocation>config/maven_checks.xml</configLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>taglist-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<tags>
|
||||
<tag>TODO</tag>
|
||||
<tag>@todo</tag>
|
||||
<tag>FIXME</tag>
|
||||
<tag>XXX</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>clean</id>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<configuration>
|
||||
<arguments>-DenableCiProfile=true</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-2</version>
|
||||
<configuration>
|
||||
<descriptor>src/main/resources/assembly-descriptor.xml</descriptor>
|
||||
<finalName>wsexampledef-${version}</finalName>
|
||||
<outputDirectory>target/dist</outputDirectory>
|
||||
<workDirectory>target/assembly/work</workDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Inderjeet Singh</name>
|
||||
<organization>Google Inc.</organization>
|
||||
</developer>
|
||||
</developers>
|
||||
</project>
|
|
@ -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<LineItem> lineItems = new ArrayList<LineItem>();
|
||||
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 );
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user