deleted wsexample and wsexample/server since its contents are now moved to greaze.

This commit is contained in:
Inderjeet Singh 2010-11-14 09:29:22 +00:00
parent c713ce1ab1
commit 371befafa3
4 changed files with 0 additions and 471 deletions

View File

@ -1,237 +0,0 @@
<?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>wsexampleserver</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/server</connection>
<developerConnection>scm:svn:https://google-gson.googlecode.com/svn/trunk/wsexample/server</developerConnection>
<url>http://google-gson.codegoogle.com/svn/trunk/wsexample/server</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.greaze</groupId>
<artifactId>greaze-definition</artifactId>
<version>0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>wsf</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>
<!-- Servlet & Jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>wsexampleserver</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<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>
<!-- configuration>
<updateReleaseInfo>true</updateReleaseInfo>
<createChecksum>true</createChecksum>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>jar</packaging>
<classifier>sources</classifier>
<file>target/wsexampleserver-sources.jar</file>
</configuration -->
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<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>
<configuration>
<descriptor>src/main/resources/assembly-descriptor.xml</descriptor>
<finalName>wsexampleserver-${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>

View File

@ -1,51 +0,0 @@
/*
* 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.wsexample.server;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.greaze.definition.CallPath;
/**
* An example servlet that receives JSON web-service requests
*
* @author inder
*/
@SuppressWarnings("serial")
public class MainServlet extends HttpServlet {
private final RestDispatcher restDispatcher;
private final ProcedureDispatcher procedureDispatcher;
public MainServlet() {
this.restDispatcher = new RestDispatcher();
this.procedureDispatcher = new ProcedureDispatcher();
}
@Override
public void service(HttpServletRequest req, HttpServletResponse res) {
String servletPath = req.getServletPath();
int index = "/wsexampleserver".length();
CallPath callPath = new CallPath(servletPath.substring(index));
String path = callPath.get();
if (path.startsWith("/rest")) {
restDispatcher.service(req, res, callPath);
} else if (path.startsWith("/procedure")) {
procedureDispatcher.service(req, res);
}
}
}

View File

@ -1,78 +0,0 @@
/*
* 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.wsexample.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.greaze.definition.HeaderMap;
import com.google.greaze.definition.webservice.RequestBody;
import com.google.greaze.definition.webservice.RequestBodyGsonConverter;
import com.google.greaze.definition.webservice.RequestSpec;
import com.google.greaze.definition.webservice.ResponseBody;
import com.google.greaze.definition.webservice.ResponseBodyGsonConverter;
import com.google.greaze.definition.webservice.ResponseSpec;
import com.google.greaze.definition.webservice.WebServiceCallSpec;
import com.google.greaze.definition.webservice.WebServiceRequest;
import com.google.greaze.definition.webservice.WebServiceResponse;
import com.google.greaze.example.definition.model.Cart;
import com.google.greaze.example.definition.model.Order;
import com.google.greaze.example.definition.model.TypedKeys;
import com.google.greaze.example.definition.service.SampleJsonService;
import com.google.greaze.webservice.server.RequestReceiver;
import com.google.greaze.webservice.server.ResponseSender;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* A dispatcher for all the procedural calls
*
* @author Inderjeet Singh
*/
public final class ProcedureDispatcher {
public void service(HttpServletRequest req, HttpServletResponse res) {
WebServiceCallSpec spec = SampleJsonService.PLACE_ORDER;
RequestSpec requestSpec = spec.getRequestSpec();
ResponseSpec responseSpec = spec.getResponseSpec();
Gson gson = new GsonBuilder()
.registerTypeAdapter(RequestBody.class,
new RequestBodyGsonConverter(requestSpec.getBodySpec()))
.registerTypeAdapter(ResponseBody.class,
new ResponseBodyGsonConverter(responseSpec.getBodySpec()))
.create();
RequestReceiver requestReceiver = new RequestReceiver(gson, requestSpec);
WebServiceRequest webServiceRequest = requestReceiver.receive(req);
Cart cart = webServiceRequest.getBody().get(TypedKeys.RequestBody.CART);
String authToken = webServiceRequest.getHeader(TypedKeys.Request.AUTH_TOKEN);
Order order = placeOrder(cart, authToken);
// Empty headers per the spec
HeaderMap responseHeaders = new HeaderMap.Builder(responseSpec.getHeadersSpec()).build();
ResponseBody responseBody = new ResponseBody.Builder(responseSpec.getBodySpec())
.put(TypedKeys.ResponseBody.ORDER, order)
.build();
WebServiceResponse response = new WebServiceResponse(responseHeaders, responseBody);
ResponseSender responseSender = new ResponseSender(gson);
responseSender.send(res, response);
}
private Order placeOrder(Cart cart, String authToken) {
// Create an order, in this case a dummy one.
return new Order(cart, "Order123");
}
}

View File

@ -1,105 +0,0 @@
/*
* 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.wsexample.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.greaze.definition.CallPath;
import com.google.greaze.definition.rest.IDFactory;
import com.google.greaze.definition.rest.MetaData;
import com.google.greaze.definition.rest.ResourceMap;
import com.google.greaze.definition.rest.RestCallSpec;
import com.google.greaze.definition.rest.RestRequest;
import com.google.greaze.definition.rest.RestResponse;
import com.google.greaze.definition.rest.ValueBasedId;
import com.google.greaze.example.definition.model.Cart;
import com.google.greaze.example.definition.model.Order;
import com.google.greaze.example.definition.service.ServicePaths;
import com.google.greaze.rest.server.Repository;
import com.google.greaze.rest.server.RepositoryInMemory;
import com.google.greaze.rest.server.ResponseBuilderMap;
import com.google.greaze.rest.server.RestRequestReceiver;
import com.google.greaze.rest.server.RestResponseBuilder;
import com.google.greaze.rest.server.RestResponseSender;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* A dispatcher for all the REST requests
*
* @author Inderjeet Singh
*/
public final class RestDispatcher {
private static final double CURRENT_VERSION = 1D;
private final ResourceMap resourceMap;
private final ResponseBuilderMap responseBuilders;
private final RestCallSpec cartSpec;
private final RestCallSpec orderSpec;
private final Gson gson;
public RestDispatcher() {
this.cartSpec = new RestCallSpec.Builder(ServicePaths.CART.getCallPath(), Cart.class)
.setVersion(CURRENT_VERSION)
.build();
this.orderSpec = new RestCallSpec.Builder(ServicePaths.CART.getCallPath(), Cart.class)
.setVersion(CURRENT_VERSION)
.build();
this.resourceMap = new ResourceMap.Builder()
.set(ServicePaths.CART.getCallPath(), cartSpec)
.set(ServicePaths.ORDER.getCallPath(), orderSpec)
.build();
gson = new GsonBuilder()
.setVersion(CURRENT_VERSION)
.registerTypeAdapter(ValueBasedId.class, new ValueBasedId.GsonTypeAdapter())
.registerTypeAdapter(MetaData.class, new MetaData.GsonTypeAdapter())
.create();
Repository<ValueBasedId<Cart>, Cart> carts =
new RepositoryInMemory<ValueBasedId<Cart>, Cart>(ValueBasedId.class, Cart.class);
Repository<ValueBasedId<Order>, Order> orders =
new RepositoryInMemory<ValueBasedId<Order>, Order>(ValueBasedId.class, Order.class);
responseBuilders = new ResponseBuilderMap.Builder()
.set(cartSpec.getResourceType(), new RestResponseBuilder<ValueBasedId<Cart>, Cart>(carts))
.set(orderSpec.getResourceType(), new RestResponseBuilder<ValueBasedId<Order>, Order>(orders))
.build();
}
public IDFactory<ValueBasedId<?>> getIDFactory(RestCallSpec callSpec) {
return new IDFactory<ValueBasedId<?>>(ValueBasedId.class, callSpec.getResourceType());
}
@SuppressWarnings({"rawtypes", "unchecked"})
public RestRequest getRestRequest(Gson gson, RestCallSpec callSpec, CallPath callPath,
HttpServletRequest request, IDFactory<ValueBasedId<?>> idFactory) {
RestRequestReceiver requestReceiver = new RestRequestReceiver(gson, callSpec.getRequestSpec());
return requestReceiver.receive(request, idFactory.createId(callPath.getResourceId()));
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void service(HttpServletRequest req, HttpServletResponse res, CallPath callPath) {
RestCallSpec callSpec = resourceMap.get(callPath).createCopy(callPath);
@SuppressWarnings("rawtypes")
RestRequestReceiver requestReceiver = new RestRequestReceiver(gson, callSpec.getRequestSpec());
IDFactory<ValueBasedId<?>> idFactory = getIDFactory(callSpec);
RestRequest<?, ?> restRequest = getRestRequest(gson, callSpec, callPath, req, idFactory);
RestResponse.Builder response = new RestResponse.Builder(callSpec.getResponseSpec());
RestResponseBuilder responseBuilder = responseBuilders.get(callSpec.getResourceType());
responseBuilder.buildResponse(callSpec, restRequest, response);
RestResponse restResponse = response.build();
RestResponseSender responseSender = new RestResponseSender(gson);
responseSender.send(res, restResponse);
}
}