moved contents of wsdef to greaze-definition.
This commit is contained in:
parent
7d055fcb51
commit
822d1bc75e
@ -56,9 +56,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<groupId>com.google.code.greaze</groupId>
|
||||
<artifactId>greaze-definition</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -17,16 +17,16 @@ package com.google.gson.rest.client;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.greaze.definition.CallPath;
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.ResourceDepot;
|
||||
import com.google.greaze.definition.rest.RestCallSpec;
|
||||
import com.google.greaze.definition.rest.RestRequest;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.RestResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.ResourceDepot;
|
||||
import com.google.gson.rest.definition.RestCallSpec;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
|
||||
/**
|
||||
* A client class to access a rest resource
|
||||
|
@ -15,15 +15,15 @@
|
||||
*/
|
||||
package com.google.gson.rest.client;
|
||||
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestCallSpec;
|
||||
import com.google.greaze.definition.rest.RestRequest;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.RestResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestCallSpec;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.webservice.client.ServerConfig;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -22,14 +22,14 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestRequest;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.wsclient.internal.utils.Streams;
|
||||
|
||||
/**
|
||||
|
@ -25,15 +25,15 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.greaze.definition.ContentBodySpec;
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.RestResponse;
|
||||
import com.google.greaze.definition.rest.RestResponseSpec;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.rest.definition.RestResponseSpec;
|
||||
import com.google.gson.webservice.definition.ContentBodySpec;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.wsclient.internal.utils.ConnectionPreconditions;
|
||||
|
||||
/**
|
||||
|
@ -17,20 +17,20 @@ package com.google.gson.rest.query.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.greaze.definition.CallPath;
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.query.ResourceQuery;
|
||||
import com.google.greaze.definition.rest.query.TypedKeysQuery;
|
||||
import com.google.greaze.definition.webservice.RequestBody;
|
||||
import com.google.greaze.definition.webservice.ResponseBody;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.query.ResourceQuery;
|
||||
import com.google.gson.rest.query.TypedKeysQuery;
|
||||
import com.google.gson.webservice.client.WebServiceClient;
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBody;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBody;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
|
||||
/**
|
||||
* A client to invoke {@link ResourceQuery}s associated with a REST resource
|
||||
|
@ -17,9 +17,9 @@ package com.google.gson.webservice.client;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCall;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.WebServiceCall;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
|
||||
/**
|
||||
* A consumer that executes in its own thread consuming queue entries and invoking web-service calls
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.webservice.client;
|
||||
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
|
||||
/**
|
||||
* A holder class for an entry stored in queue. It contains references to the request, callspec,
|
||||
|
@ -22,12 +22,12 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.RequestBody;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBody;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.wsclient.internal.utils.Streams;
|
||||
|
||||
/**
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.google.gson.webservice.client;
|
||||
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCall;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.WebServiceCall;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
|
||||
/**
|
||||
* A client-supplied callback to be used with {@link WebServiceClientAsync}. When a web-service
|
||||
|
@ -25,14 +25,14 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.ResponseBody;
|
||||
import com.google.greaze.definition.webservice.ResponseBodySpec;
|
||||
import com.google.greaze.definition.webservice.ResponseSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBody;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBodySpec;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
import com.google.gson.wsclient.internal.utils.ConnectionPreconditions;
|
||||
|
||||
/**
|
||||
|
@ -22,14 +22,14 @@ import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.ResponseBody;
|
||||
import com.google.greaze.definition.webservice.ResponseBodyGsonConverter;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBody;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBodyGsonConverter;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
|
||||
/**
|
||||
* Main class used by clients to access a Gson Web service.
|
||||
|
@ -19,9 +19,9 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
|
||||
/**
|
||||
* A client for invoking a JSON-based Web-service in an asynchronous manner. The call is queued,
|
||||
|
@ -1,29 +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.rest.definition;
|
||||
|
||||
/**
|
||||
* An interface to indicate that an object has an Id
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <R> type of object
|
||||
*/
|
||||
public interface HasId<I extends ID> {
|
||||
public I getId();
|
||||
public void setId(I id);
|
||||
public boolean hasId();
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.google.gson.rest.definition;
|
||||
|
||||
public interface ID {
|
||||
public static final long INVALID_ID = -1L;
|
||||
|
||||
public long getValue();
|
||||
}
|
@ -1,43 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* A factory to create {@link ValueBasedId)s
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <I>
|
||||
*/
|
||||
public class IDFactory<I extends ID> {
|
||||
private final Class<? super I> classOfI;
|
||||
private final Type typeOfId;
|
||||
|
||||
public IDFactory(Class<? super I> classOfI, Type typeOfId) {
|
||||
this.classOfI = classOfI;
|
||||
this.typeOfId = typeOfId;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public I createId(long value) {
|
||||
if (classOfI.isAssignableFrom(ValueBasedId.class)) {
|
||||
return (I)ValueBasedId.get(value, typeOfId);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -1,124 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Metadata associated with a repository for a rest resource. Metadata is of two types: persistent
|
||||
* and transient. All metadata is persistent by default, and must be a name-value pair of strings.
|
||||
* Transient metadata can be an arbitrary key-value pair of objects and is available through
|
||||
* {@link #getFromTransient(Object)}, {@link #putInTransient(Object, Object)},
|
||||
* and {@link #removeFromTransient(Object)} methods.
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <R> The resource
|
||||
*/
|
||||
public final class MetaData<I extends ID, R extends RestResource<I, R>> {
|
||||
|
||||
private final Map<String, String> map;
|
||||
private final transient Map<Object, Object> mapTransient;
|
||||
|
||||
public static <II extends ID, RS extends RestResource<II, RS>> MetaData<II, RS> create() {
|
||||
return new MetaData<II, RS>();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static MetaData<?, ?> createTypeUnsafe(Map<String, String> values) {
|
||||
return new MetaData(values);
|
||||
}
|
||||
|
||||
public MetaData() {
|
||||
this(new HashMap<String, String>());
|
||||
}
|
||||
|
||||
private MetaData(Map<String, String> values) {
|
||||
this.map = values == null ? new HashMap<String, String>() : values;
|
||||
this.mapTransient = new HashMap<Object, Object>();
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public void putString(String key, String value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
String value = map.get(key);
|
||||
return value == null ? false : Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
public void putBoolean(String key, boolean value) {
|
||||
map.put(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
public Object getFromTransient(Object key) {
|
||||
return mapTransient.get(key);
|
||||
}
|
||||
|
||||
public void putInTransient(Object key, Object value) {
|
||||
mapTransient.put(key, value);
|
||||
}
|
||||
|
||||
public void removeFromTransient(Object key) {
|
||||
mapTransient.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder().append(map).append(',').append(mapTransient).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gson Type adapter for {@link MetaData}. The serialized representation on wire is just a
|
||||
* Map<String, String>
|
||||
*/
|
||||
public static final class GsonTypeAdapter implements JsonSerializer<MetaData<?, ?>>,
|
||||
JsonDeserializer<MetaData<?, ?>>{
|
||||
|
||||
private static final Type MAP_TYPE = new TypeToken<Map<String, String>>(){}.getType();
|
||||
|
||||
@Override
|
||||
public MetaData<?, ?> deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
Map<String, String> map = context.deserialize(json, MAP_TYPE);
|
||||
return MetaData.createTypeUnsafe(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(MetaData<?, ?> src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return context.serialize(src.map, MAP_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +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.rest.definition;
|
||||
|
||||
public interface ResourceDepot<I extends ID, R extends RestResource<I, R>> {
|
||||
|
||||
public R get(I resourceId);
|
||||
|
||||
public R post(R resource);
|
||||
|
||||
public R put(R resource);
|
||||
|
||||
public void delete(I resourceId);
|
||||
}
|
@ -1,55 +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.rest.definition;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A {@link Map} of {@link CallPath} to {@link RestCallSpec}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class ResourceMap {
|
||||
|
||||
public static final class Builder {
|
||||
private final Map<CallPath, RestCallSpec> resources =
|
||||
new HashMap<CallPath, RestCallSpec>();
|
||||
|
||||
public Builder set(CallPath baseCallPath, RestCallSpec spec) {
|
||||
Preconditions.checkArgument(resources.get(baseCallPath) == null);
|
||||
resources.put(baseCallPath, spec);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceMap build() {
|
||||
return new ResourceMap(resources);
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<CallPath, RestCallSpec> resources;
|
||||
|
||||
public ResourceMap(Map<CallPath, RestCallSpec> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public RestCallSpec get(CallPath callPath) {
|
||||
return resources.get(callPath);
|
||||
}
|
||||
}
|
@ -1,47 +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.rest.definition;
|
||||
|
||||
/**
|
||||
* The data associated with a Rest Web service call. This includes http request header parameters
|
||||
* (form and URL parameters), request body, response header parameters, and resource response body.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestCall<I extends ID, R extends RestResource<I, R>> {
|
||||
|
||||
private final RestCallSpec callSpec;
|
||||
private final RestRequest<I, R> request;
|
||||
private final RestResponse<I, R> response;
|
||||
|
||||
public RestCall(RestCallSpec callSpec, RestRequest<I, R> request, RestResponse<I, R> response) {
|
||||
this.callSpec = callSpec;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public RestCallSpec getSpec() {
|
||||
return callSpec;
|
||||
}
|
||||
|
||||
public RestRequest<I, R> getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public RestResponse<I, R> getResponse() {
|
||||
return response;
|
||||
}
|
||||
}
|
@ -1,138 +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.rest.definition;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Specification for a REST service
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestCallSpec {
|
||||
public static class Builder {
|
||||
private final CallPath callPath;
|
||||
private final Set<HttpMethod> supportedHttpMethods = new LinkedHashSet<HttpMethod>();
|
||||
private final HeaderMapSpec.Builder reqParamsSpecBuilder = new HeaderMapSpec.Builder();
|
||||
private final HeaderMapSpec.Builder resParamsSpecBuilder = new HeaderMapSpec.Builder();
|
||||
private final Type resourceType;
|
||||
private double version;
|
||||
|
||||
public Builder(CallPath callPath, Type resourceType) {
|
||||
this.callPath = callPath;
|
||||
supportedHttpMethods.addAll(HttpMethod.ALL_METHODS);
|
||||
this.resourceType = resourceType;
|
||||
this.version = -1D;
|
||||
}
|
||||
|
||||
public Builder disableHttpMethod(HttpMethod httpMethod) {
|
||||
supportedHttpMethods.remove(httpMethod);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setVersion(double version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addRequestParam(TypedKey<T> param) {
|
||||
reqParamsSpecBuilder.put(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addResponseParam(TypedKey<T> param) {
|
||||
resParamsSpecBuilder.put(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public RestCallSpec build() {
|
||||
if (supportedHttpMethods.isEmpty()) {
|
||||
supportedHttpMethods.addAll(Arrays.asList(HttpMethod.values()));
|
||||
}
|
||||
RestRequestSpec requestSpec =
|
||||
new RestRequestSpec(reqParamsSpecBuilder.build(), resourceType);
|
||||
RestResponseSpec responseSpec =
|
||||
new RestResponseSpec(resParamsSpecBuilder.build(), resourceType);
|
||||
return new RestCallSpec(supportedHttpMethods, callPath,
|
||||
requestSpec, responseSpec, resourceType, version);
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<HttpMethod> supportedHttpMethods;
|
||||
private final CallPath path;
|
||||
private final RestRequestSpec requestSpec;
|
||||
private final RestResponseSpec responseSpec;
|
||||
private final Type resourceType;
|
||||
private final double version;
|
||||
|
||||
private RestCallSpec(Set<HttpMethod> supportedHttpMethods, CallPath path,
|
||||
RestRequestSpec requestSpec, RestResponseSpec responseSpec,
|
||||
Type resourceType, double version) {
|
||||
Preconditions.checkArgument(!supportedHttpMethods.isEmpty());
|
||||
Preconditions.checkNotNull(path);
|
||||
this.supportedHttpMethods = supportedHttpMethods;
|
||||
this.path = path;
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
this.resourceType = resourceType;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public CallPath getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public Set<HttpMethod> getSupportedHttpMethods() {
|
||||
return supportedHttpMethods;
|
||||
}
|
||||
|
||||
public RestResponseSpec getResponseSpec() {
|
||||
return responseSpec;
|
||||
}
|
||||
|
||||
public RestRequestSpec getRequestSpec() {
|
||||
return requestSpec;
|
||||
}
|
||||
|
||||
public Type getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public double getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"path: %s, version: %.2f, resourceType: %s, requestSpec: %s, responseSpec: %s",
|
||||
path, version, resourceType, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
public RestCallSpec createCopy(CallPath callPath) {
|
||||
return new RestCallSpec(supportedHttpMethods, callPath, requestSpec,
|
||||
responseSpec, resourceType, version);
|
||||
}
|
||||
}
|
@ -1,89 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
/**
|
||||
* The data associated with a Web service request. This includes HTTP request header parameters
|
||||
* (form and URL parameters), and request body.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestRequest<I extends ID, R extends RestResource<I, R>> {
|
||||
public static final String JSON_CONTENT_TYPE = "application/json";
|
||||
|
||||
private final HttpMethod method;
|
||||
private final HeaderMap headers;
|
||||
private final I id;
|
||||
private final R body;
|
||||
private final RestRequestSpec spec;
|
||||
|
||||
public RestRequest(HttpMethod method, HeaderMap requestHeaders,
|
||||
I resourceId, R requestBody, Type resourceType) {
|
||||
this.method = method;
|
||||
this.id = resourceId;
|
||||
this.body = requestBody;
|
||||
this.headers = requestHeaders;
|
||||
this.spec = new RestRequestSpec(requestHeaders.getSpec(), resourceType);
|
||||
}
|
||||
|
||||
public I getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public RestRequestSpec getSpec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
public HttpMethod getHttpMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public R getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public HeaderMap getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return JSON_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
public <T> T getHeader(TypedKey<T> key) {
|
||||
return headers.get(key);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getHeader(String headerName) {
|
||||
return (T) headers.get(headerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{method:%s,headers:%s,body:%s}", method, headers, body);
|
||||
}
|
||||
}
|
@ -1,48 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
|
||||
/**
|
||||
* Specification for a {@link RestRequest}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestRequestSpec {
|
||||
private final HeaderMapSpec headersSpec;
|
||||
private final Type resourceType;
|
||||
|
||||
public RestRequestSpec(HeaderMapSpec headersSpec, Type resourceClass) {
|
||||
this.headersSpec = headersSpec;
|
||||
this.resourceType = resourceClass;
|
||||
}
|
||||
|
||||
public Type getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public HeaderMapSpec getHeadersSpec() {
|
||||
return headersSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{headersSpec:%s,resourceType:%s}", headersSpec, resourceType);
|
||||
}
|
||||
}
|
@ -1,26 +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.rest.definition;
|
||||
|
||||
/**
|
||||
* An interface implemented by an object that is intended to be a rest resource
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <R> the rest resource type
|
||||
*/
|
||||
public interface RestResource<I extends ID, R> extends HasId<I> {
|
||||
}
|
@ -1,93 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
/**
|
||||
* The data associated with a REST Web service response. This includes http response header
|
||||
* parameters, and the response body.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestResponse<I extends ID, R extends RestResource<I, R>> {
|
||||
|
||||
private final HeaderMap headers;
|
||||
private final R body;
|
||||
private final RestResponseSpec spec;
|
||||
|
||||
public static class Builder<II extends ID, RS extends RestResource<II, RS>> {
|
||||
private final HeaderMap.Builder headers;
|
||||
private RS body;
|
||||
private final RestResponseSpec spec;
|
||||
|
||||
public Builder(RestResponseSpec spec) {
|
||||
this.spec = spec;
|
||||
headers = new HeaderMap.Builder(spec.getHeadersSpec());
|
||||
}
|
||||
|
||||
public <T> Builder<II, RS> putHeader(TypedKey<T> paramName, T content) {
|
||||
headers.put(paramName.getName(), content, paramName.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<II, RS> setBody(RS body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RestResponse<II, RS> build() {
|
||||
return new RestResponse<II, RS>(spec, headers.build(), body);
|
||||
}
|
||||
}
|
||||
|
||||
private RestResponse(RestResponseSpec spec, HeaderMap headers, R body) {
|
||||
this.spec = spec;
|
||||
this.headers = headers;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public RestResponse(HeaderMap responseHeaders, R responseBody, Type responseBodyType) {
|
||||
this.spec = new RestResponseSpec(responseHeaders.getSpec(), responseBodyType);
|
||||
this.headers = responseHeaders;
|
||||
this.body = responseBody;
|
||||
}
|
||||
|
||||
public RestResponseSpec getSpec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
public HeaderMap getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public R getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getHeader(String headerName) {
|
||||
return (T) headers.get(headerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{headers:%s, body:%s}", headers, body);
|
||||
}
|
||||
}
|
@ -1,48 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
|
||||
/**
|
||||
* Specification for a {@link RestResponse}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RestResponseSpec {
|
||||
private final HeaderMapSpec headersSpec;
|
||||
private final Type resourceType;
|
||||
|
||||
public RestResponseSpec(HeaderMapSpec headersSpec, Type resourceType) {
|
||||
this.headersSpec = headersSpec;
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public Type getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public HeaderMapSpec getHeadersSpec() {
|
||||
return headersSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{headersSpec:%s,resourceType:%s}", headersSpec, resourceType);
|
||||
}
|
||||
}
|
@ -1,203 +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.rest.definition;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.WildcardType;
|
||||
|
||||
/**
|
||||
* An id for a rest resource
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <R> type variable for the rest resource
|
||||
*/
|
||||
public final class ValueBasedId<R> implements ID {
|
||||
private final long value;
|
||||
private final Type typeOfId;
|
||||
|
||||
private ValueBasedId(long value, Type typeOfId) {
|
||||
this.value = value;
|
||||
this.typeOfId = typeOfId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long getValue(ValueBasedId<?> id) {
|
||||
return id == null ? INVALID_ID : id.getValue();
|
||||
}
|
||||
|
||||
public String getValueAsString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
public Type getTypeOfId() {
|
||||
return typeOfId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
public static boolean isValid(ValueBasedId<?> id) {
|
||||
return id != null && id.value != INVALID_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more efficient comparison method for ids that take into account of ids being nullable.
|
||||
* Since the method is parameterized and both ids are of the same type, this method compares
|
||||
* only id values, not their types. Note that this shortcut doesn't work if you pass raw ids
|
||||
* to this method
|
||||
*/
|
||||
public static <T> boolean equals(/* @Nullable */ ValueBasedId<T> id1,
|
||||
/* @Nullable */ ValueBasedId<T> id2) {
|
||||
if ((id1 == null && id2 != null) || (id1 != null && id2 == null)) {
|
||||
return false;
|
||||
}
|
||||
if (id1 == null && id2 == null) {
|
||||
return true;
|
||||
}
|
||||
return id1.value == id2.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
@SuppressWarnings("unchecked")
|
||||
ValueBasedId<R> other = (ValueBasedId<R>)obj;
|
||||
if (typeOfId == null) {
|
||||
if (other.typeOfId != null) return false;
|
||||
} else if (!equivalentTypes(typeOfId, other.typeOfId)) return false;
|
||||
if (value != other.value) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true for equivalentTypes(Class<?>, Class)
|
||||
* Visible for testing only
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
static boolean equivalentTypes(Type type1, Type type2) {
|
||||
if (type1 instanceof ParameterizedType && type2 instanceof Class) {
|
||||
return areEquivalentTypes((ParameterizedType)type1, (Class)type2);
|
||||
} else if (type2 instanceof ParameterizedType && type1 instanceof Class) {
|
||||
return areEquivalentTypes((ParameterizedType)type2, (Class)type1);
|
||||
}
|
||||
return type1.equals(type2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible for testing only
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
static boolean areEquivalentTypes(ParameterizedType type, Class clazz) {
|
||||
Class rawClass = (Class) type.getRawType();
|
||||
if (!clazz.equals(rawClass)) {
|
||||
return false;
|
||||
}
|
||||
for (Type typeVariable : type.getActualTypeArguments()) {
|
||||
if (typeVariable instanceof WildcardType) {
|
||||
continue;
|
||||
}
|
||||
// This is a real parameterized type, not just ?
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <RS> ValueBasedId<RS> get(long value, Type typeOfId) {
|
||||
return new ValueBasedId<RS>(value, typeOfId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String typeAsString = getSimpleTypeName(typeOfId);
|
||||
return String.format("{value:%s,type:%s}", value, typeAsString);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static String getSimpleTypeName(Type type) {
|
||||
if (type == null) {
|
||||
return "null";
|
||||
}
|
||||
if (type instanceof Class) {
|
||||
return ((Class)type).getSimpleName();
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
StringBuilder sb = new StringBuilder(getSimpleTypeName(pType.getRawType()));
|
||||
sb.append('<');
|
||||
boolean first = true;
|
||||
for (Type argumentType : pType.getActualTypeArguments()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append(getSimpleTypeName(argumentType));
|
||||
}
|
||||
sb.append('>');
|
||||
return sb.toString();
|
||||
} else if (type instanceof WildcardType) {
|
||||
return "?";
|
||||
}
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type adapter for converting an Id to its serialized form
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
*/
|
||||
public static final class GsonTypeAdapter implements JsonSerializer<ValueBasedId<?>>,
|
||||
JsonDeserializer<ValueBasedId<?>> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ValueBasedId<?> src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueBasedId<?> deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
if (!(typeOfT instanceof ParameterizedType)) {
|
||||
throw new JsonParseException("Id of unknown type: " + typeOfT);
|
||||
}
|
||||
ParameterizedType parameterizedType = (ParameterizedType) typeOfT;
|
||||
// Since Id takes only one TypeVariable, the actual type corresponding to the first
|
||||
// TypeVariable is the Type we are looking for
|
||||
Type typeOfId = parameterizedType.getActualTypeArguments()[0];
|
||||
return ValueBasedId.get(json.getAsLong(), typeOfId);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +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.rest.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
|
||||
/**
|
||||
* A query for a list of rest resources.
|
||||
*
|
||||
* @author Inderjeet Singh
|
||||
*/
|
||||
public interface ResourceQuery<I extends ID, R extends RestResource<I, R>, QUERY> {
|
||||
/**
|
||||
* Returns a list of resources matching the query
|
||||
*/
|
||||
public List<R> query(QUERY query);
|
||||
}
|
@ -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.rest.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
/**
|
||||
* List of {@link TypedKey}s associated with REST queries
|
||||
*
|
||||
* @author Inderjeet Singh
|
||||
*
|
||||
* @param <I> ID type of the REST resource
|
||||
* @param <R> The type of the REST resource
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class TypedKeysQuery<I extends ID, R extends RestResource<I, R>> {
|
||||
|
||||
// TODO(inder): This should really be TypedKey<List<R>>
|
||||
public static TypedKey<List> RESOURCE_LIST = new TypedKey<List>("resourceList", List.class);
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.webservice.definition.internal.utils.Pair;
|
||||
|
||||
/**
|
||||
* Encapsulation of a Web service path that is sent by the client.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class CallPath {
|
||||
|
||||
/** Visible for testing only */
|
||||
static final double IGNORE_VERSION = -1D;
|
||||
private final String path;
|
||||
private final double version;
|
||||
private final long resourceId;
|
||||
|
||||
public CallPath(String path) {
|
||||
if (path == null || path.trim().equals("")) {
|
||||
this.path = path;
|
||||
version = IGNORE_VERSION;
|
||||
resourceId = ID.INVALID_ID;
|
||||
} else {
|
||||
Pair<Double, String> path2 = extractVersion(path);
|
||||
this.version = path2.first;
|
||||
Pair<Long, String> path3 = extractId(path2.second);
|
||||
this.resourceId = path3.first;
|
||||
this.path = path3.second;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path after consuming version number from the begining
|
||||
*/
|
||||
private static Pair<Double, String> extractVersion(String path) {
|
||||
int index1 = path.indexOf('/');
|
||||
int index2 = path.substring(index1+1).indexOf('/');
|
||||
String versionStr = path.substring(index1+1, index2+1);
|
||||
double extractedVersion = -1.0D;
|
||||
String revisedPath = path;
|
||||
try {
|
||||
// Skip over the version number from the URL
|
||||
extractedVersion = Double.parseDouble(versionStr);
|
||||
revisedPath = path.substring(index2+1);
|
||||
} catch (NumberFormatException e) {
|
||||
// Assume that version number wasn't specified
|
||||
}
|
||||
return Pair.create(extractedVersion, revisedPath);
|
||||
}
|
||||
|
||||
private static Pair<Long, String> extractId(String path) {
|
||||
Pair<Long, String> originalPath = Pair.create(ID.INVALID_ID, path);
|
||||
int end = path.endsWith("/") ? path.length() - 1 : path.length();
|
||||
int begin = path.substring(0, end-1).lastIndexOf('/') + 1;
|
||||
if (begin < 0 || end < 0 || begin >= end) {
|
||||
return originalPath;
|
||||
}
|
||||
try {
|
||||
String id = path.substring(begin, end);
|
||||
String pathWithoutId = path.substring(0, begin-1);
|
||||
return Pair.create(Long.parseLong(id), pathWithoutId);
|
||||
} catch (NumberFormatException e) {
|
||||
return originalPath;
|
||||
}
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public double getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public long getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return path.hashCode();
|
||||
}
|
||||
|
||||
public boolean matches(CallPath callPath) {
|
||||
return path.startsWith(callPath.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
return getClass() == obj.getClass() && equal(path, ((CallPath)obj).path);
|
||||
}
|
||||
|
||||
private static boolean equal(String s1, String s2) {
|
||||
return s1 == s2 || (s1 != null && s2 != null && s1.equals(s2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("path:%s, version:%2.f, resourceId: %d", path, version, resourceId);
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A generic Map of calls with relative path where the call is available as the key.
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <T> The target of the call path.
|
||||
*/
|
||||
public final class CallPathMap<T> {
|
||||
|
||||
public static class Builder<T> {
|
||||
private final Map<CallPath, T> contents = new HashMap<CallPath, T>();
|
||||
private final T nullValue;
|
||||
|
||||
public Builder(T nullValue) {
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
public <R extends T> Builder<T> put(CallPath path, R content) {
|
||||
contents.put(path, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CallPathMap<T> build() {
|
||||
return new CallPathMap<T>(contents, nullValue);
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<CallPath, T> contents;
|
||||
private final T nullValue;
|
||||
|
||||
private CallPathMap(Map<CallPath, T> contents, T nullValue) {
|
||||
this.contents = contents;
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
||||
public T get(CallPath path) {
|
||||
T content = contents.get(path);
|
||||
return content == null ? nullValue : content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
boolean first = true;
|
||||
for (Map.Entry<CallPath, T> entry : contents.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
CallPath path = entry.getKey();
|
||||
sb.append(path.get()).append(":");
|
||||
sb.append(entry.getValue().toString());
|
||||
}
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Body of a request or response. The body contains a map of name-value pairs.
|
||||
* There is a {@link ContentBodySpec} associated with the body as well and only the name-value
|
||||
* pairs consistent with the specification are permitted.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class ContentBody extends ParamMap {
|
||||
|
||||
public ContentBody(ContentBodySpec spec, Map<String, Object> contents) {
|
||||
super(spec, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentBodySpec getSpec() {
|
||||
return (ContentBodySpec) spec;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return getSpec().getContentType();
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return getSpec().getCharacterEncoding();
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Base class for the specification of a {@link ContentBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class ContentBodySpec implements ParamMapSpec {
|
||||
|
||||
public static final String JSON_CONTENT_TYPE = "application/json";
|
||||
public static final String JSON_CHARACTER_ENCODING = "utf-8";
|
||||
|
||||
private final Map<String, Type> paramsSpec;
|
||||
|
||||
protected ContentBodySpec(Map<String, Type> paramsSpec) {
|
||||
this.paramsSpec = Collections.unmodifiableMap(paramsSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getTypeFor(String paramName) {
|
||||
return paramsSpec.get(paramName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfCompatible(String paramName, Type type) {
|
||||
return type.equals(getTypeFor(paramName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfCompatible(String paramName, Object object) {
|
||||
return checkIfCompatible(paramName, object.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<String, Type>> entrySet() {
|
||||
return paramsSpec.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return paramsSpec.size();
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return JSON_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return JSON_CHARACTER_ENCODING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Util.toStringMapKeys(paramsSpec);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Map of request or response header objects. There is a {@link HeaderMapSpec} associated with the
|
||||
* map as well and only those headers are allowed that are consistent with the specification.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class HeaderMap extends ParamMap {
|
||||
|
||||
public static class Builder extends ParamMap.Builder<HeaderMapSpec> {
|
||||
public Builder(HeaderMapSpec spec) {
|
||||
super(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Builder put(TypedKey<T> paramKey, T content) {
|
||||
return put(paramKey.getName(), content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content) {
|
||||
return (Builder) super.put(paramName, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content, Type typeOfContent) {
|
||||
return (Builder) super.put(paramName, content, typeOfContent);
|
||||
}
|
||||
|
||||
public HeaderMap build() {
|
||||
return new HeaderMap(spec, contents);
|
||||
}
|
||||
}
|
||||
|
||||
private HeaderMap(HeaderMapSpec spec, Map<String, Object> contents) {
|
||||
super(spec, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeaderMapSpec getSpec() {
|
||||
return (HeaderMapSpec) super.getSpec();
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Specification of a header map for {@link HeaderMap}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class HeaderMapSpec implements ParamMapSpec {
|
||||
|
||||
public static class Builder {
|
||||
private final Map<String, Type> map = new LinkedHashMap<String, Type>();
|
||||
|
||||
public void put(String headerName, Type headerType) {
|
||||
map.put(headerName, headerType);
|
||||
}
|
||||
|
||||
public HeaderMapSpec build() {
|
||||
return new HeaderMapSpec(map);
|
||||
}
|
||||
}
|
||||
private final Map<String, Type> map;
|
||||
|
||||
private HeaderMapSpec(Map<String, Type> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getTypeFor(String headerName) {
|
||||
return map.get(headerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<String, Type>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfCompatible(String headerName, Type targetType) {
|
||||
Type typeOfHeader = getTypeFor(headerName);
|
||||
if (typeOfHeader == null) {
|
||||
return false;
|
||||
}
|
||||
Class<?> rawClassOfHeader = TypeUtils.toRawClass(typeOfHeader);
|
||||
Class<?> rawClassOfTargetType = TypeUtils.toRawClass(targetType);
|
||||
return rawClassOfHeader.isAssignableFrom(rawClassOfTargetType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfCompatible(String headerName, Object headerValue) {
|
||||
return checkIfCompatible(headerName, headerValue.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Util.toStringMapKeys(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An enum of Http methods to provide strongly-typed versions instead of strings.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public enum HttpMethod {
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
DELETE;
|
||||
|
||||
public static HttpMethod getMethod(String method) {
|
||||
return valueOf(method.trim().toUpperCase());
|
||||
}
|
||||
|
||||
public static final List<HttpMethod> ALL_METHODS =
|
||||
Collections.unmodifiableList(Arrays.asList(values()));
|
||||
|
||||
/**
|
||||
* This header is used to indicate the real method that is channeled through the current
|
||||
* request. For example, you can use it to send PUT requests under a POST.
|
||||
*/
|
||||
public static final String SIMULATED_METHOD_HEADER = "SimulatedMethod";
|
||||
}
|
@ -1,98 +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.webservice.definition;
|
||||
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ParamMap {
|
||||
|
||||
public static class Builder<T extends ParamMapSpec> {
|
||||
protected final Map<String, Object> contents = new LinkedHashMap<String, Object>();
|
||||
protected final T spec;
|
||||
|
||||
public Builder(T spec) {
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
/**
|
||||
* If value is a generic type, use {@link #put(String, Object, Type)} instead.
|
||||
*/
|
||||
public Builder<T> put(String paramName, Object content) {
|
||||
return put(paramName, content, content.getClass());
|
||||
}
|
||||
|
||||
public Builder<T> put(String paramName, Object content, Type typeOfContent) {
|
||||
Preconditions.checkArgument(spec.checkIfCompatible(paramName, typeOfContent));
|
||||
contents.put(paramName, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <K> Builder<T> put(TypedKey<K> paramKey, K param) {
|
||||
contents.put(paramKey.getName(), param);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected final Map<String, Object> contents;
|
||||
protected final ParamMapSpec spec;
|
||||
|
||||
protected ParamMap(ParamMapSpec spec, Map<String, Object> contents) {
|
||||
this.spec = spec;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public ParamMapSpec getSpec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
public Object get(String paramName) {
|
||||
return contents.get(paramName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(TypedKey<T> key) {
|
||||
return (T) get(key.getName(), key.getClassOfT());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(String key, Type typeOfValue) {
|
||||
Preconditions.checkArgument(spec.checkIfCompatible(key, typeOfValue),
|
||||
"Incompatible key %s for type %s", key, typeOfValue);
|
||||
return (T) contents.get(key);
|
||||
}
|
||||
|
||||
public Type getSpec(String headerName) {
|
||||
return spec.getTypeFor(headerName);
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, Object>> entrySet() {
|
||||
return contents.entrySet();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return contents.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Util.toStringMap(contents);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Specification of a parameter map. Both {@link ContentBody} and {@link HeaderMap} are
|
||||
* parameter maps.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
interface ParamMapSpec {
|
||||
|
||||
Type getTypeFor(String paramName);
|
||||
|
||||
boolean checkIfCompatible(String paramName, Type type);
|
||||
|
||||
boolean checkIfCompatible(String paramName, Object object);
|
||||
|
||||
public Set<Map.Entry<String, Type>> entrySet();
|
||||
|
||||
public int size();
|
||||
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
|
||||
// Copied from com.google.gson.TypeUtils
|
||||
package com.google.gson.webservice.definition;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Utility class containing some methods for obtaining information on types.
|
||||
*
|
||||
* @author Inderjeet Singh
|
||||
* @author Joel Leitch
|
||||
*/
|
||||
final class TypeUtils {
|
||||
|
||||
/**
|
||||
* Returns the actual type matching up with the first type variable.
|
||||
* So, for a {@code typeInfo} instance defined as:
|
||||
* <pre>
|
||||
* class Foo<A, B> {
|
||||
* }
|
||||
* Type fooType = new TypeToken<Foo<Integer, String>>() {}.getType();
|
||||
* </pre>
|
||||
* <code>TypeUtils.getActualTypeForFirstTypeVariable(fooType)</code> will return Integer.class.
|
||||
*/
|
||||
static Type getActualTypeForFirstTypeVariable(Type type) {
|
||||
if (type instanceof Class) {
|
||||
return Object.class;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
return ((ParameterizedType)type).getActualTypeArguments()[0];
|
||||
} else if (type instanceof GenericArrayType) {
|
||||
return getActualTypeForFirstTypeVariable(((GenericArrayType)type).getGenericComponentType());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Type \'" + type + "\' is not a Class, "
|
||||
+ "ParameterizedType, or GenericArrayType. Can't extract class.");
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isArray(Type type) {
|
||||
if (type instanceof Class) {
|
||||
return ((Class<?>)type).isArray();
|
||||
} else if (type instanceof GenericArrayType) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the actual raw class associated with the specified type.
|
||||
*/
|
||||
static Class<?> toRawClass(Type type) {
|
||||
if (type instanceof Class) {
|
||||
return (Class<?>) type;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
ParameterizedType actualType = (ParameterizedType)type;
|
||||
return toRawClass(actualType.getRawType());
|
||||
} else if (type instanceof GenericArrayType) {
|
||||
GenericArrayType actualType = (GenericArrayType) type;
|
||||
Class<?> rawClass = toRawClass(actualType.getGenericComponentType());
|
||||
return wrapWithArray(rawClass);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Type \'" + type + "\' is not a Class, "
|
||||
+ "ParameterizedType, or GenericArrayType. Can't extract class.");
|
||||
}
|
||||
}
|
||||
|
||||
static Class<?> wrapWithArray(Class<?> rawClass) {
|
||||
return Array.newInstance(rawClass, 0).getClass();
|
||||
}
|
||||
|
||||
private TypeUtils() {
|
||||
// Class with just some static utility methods, should not be instantiated
|
||||
}
|
||||
}
|
@ -1,72 +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.webservice.definition;
|
||||
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
/**
|
||||
* A typed key for use in a {@link ParamMap} or a {@link ParamMapSpec}.
|
||||
*
|
||||
* @author inder
|
||||
*
|
||||
* @param <T> Intended type of the content for the key
|
||||
*/
|
||||
public class TypedKey<T> {
|
||||
private final String name;
|
||||
private final Class<T> classOfT;
|
||||
|
||||
public TypedKey(String name, Class<T> classOfT) {
|
||||
Preconditions.checkNotNull(name);
|
||||
Preconditions.checkNotNull(classOfT);
|
||||
|
||||
this.name = name;
|
||||
this.classOfT = classOfT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<T> getClassOfT() {
|
||||
return classOfT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode() + classOfT.getCanonicalName().hashCode() >> 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TypedKey<?> other = (TypedKey<?>) obj;
|
||||
return name.equals(other.name) && classOfT.equals(other.classOfT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{name:%s, classOfT:%s}", name, classOfT);
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
final class Util {
|
||||
private Util() { }
|
||||
|
||||
public static boolean isAssignableFrom(Type typeOfValue, Type expectedType) {
|
||||
return typeOfValue.equals(expectedType);
|
||||
}
|
||||
|
||||
public static String toStringMapKeys(Map<String, ?> map) {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(entry.getKey());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String toStringMapOfTypes(Map<String, Type> map) {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(entry.getKey()).append(":");
|
||||
Class<?> clazz = (Class<?>) entry.getValue();
|
||||
sb.append(clazz.getSimpleName());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String toStringMap(Map<String, Object> map) {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
boolean first = true;
|
||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(entry.getKey()).append(":").append(entry.getValue());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition;
|
||||
|
||||
/**
|
||||
* Base class for all exceptions thrown by the Web service to indicate a system error condition.
|
||||
* This should never be thrown to indicate bad user input.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class WebServiceSystemException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public WebServiceSystemException(Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public WebServiceSystemException(String msg, Exception cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
@ -1,64 +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.webservice.definition.internal.utils;
|
||||
|
||||
/**
|
||||
* A simple object that holds onto a pair of object references, first and second.
|
||||
*
|
||||
* @author Inderjeet Singh
|
||||
*
|
||||
* @param <FIRST>
|
||||
* @param <SECOND>
|
||||
*/
|
||||
public final class Pair<FIRST, SECOND> {
|
||||
|
||||
public final FIRST first;
|
||||
public final SECOND second;
|
||||
|
||||
public Pair(FIRST first, SECOND second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public static <F, S> Pair<F, S> create(F first, S second) {
|
||||
return new Pair<F, S>(first, second);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 17 * ((first != null) ? first.hashCode() : 0)
|
||||
+ 17 * ((second != null) ? second.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Pair<?, ?>)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pair<?, ?> that = (Pair<?, ?>) o;
|
||||
return equal(this.first, that.first) && equal(this.second, that.second);
|
||||
}
|
||||
|
||||
private static boolean equal(Object a, Object b) {
|
||||
return a == b || (a != null && a.equals(b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{%s,%s}", first, second);
|
||||
}
|
||||
}
|
@ -1,43 +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.webservice.definition.internal.utils;
|
||||
|
||||
public final class Preconditions {
|
||||
|
||||
public static void checkArgument(boolean condition) {
|
||||
if (!condition) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkArgument(boolean condition, String msg, Object... msgArgs) {
|
||||
if (!condition) {
|
||||
throw new IllegalArgumentException(String.format(msg, msgArgs));
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotNull(Object obj) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotNull(Object obj, String msg, Object... msgArgs) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException(String.format(msg, msgArgs));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.ContentBody;
|
||||
import com.google.gson.webservice.definition.ParamMap;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
import com.google.gson.webservice.definition.ParamMap.Builder;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Definition of the request body of a {@link WebServiceCall}. The request body is what is sent out
|
||||
* in the output stream of the request (for example, with
|
||||
* {@link java.net.HttpURLConnection#getOutputStream()}) , and is read by the
|
||||
* javax.servlet.http.HttpServletRequest#getInputStream().
|
||||
* This class omits the default constructor for use by Gson. Instead the user must use
|
||||
* {@link com.google.gson.webservice.definition.procedural.RequestBodyGsonConverter}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RequestBody extends ContentBody {
|
||||
|
||||
public static class Builder extends ParamMap.Builder<RequestBodySpec> {
|
||||
|
||||
public Builder(RequestBodySpec spec) {
|
||||
super(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content) {
|
||||
return (Builder) super.put(paramName, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content, Type typeOfContent) {
|
||||
return (Builder) super.put(paramName, content, typeOfContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Builder put(TypedKey<T> paramKey, T param) {
|
||||
return (Builder) super.put(paramKey, param);
|
||||
}
|
||||
|
||||
public RequestBody build() {
|
||||
return new RequestBody(spec, contents);
|
||||
}
|
||||
}
|
||||
|
||||
private RequestBody(RequestBodySpec spec, Map<String, Object> contents) {
|
||||
super(spec, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBodySpec getSpec() {
|
||||
return (RequestBodySpec) spec;
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
/**
|
||||
* Gson type adapter for {@link RequestBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class RequestBodyGsonConverter implements JsonSerializer<RequestBody>,
|
||||
JsonDeserializer<RequestBody>, InstanceCreator<RequestBody> {
|
||||
|
||||
private final RequestBodySpec spec;
|
||||
|
||||
public RequestBodyGsonConverter(RequestBodySpec spec) {
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(RequestBody src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
JsonObject root = new JsonObject();
|
||||
for(Map.Entry<String, Object> entry : src.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Type entryType = src.getSpec().getTypeFor(key);
|
||||
JsonElement value = context.serialize(entry.getValue(), entryType);
|
||||
root.add(key, value);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
RequestBody.Builder builder = new RequestBody.Builder(spec);
|
||||
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Type entryType = spec.getTypeFor(key);
|
||||
Object value = context.deserialize(entry.getValue(), entryType);
|
||||
builder.put(key, value);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBody createInstance(Type type) {
|
||||
return new RequestBody.Builder(spec).build();
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
|
||||
import com.google.gson.webservice.definition.ContentBodySpec;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Specification of a {@link RequestBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RequestBodySpec extends ContentBodySpec {
|
||||
|
||||
public static class Builder {
|
||||
private final Map<String, Type> paramsSpec = new LinkedHashMap<String, Type>();
|
||||
public Builder add(String paramName, Type type) {
|
||||
paramsSpec.put(paramName, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestBodySpec build() {
|
||||
RequestBodySpec spec = new RequestBodySpec(paramsSpec);
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
|
||||
public RequestBodySpec(Map<String, Type> paramsSpec) {
|
||||
super(paramsSpec);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
/**
|
||||
* Specification for a {@link WebServiceRequest}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class RequestSpec {
|
||||
|
||||
private final HeaderMapSpec headersSpec;
|
||||
private final RequestBodySpec bodySpec;
|
||||
|
||||
public RequestSpec(HeaderMapSpec headersSpec, RequestBodySpec bodySpec) {
|
||||
Preconditions.checkNotNull(headersSpec);
|
||||
Preconditions.checkNotNull(bodySpec);
|
||||
|
||||
this.headersSpec = headersSpec;
|
||||
this.bodySpec = bodySpec;
|
||||
}
|
||||
|
||||
public HeaderMapSpec getHeadersSpec() {
|
||||
return headersSpec;
|
||||
}
|
||||
|
||||
public RequestBodySpec getBodySpec() {
|
||||
return bodySpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{headersSpec:");
|
||||
sb.append(headersSpec).append(",bodySpec:");
|
||||
sb.append(bodySpec).append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.ContentBody;
|
||||
import com.google.gson.webservice.definition.ParamMap;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* body of the response. This is written out as JSON to be sent out to the client.
|
||||
* This class omits the default constructor for use by Gson. Instead the user must use
|
||||
* {@link com.google.gson.webservice.definition.procedural.ResponseBodyGsonConverter}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class ResponseBody extends ContentBody {
|
||||
|
||||
public static class Builder extends ParamMap.Builder<ResponseBodySpec> {
|
||||
|
||||
public Builder(ResponseBodySpec spec) {
|
||||
super(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content) {
|
||||
return (Builder) super.put(paramName, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder put(String paramName, Object content, Type typeOfContent) {
|
||||
return (Builder) super.put(paramName, content, typeOfContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Builder put(TypedKey<T> paramKey, T param) {
|
||||
return (Builder) super.put(paramKey, param);
|
||||
}
|
||||
|
||||
public ResponseBody build() {
|
||||
return new ResponseBody(spec, contents);
|
||||
}
|
||||
}
|
||||
|
||||
private ResponseBody(ResponseBodySpec spec, Map<String, Object> contents) {
|
||||
super(spec, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseBodySpec getSpec() {
|
||||
return (ResponseBodySpec) spec;
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
/**
|
||||
* Gson type adapter for {@link ResponseBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class ResponseBodyGsonConverter implements JsonSerializer<ResponseBody>,
|
||||
JsonDeserializer<ResponseBody>, InstanceCreator<ResponseBody> {
|
||||
|
||||
private final ResponseBodySpec spec;
|
||||
|
||||
public ResponseBodyGsonConverter(ResponseBodySpec spec) {
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ResponseBody src, Type typeOfSrc,
|
||||
JsonSerializationContext context) {
|
||||
JsonObject root = new JsonObject();
|
||||
for(Map.Entry<String, Object> entry : src.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Type entryType = src.getSpec().getTypeFor(key);
|
||||
JsonElement value = context.serialize(entry.getValue(), entryType);
|
||||
root.add(key, value);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseBody deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
ResponseBody.Builder responseBodyBuilder = new ResponseBody.Builder(spec);
|
||||
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Type entryType = spec.getTypeFor(key);
|
||||
Object value = context.deserialize(entry.getValue(), entryType);
|
||||
responseBodyBuilder.put(key, value, entryType);
|
||||
}
|
||||
return responseBodyBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseBody createInstance(Type type) {
|
||||
return new ResponseBody.Builder(spec).build();
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.ContentBodySpec;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Specification of a {@link ResponseBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class ResponseBodySpec extends ContentBodySpec {
|
||||
|
||||
public static class Builder {
|
||||
private final Map<String, Type> paramsSpec = new LinkedHashMap<String, Type>();
|
||||
public Builder add(String paramName, Type type) {
|
||||
paramsSpec.put(paramName, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseBodySpec build() {
|
||||
ResponseBodySpec spec = new ResponseBodySpec(paramsSpec);
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
|
||||
public ResponseBodySpec(Map<String, Type> paramsSpec) {
|
||||
super(paramsSpec);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
/**
|
||||
* Specification for a {@link WebServiceResponse}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class ResponseSpec {
|
||||
private final HeaderMapSpec headersSpec;
|
||||
private final ResponseBodySpec bodySpec;
|
||||
|
||||
public ResponseSpec(HeaderMapSpec headersSpec, ResponseBodySpec bodySpec) {
|
||||
Preconditions.checkNotNull(headersSpec);
|
||||
Preconditions.checkNotNull(bodySpec);
|
||||
|
||||
this.headersSpec = headersSpec;
|
||||
this.bodySpec = bodySpec;
|
||||
}
|
||||
|
||||
public ResponseBodySpec getBodySpec() {
|
||||
return bodySpec;
|
||||
}
|
||||
|
||||
public HeaderMapSpec getHeadersSpec() {
|
||||
return headersSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{headersSpec:");
|
||||
sb.append(headersSpec).append(",bodySpec:");
|
||||
sb.append(bodySpec).append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
|
||||
/**
|
||||
* The data associated with a Web service call. This includes http request header parameters (form
|
||||
* and URL parameters), {@link RequestBody}, response header parameters, and {@link ResponseBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class WebServiceCall {
|
||||
|
||||
private final WebServiceCallSpec callSpec;
|
||||
private final WebServiceRequest request;
|
||||
private final WebServiceResponse response;
|
||||
|
||||
public WebServiceCall(WebServiceCallSpec callSpec, WebServiceRequest request,
|
||||
WebServiceResponse response) {
|
||||
this.callSpec = callSpec;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public WebServiceCallSpec getSpec() {
|
||||
return callSpec;
|
||||
}
|
||||
|
||||
public WebServiceRequest getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public WebServiceResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
import com.google.gson.webservice.definition.internal.utils.Preconditions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Specification for a Json web service call. The call includes the relative path where the call
|
||||
* is available, the specification of requests, and responses.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class WebServiceCallSpec {
|
||||
|
||||
public static final WebServiceCallSpec NULL_SPEC = new Builder(new CallPath("")).build();
|
||||
|
||||
public static class Builder {
|
||||
private final CallPath callPath;
|
||||
private final Set<HttpMethod> supportedHttpMethods = new LinkedHashSet<HttpMethod>();
|
||||
private final HeaderMapSpec.Builder reqParamsSpecBuilder = new HeaderMapSpec.Builder();
|
||||
private final RequestBodySpec.Builder reqBodySpecBuilder = new RequestBodySpec.Builder();
|
||||
private final HeaderMapSpec.Builder resParamsSpecBuilder = new HeaderMapSpec.Builder();
|
||||
private final ResponseBodySpec.Builder resBodySpecBuilder = new ResponseBodySpec.Builder();
|
||||
|
||||
public Builder(CallPath callPath) {
|
||||
this.callPath = callPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this method is not invoked, then it is assumed that the WebServiceCall supports all
|
||||
* methods specified in {@link HttpMethod#values()}.
|
||||
*
|
||||
* @param httpMethods list of methods that this call supports.
|
||||
* @return self to follow the Builder pattern.
|
||||
*/
|
||||
public Builder supportsHttpMethod(HttpMethod... httpMethods) {
|
||||
supportedHttpMethods.addAll(Arrays.asList(httpMethods));
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addRequestParam(TypedKey<T> param) {
|
||||
reqParamsSpecBuilder.put(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addRequestBodyParam(TypedKey<T> param) {
|
||||
reqBodySpecBuilder.add(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addResponseParam(TypedKey<T> param) {
|
||||
resParamsSpecBuilder.put(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder addResponseBodyParam(TypedKey<T> param) {
|
||||
resBodySpecBuilder.add(param.getName(), param.getClassOfT());
|
||||
return this;
|
||||
}
|
||||
|
||||
public WebServiceCallSpec build() {
|
||||
if (supportedHttpMethods.isEmpty()) {
|
||||
supportedHttpMethods.addAll(Arrays.asList(HttpMethod.values()));
|
||||
}
|
||||
RequestSpec requestSpec =
|
||||
new RequestSpec(reqParamsSpecBuilder.build(), reqBodySpecBuilder.build());
|
||||
ResponseSpec responseSpec =
|
||||
new ResponseSpec(resParamsSpecBuilder.build(), resBodySpecBuilder.build());
|
||||
WebServiceCallSpec callSpec = new WebServiceCallSpec(supportedHttpMethods, callPath,
|
||||
requestSpec, responseSpec);
|
||||
return callSpec;
|
||||
}
|
||||
}
|
||||
|
||||
private final Set<HttpMethod> supportedHttpMethods;
|
||||
private final CallPath path;
|
||||
private final ResponseSpec responseSpec;
|
||||
private final RequestSpec requestSpec;
|
||||
|
||||
private WebServiceCallSpec(Set<HttpMethod> supportedHttpMethods, CallPath path,
|
||||
RequestSpec requestSpec, ResponseSpec responseSpec) {
|
||||
Preconditions.checkArgument(!supportedHttpMethods.isEmpty());
|
||||
Preconditions.checkNotNull(path);
|
||||
|
||||
this.supportedHttpMethods = supportedHttpMethods;
|
||||
this.path = path;
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public CallPath getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public Set<HttpMethod> getSupportedHttpMethods() {
|
||||
return supportedHttpMethods;
|
||||
}
|
||||
|
||||
public ResponseSpec getResponseSpec() {
|
||||
return responseSpec;
|
||||
}
|
||||
|
||||
public RequestSpec getRequestSpec() {
|
||||
return requestSpec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{path:");
|
||||
sb.append(path).append(",supportedHttpMethods:[");
|
||||
boolean first = true;
|
||||
for (HttpMethod method : supportedHttpMethods) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(method);
|
||||
}
|
||||
sb.append("],requestSpec:").append(requestSpec);
|
||||
sb.append(",responseSpec:").append(responseSpec).append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.ContentBodySpec;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
/**
|
||||
* The data associated with a Web service request. This includes HTTP request header parameters
|
||||
* (form and URL parameters), and {@link RequestBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class WebServiceRequest {
|
||||
private final HttpMethod method;
|
||||
private final HeaderMap headers;
|
||||
private final RequestBody body;
|
||||
private final RequestSpec spec;
|
||||
|
||||
public WebServiceRequest(HttpMethod method, HeaderMap requestHeaders, RequestBody requestBody) {
|
||||
this.method = method;
|
||||
this.body = requestBody;
|
||||
this.headers = requestHeaders;
|
||||
this.spec = new RequestSpec(requestHeaders.getSpec(), requestBody.getSpec());
|
||||
}
|
||||
|
||||
public HttpMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public RequestSpec getSpec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
public HttpMethod getHttpMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public RequestBody getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public HeaderMap getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return ContentBodySpec.JSON_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
public <T> T getHeader(TypedKey<T> headerKey) {
|
||||
return headers.get(headerKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
sb.append(method).append(",");
|
||||
sb.append(",headers:").append(headers);
|
||||
sb.append(",body:").append(body);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* The data associated with a Web service response. This includes http response header parameters,
|
||||
* and {@link ResponseBody}.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public final class WebServiceResponse {
|
||||
|
||||
private final HeaderMap headers;
|
||||
private final ResponseBody body;
|
||||
private final ResponseSpec spec;
|
||||
|
||||
public static class Builder {
|
||||
private final HeaderMap.Builder headers;
|
||||
private final ResponseBody.Builder body;
|
||||
private final ResponseSpec spec;
|
||||
|
||||
public Builder(ResponseSpec spec) {
|
||||
this.spec = spec;
|
||||
headers = new HeaderMap.Builder(spec.getHeadersSpec());
|
||||
body = new ResponseBody.Builder(spec.getBodySpec());
|
||||
}
|
||||
|
||||
public Builder putHeader(String paramName, Object content) {
|
||||
headers.put(paramName, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder putHeader(String paramName, Object content, Type typeOfContent) {
|
||||
headers.put(paramName, content, typeOfContent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Builder putBody(TypedKey<T> paramName, T content) {
|
||||
return putBody(paramName.getName(), content);
|
||||
}
|
||||
|
||||
public Builder putBody(String paramName, Object content) {
|
||||
body.put(paramName, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder put(String paramName, Object content, Type typeOfContent) {
|
||||
body.put(paramName, content, typeOfContent);
|
||||
return this;
|
||||
}
|
||||
|
||||
public WebServiceResponse build() {
|
||||
return new WebServiceResponse(spec, headers.build(), body.build());
|
||||
}
|
||||
}
|
||||
|
||||
private WebServiceResponse(ResponseSpec spec, HeaderMap headers, ResponseBody body) {
|
||||
this.spec = spec;
|
||||
this.headers = headers;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public WebServiceResponse(HeaderMap responseHeaders, ResponseBody responseBody) {
|
||||
this.spec = new ResponseSpec(responseHeaders.getSpec(), responseBody.getSpec());
|
||||
this.headers = responseHeaders;
|
||||
this.body = responseBody;
|
||||
}
|
||||
|
||||
public ResponseSpec getSpec() {
|
||||
return spec;
|
||||
}
|
||||
|
||||
public HeaderMap getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public ResponseBody getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getHeader(String headerName) {
|
||||
return (T) headers.get(headerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("{headers:");
|
||||
sb.append(headers);
|
||||
sb.append(",body:").append(body);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.webservice.definition.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPathMap;
|
||||
|
||||
/**
|
||||
* Specification of the Web service. This contains a specification of all the
|
||||
* {@link WebServiceCall}s supported by this Web service.
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public interface WebServiceSpec {
|
||||
public CallPathMap<WebServiceCallSpec> getCalls();
|
||||
}
|
@ -1,55 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
|
||||
/**
|
||||
* Unit test for {@link ValueBasedId}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class IdTest extends TestCase {
|
||||
|
||||
public void testRawTypeNotEqualToParameterizedOfConcreteType() {
|
||||
ParameterizedType type = (ParameterizedType) new TypeToken<ValueBasedId<Foo>>(){}.getType();
|
||||
assertFalse(ValueBasedId.areEquivalentTypes(type, ValueBasedId.class));
|
||||
}
|
||||
|
||||
public void testRawTypeEqualToParameterizedOfWildcardType() {
|
||||
ParameterizedType fooType = (ParameterizedType) new TypeToken<ValueBasedId<?>>(){}.getType();
|
||||
assertTrue(ValueBasedId.areEquivalentTypes(fooType, ValueBasedId.class));
|
||||
}
|
||||
|
||||
public void testStaticEquals() {
|
||||
ValueBasedId<Foo> id1 = ValueBasedId.get(3L, Foo.class);
|
||||
ValueBasedId<Foo> id2 = ValueBasedId.get(3L, Foo.class);
|
||||
ValueBasedId<Foo> id3 = ValueBasedId.get(4L, Foo.class);
|
||||
assertTrue(ValueBasedId.equals(id1, id2));
|
||||
assertFalse(ValueBasedId.equals(null, id2));
|
||||
assertFalse(ValueBasedId.equals(id1, null));
|
||||
assertTrue(ValueBasedId.equals(null, null));
|
||||
assertFalse(ValueBasedId.equals(id1, id3));
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
}
|
||||
}
|
@ -1,133 +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.rest.definition;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ValueBasedId.GsonTypeAdapter}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class IdTypeAdapterTest extends TestCase {
|
||||
private static final ValueBasedId<Student> STUDENT1_ID = ValueBasedId.get(5L, Student.class);
|
||||
private static final ValueBasedId<Student> STUDENT2_ID = ValueBasedId.get(6L, Student.class);
|
||||
private static final Student STUDENT1 = new Student(STUDENT1_ID, "first");
|
||||
private static final Student STUDENT2 = new Student(STUDENT2_ID, "second");
|
||||
private static final Type TYPE_COURSE_HISTORY =
|
||||
new TypeToken<Course<HistoryCourse>>(){}.getType();
|
||||
private static final ValueBasedId<Course<HistoryCourse>> COURSE_ID = ValueBasedId.get(10L, TYPE_COURSE_HISTORY);
|
||||
|
||||
private Gson gson;
|
||||
private Course<HistoryCourse> course;
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
gson = new GsonBuilder()
|
||||
.registerTypeAdapter(ValueBasedId.class, new ValueBasedId.GsonTypeAdapter())
|
||||
.create();
|
||||
course = new Course<HistoryCourse>(COURSE_ID, 4,
|
||||
new Assignment<HistoryCourse>(null, null), createList(STUDENT1, STUDENT2));
|
||||
}
|
||||
|
||||
public void testSerializeId() {
|
||||
String json = gson.toJson(course, TYPE_COURSE_HISTORY);
|
||||
assertTrue(json.contains(String.valueOf(COURSE_ID.getValue())));
|
||||
assertTrue(json.contains(String.valueOf(STUDENT1_ID.getValue())));
|
||||
assertTrue(json.contains(String.valueOf(STUDENT2_ID.getValue())));
|
||||
}
|
||||
|
||||
public void testDeserializeId() {
|
||||
String json = "{courseId:1,students:[{id:1,name:'first'},{id:6,name:'second'}],"
|
||||
+ "numAssignments:4,assignment:{}}";
|
||||
Course<HistoryCourse> target = gson.fromJson(json, TYPE_COURSE_HISTORY);
|
||||
assertEquals(1, target.getStudents().get(0).id.getValue());
|
||||
assertEquals(6, target.getStudents().get(1).id.getValue());
|
||||
assertEquals(1, target.getId().getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Student {
|
||||
ValueBasedId<Student> id;
|
||||
String name;
|
||||
|
||||
private Student() {
|
||||
this(null, null);
|
||||
}
|
||||
public Student(ValueBasedId<Student> id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
private static class Course<T> {
|
||||
final List<Student> students;
|
||||
private final ValueBasedId<Course<T>> courseId;
|
||||
private final int numAssignments;
|
||||
private final Assignment<T> assignment;
|
||||
|
||||
private Course() {
|
||||
this(null, 0, null, new ArrayList<Student>());
|
||||
}
|
||||
|
||||
public Course(ValueBasedId<Course<T>> courseId, int numAssignments,
|
||||
Assignment<T> assignment, List<Student> players) {
|
||||
this.courseId = courseId;
|
||||
this.numAssignments = numAssignments;
|
||||
this.assignment = assignment;
|
||||
this.students = players;
|
||||
}
|
||||
public ValueBasedId<Course<T>> getId() {
|
||||
return courseId;
|
||||
}
|
||||
List<Student> getStudents() {
|
||||
return students;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Assignment<T> {
|
||||
private final ValueBasedId<Assignment<T>> id;
|
||||
private final T data;
|
||||
|
||||
private Assignment() {
|
||||
this(null, null);
|
||||
}
|
||||
public Assignment(ValueBasedId<Assignment<T>> id, T data) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class HistoryCourse {
|
||||
int numClasses;
|
||||
}
|
||||
|
||||
private static <T> List<T> createList(T ...items) {
|
||||
return Arrays.asList(items);
|
||||
}
|
||||
}
|
@ -1,82 +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.webservice.definition;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit test for {@link CallPath}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class CallPathTest extends TestCase {
|
||||
|
||||
public void testVersionIsSkipped() {
|
||||
CallPath path = new CallPath("/1.0/rest/service1");
|
||||
assertEquals("/rest/service1", path.get());
|
||||
assertEquals(1D, path.getVersion());
|
||||
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||
}
|
||||
|
||||
public void testVersionNotPresent() {
|
||||
CallPath path = new CallPath("/rest/service1");
|
||||
assertEquals("/rest/service1", path.get());
|
||||
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||
}
|
||||
|
||||
public void testResourceIdPresent() {
|
||||
CallPath path = new CallPath("/rest/service/3");
|
||||
assertEquals("/rest/service", path.get());
|
||||
assertEquals(3L, path.getResourceId());
|
||||
}
|
||||
|
||||
public void testResourceIdWithEndSlashPresent() {
|
||||
CallPath path = new CallPath("/rest/service/3/");
|
||||
assertEquals("/rest/service", path.get());
|
||||
assertEquals(3L, path.getResourceId());
|
||||
}
|
||||
|
||||
public void testVersionAndResourceIdPresent() {
|
||||
CallPath path = new CallPath("/3.1/rest/service53/323222");
|
||||
assertEquals(3.1D, path.getVersion());
|
||||
assertEquals("/rest/service53", path.get());
|
||||
assertEquals(323222L, path.getResourceId());
|
||||
}
|
||||
|
||||
public void testNullPath() {
|
||||
CallPath path = new CallPath(null);
|
||||
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||
assertNull(path.get());
|
||||
}
|
||||
|
||||
public void testEmptyPath() {
|
||||
CallPath path = new CallPath("");
|
||||
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||
assertEquals("", path.get());
|
||||
}
|
||||
|
||||
public void testWhiteSpacePath() {
|
||||
CallPath path = new CallPath("\r\n");
|
||||
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||
assertEquals("\r\n", path.get());
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
|
||||
package com.google.gson.webservice.definition;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link TypedKey}
|
||||
*
|
||||
* @author inder
|
||||
*/
|
||||
public class TypedKeyTest extends TestCase {
|
||||
|
||||
public void testEqualsForSameName() {
|
||||
assertEquals(new TypedKey<String>("name", String.class),
|
||||
new TypedKey<String>(new String("name"), String.class));
|
||||
}
|
||||
|
||||
public void testEqualsFailsForDifferentClasses() {
|
||||
assertFalse(new TypedKey<Object>("name", Object.class).equals(
|
||||
new TypedKey<String>("name", String.class)));
|
||||
}
|
||||
}
|
@ -56,9 +56,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<groupId>com.google.code.greaze</groupId>
|
||||
<artifactId>greaze-definition</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -15,6 +15,12 @@
|
||||
*/
|
||||
package com.google.gson.example.client;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
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.gson.example.model.Cart;
|
||||
import com.google.gson.example.model.LineItem;
|
||||
import com.google.gson.example.model.Order;
|
||||
@ -22,12 +28,6 @@ import com.google.gson.example.model.TypedKeys;
|
||||
import com.google.gson.example.service.SampleJsonService;
|
||||
import com.google.gson.webservice.client.ServerConfig;
|
||||
import com.google.gson.webservice.client.WebServiceClient;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBody;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -14,6 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/package com.google.gson.example.rest.client;
|
||||
|
||||
import com.google.greaze.definition.CallPath;
|
||||
import com.google.greaze.definition.rest.ValueBasedId;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.example.model.Cart;
|
||||
import com.google.gson.example.model.LineItem;
|
||||
@ -21,11 +23,9 @@ import com.google.gson.example.model.Order;
|
||||
import com.google.gson.example.model.QueryOrdersByItemName;
|
||||
import com.google.gson.rest.client.ResourceDepotClient;
|
||||
import com.google.gson.rest.client.RestClientStub;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
import com.google.gson.rest.query.client.ResourceQueryClient;
|
||||
import com.google.gson.webservice.client.ServerConfig;
|
||||
import com.google.gson.webservice.client.WebServiceClient;
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -56,9 +56,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<groupId>com.google.code.greaze</groupId>
|
||||
<artifactId>greaze-definition</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.example.model;
|
||||
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.ValueBasedId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.example.model;
|
||||
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.ValueBasedId;
|
||||
|
||||
/**
|
||||
* An order
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.google.gson.example.model;
|
||||
|
||||
import com.google.gson.webservice.definition.TypedKey;
|
||||
import com.google.greaze.definition.TypedKey;
|
||||
|
||||
/**
|
||||
* Definition of various constants to be used for parameter names of request and response headers,
|
||||
|
@ -14,10 +14,10 @@
|
||||
* 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;
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
|
||||
/**
|
||||
* An example of a web-service definition
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.google.gson.example.service;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.greaze.definition.CallPath;
|
||||
|
||||
/**
|
||||
* An enum describing all paths for this service
|
||||
|
@ -56,9 +56,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<groupId>com.google.code.greaze</groupId>
|
||||
<artifactId>greaze-definition</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -19,7 +19,7 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.greaze.definition.CallPath;
|
||||
|
||||
/**
|
||||
* An example servlet that receives JSON web-service requests
|
||||
|
@ -18,22 +18,22 @@ 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.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;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBody;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBodyGsonConverter;
|
||||
import com.google.gson.webservice.definition.procedural.RequestSpec;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBody;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBodyGsonConverter;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
import com.google.gson.wsf.server.procedural.RequestReceiver;
|
||||
import com.google.gson.wsf.server.procedural.ResponseSender;
|
||||
|
||||
|
@ -18,25 +18,25 @@ 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.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;
|
||||
import com.google.gson.rest.definition.IDFactory;
|
||||
import com.google.gson.rest.definition.MetaData;
|
||||
import com.google.gson.rest.definition.ResourceMap;
|
||||
import com.google.gson.rest.definition.RestCallSpec;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.rest.definition.ValueBasedId;
|
||||
import com.google.gson.rest.server.Repository;
|
||||
import com.google.gson.rest.server.RepositoryInMemory;
|
||||
import com.google.gson.rest.server.ResponseBuilderMap;
|
||||
import com.google.gson.rest.server.RestRequestReceiver;
|
||||
import com.google.gson.rest.server.RestResponseBuilder;
|
||||
import com.google.gson.rest.server.RestResponseSender;
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
|
||||
/**
|
||||
* A dispatcher for all the REST requests
|
||||
|
@ -64,9 +64,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>wsdef</artifactId>
|
||||
<version>0.1</version>
|
||||
<groupId>com.google.code.greaze</groupId>
|
||||
<artifactId>greaze-definition</artifactId>
|
||||
<version>0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -21,9 +21,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.gson.rest.definition.HasId;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.IDFactory;
|
||||
import com.google.greaze.definition.rest.HasId;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.IDFactory;
|
||||
|
||||
/**
|
||||
* This class provides a type-safe map to access values associated with Ids
|
||||
|
@ -18,9 +18,9 @@ package com.google.gson.rest.server;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.MetaData;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.MetaData;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
|
||||
/**
|
||||
* A map of resources to their MetaData
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.rest.server;
|
||||
|
||||
import com.google.gson.rest.definition.HasId;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.greaze.definition.rest.HasId;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
|
||||
/**
|
||||
* An interface for a repository of rest resources. Meant for abstracting the server-side
|
||||
|
@ -16,9 +16,9 @@
|
||||
package com.google.gson.rest.server;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.MetaData;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.MetaData;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
|
||||
/**
|
||||
* An in-memory map of rest resources
|
||||
|
@ -19,9 +19,9 @@ import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestCallSpec;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestCallSpec;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
|
||||
/**
|
||||
* A map of {@link RestCallSpec}, {@link RestResponseBuilder} to help figure out which
|
||||
|
@ -24,16 +24,16 @@ import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestRequest;
|
||||
import com.google.greaze.definition.rest.RestRequestSpec;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestRequestSpec;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
|
||||
/**
|
||||
* Receives and parses a request at the server side on a {@link HttpServletRequest}.
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.google.gson.rest.server;
|
||||
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestCallSpec;
|
||||
import com.google.gson.rest.definition.RestRequest;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestCallSpec;
|
||||
import com.google.greaze.definition.rest.RestRequest;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.RestResponse;
|
||||
|
||||
public class RestResponseBuilder<I extends ID, R extends RestResource<I, R>> {
|
||||
protected final Repository<I, R> resources;
|
||||
|
@ -22,13 +22,13 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.google.greaze.definition.ContentBodySpec;
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.rest.ID;
|
||||
import com.google.greaze.definition.rest.RestResource;
|
||||
import com.google.greaze.definition.rest.RestResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.rest.definition.ID;
|
||||
import com.google.gson.rest.definition.RestResource;
|
||||
import com.google.gson.rest.definition.RestResponse;
|
||||
import com.google.gson.webservice.definition.ContentBodySpec;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
|
||||
/**
|
||||
* Sends a JSON web service response on {@link HttpServletResponse}.
|
||||
|
@ -17,7 +17,7 @@ package com.google.gson.wsf.inject;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.greaze.definition.CallPath;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.wsf.inject.server.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.procedural.RequestBodySpec;
|
||||
import com.google.gson.webservice.definition.procedural.RequestSpec;
|
||||
import com.google.greaze.definition.webservice.RequestBodySpec;
|
||||
import com.google.greaze.definition.webservice.RequestSpec;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.google.gson.wsf.inject.server.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.procedural.RequestSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.RequestSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
|
@ -17,11 +17,11 @@ package com.google.gson.wsf.inject.server.procedural;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.greaze.definition.webservice.WebServiceCall;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCall;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
import com.google.gson.wsf.server.procedural.RequestReceiver;
|
||||
import com.google.gson.wsf.server.procedural.WebServiceCallServerBuilder;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.google.gson.wsf.inject.server.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.CallPath;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceSpec;
|
||||
import com.google.greaze.definition.CallPath;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceSpec;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
|
@ -24,16 +24,16 @@ import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.HttpMethod;
|
||||
import com.google.greaze.definition.WebServiceSystemException;
|
||||
import com.google.greaze.definition.webservice.RequestBody;
|
||||
import com.google.greaze.definition.webservice.RequestBodySpec;
|
||||
import com.google.greaze.definition.webservice.RequestSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.HttpMethod;
|
||||
import com.google.gson.webservice.definition.WebServiceSystemException;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBody;
|
||||
import com.google.gson.webservice.definition.procedural.RequestBodySpec;
|
||||
import com.google.gson.webservice.definition.procedural.RequestSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
|
||||
/**
|
||||
* Receives and parses a request at the server side on a {@link HttpServletRequest}.
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.google.gson.wsf.server.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
|
||||
/**
|
||||
* An interface describing a class that can build a response
|
||||
|
@ -22,11 +22,11 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.google.greaze.definition.HeaderMap;
|
||||
import com.google.greaze.definition.HeaderMapSpec;
|
||||
import com.google.greaze.definition.webservice.ResponseBody;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.webservice.definition.HeaderMap;
|
||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||
import com.google.gson.webservice.definition.procedural.ResponseBody;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse;
|
||||
|
||||
/**
|
||||
* Sends a JSON web service response on {@link HttpServletResponse}.
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.google.gson.wsf.server.procedural;
|
||||
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceCallSpec;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceRequest;
|
||||
import com.google.gson.webservice.definition.procedural.WebServiceResponse.Builder;
|
||||
import com.google.greaze.definition.webservice.WebServiceCallSpec;
|
||||
import com.google.greaze.definition.webservice.WebServiceRequest;
|
||||
import com.google.greaze.definition.webservice.WebServiceResponse.Builder;
|
||||
|
||||
public class WebServiceCallServerBuilder {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user