moved contents of wexample/definition to greaze-example-definition

This commit is contained in:
Inderjeet Singh 2010-11-14 09:10:44 +00:00
parent debd3309b3
commit 5082dd4662
12 changed files with 16 additions and 572 deletions

View File

@ -21,13 +21,13 @@ import com.google.greaze.definition.webservice.RequestBody;
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.LineItem;
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.client.ServerConfig;
import com.google.greaze.webservice.client.WebServiceClient;
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 java.util.ArrayList;
import java.util.List;

View File

@ -16,16 +16,16 @@
import com.google.greaze.definition.CallPath;
import com.google.greaze.definition.rest.ValueBasedId;
import com.google.greaze.example.definition.model.Cart;
import com.google.greaze.example.definition.model.LineItem;
import com.google.greaze.example.definition.model.Order;
import com.google.greaze.example.definition.model.QueryOrdersByItemName;
import com.google.greaze.rest.client.ResourceDepotClient;
import com.google.greaze.rest.client.RestClientStub;
import com.google.greaze.rest.query.client.ResourceQueryClient;
import com.google.greaze.webservice.client.ServerConfig;
import com.google.greaze.webservice.client.WebServiceClient;
import com.google.gson.Gson;
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.QueryOrdersByItemName;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,217 +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>wsexampledef</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Gson Web Service Example</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/definition</connection>
<developerConnection>scm:svn:https://google-gson.googlecode.com/svn/trunk/wsexample/definition</developerConnection>
<url>http://google-gson.codegoogle.com/svn/trunk/wsexample/definition</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>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>wsexampledef</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/wsexampledef-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>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>

View File

@ -1,66 +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.example.model;
import com.google.greaze.definition.rest.RestResource;
import com.google.greaze.definition.rest.ValueBasedId;
import java.util.List;
/**
* A cart that can be posted to the server
*
* @author inder
*/
public class Cart implements RestResource<ValueBasedId<Cart>, Cart> {
private final List<LineItem> lineItems;
private final String buyerName;
private final String creditCard;
private ValueBasedId<Cart> id;
public Cart(List<LineItem> lineItems, String buyerName, String creditCard) {
this.lineItems = lineItems;
this.buyerName = buyerName;
this.creditCard = creditCard;
}
public List<LineItem> getLineItems() {
return lineItems;
}
public String getBuyerName() {
return buyerName;
}
public String getCreditCard() {
return creditCard;
}
@Override
public ValueBasedId<Cart> getId() {
return id;
}
@Override
public void setId(ValueBasedId<Cart> id) {
this.id = id;
}
@Override
public boolean hasId() {
return ValueBasedId.isValid(id);
}
}

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.example.model;
/**
* A line item in a cart
*
* @author inder
*/
public class LineItem {
private final String name;
private final int quantity;
private final long priceInMicros;
private final String currencyCode;
public LineItem(String name, int quantity, long priceInMicros, String currencyCode) {
this.name = name;
this.quantity = quantity;
this.priceInMicros = priceInMicros;
this.currencyCode = currencyCode;
}
public String getName() {
return name;
}
public int getQuantity() {
return quantity;
}
public long getPriceInMicros() {
return priceInMicros;
}
public String getCurrencyCode() {
return currencyCode;
}
}

View File

@ -1,58 +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.example.model;
import com.google.greaze.definition.rest.RestResource;
import com.google.greaze.definition.rest.ValueBasedId;
/**
* An order
*
* @author inder
*/
public class Order implements RestResource<ValueBasedId<Order>, Order> {
public final Cart postedCart;
public final String orderNumber;
private ValueBasedId<Order> id;
public Order(Cart postedCart, String orderNumber) {
this.postedCart = postedCart;
this.orderNumber = orderNumber;
}
public Cart getPostedCart() {
return postedCart;
}
public String getOrderNumber() {
return orderNumber;
}
@Override
public ValueBasedId<Order> getId() {
return id;
}
@Override
public void setId(ValueBasedId<Order> id) {
this.id = id;
}
@Override
public boolean hasId() {
return ValueBasedId.isValid(id);
}
}

View File

@ -1,37 +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.example.model;
/**
* A query for orders by item name
*
* @author Inderjeet Singh
*/
public class QueryOrdersByItemName {
private final String itemName;
public QueryOrdersByItemName() {
this(null);
}
public QueryOrdersByItemName(String itemName) {
this.itemName = itemName;
}
public String getItemName() {
return itemName;
}
}

View File

@ -1,39 +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.example.model;
import com.google.greaze.definition.TypedKey;
/**
* Definition of various constants to be used for parameter names of request and response headers,
* and request and response body.
*
* @author inder
*/
public final class TypedKeys {
public static final class Request {
public static final TypedKey<String> AUTH_TOKEN =
new TypedKey<String>("authToken", String.class);
}
public static final class RequestBody {
public static final TypedKey<Cart> CART = new TypedKey<Cart>("cart", Cart.class);
}
public static final class ResponseBody {
public static final TypedKey<Order> ORDER = new TypedKey<Order>("order", Order.class);
}
}

View File

@ -1,36 +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.example.service;
import com.google.greaze.definition.CallPath;
import com.google.greaze.definition.HttpMethod;
import com.google.greaze.definition.webservice.WebServiceCallSpec;
import com.google.gson.example.model.TypedKeys;
/**
* An example of a web-service definition
*
* @author inder
*/
public class SampleJsonService {
public static final WebServiceCallSpec PLACE_ORDER = new WebServiceCallSpec.Builder(
new CallPath("/placeOrder"))
.supportsHttpMethod(HttpMethod.POST)
.addRequestParam(TypedKeys.Request.AUTH_TOKEN)
.addRequestBodyParam(TypedKeys.RequestBody.CART)
.addResponseBodyParam(TypedKeys.ResponseBody.ORDER)
.build();
}

View File

@ -1,52 +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.example.service;
import com.google.greaze.definition.CallPath;
/**
* An enum describing all paths for this service
*
* @author Inderjeet Singh
*/
public enum ServicePaths {
NULL_REQUEST(null),
CART("/rest/cart"),
ORDER("/rest/order");
private final CallPath path;
private ServicePaths(String pathInfo) {
this.path = new CallPath(pathInfo);
}
public CallPath getCallPath() {
return path;
}
public static CallPath getCallPath(CallPath invokedPath) {
for (ServicePaths path : values()) {
CallPath callPath = path.path;
String callPathInfo = callPath.get();
// A rest path can end with a resource-id too.
// For example, /rest/cart/1234 should match with /rest/cart
if (callPathInfo != null && invokedPath.matches(callPath)) {
return callPath;
}
}
return null;
}
}

View File

@ -28,14 +28,14 @@ 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;
import com.google.gson.example.model.Cart;
import com.google.gson.example.model.Order;
import com.google.gson.example.model.TypedKeys;
import com.google.gson.example.service.SampleJsonService;
/**
* A dispatcher for all the procedural calls

View File

@ -26,6 +26,9 @@ 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;
@ -34,9 +37,6 @@ import com.google.greaze.rest.server.RestResponseBuilder;
import com.google.greaze.rest.server.RestResponseSender;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.example.model.Cart;
import com.google.gson.example.model.Order;
import com.google.gson.example.service.ServicePaths;
/**
* A dispatcher for all the REST requests