From c4a4f1c3b0e79129eb022ddb43ef2f9596ddb63a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 28 Apr 2014 18:11:45 -0700 Subject: [PATCH] A few bug fixes. --- .../activitystreams/internal/GsonWrapper.java | 45 +++++++++++-------- .../activitystreams/internal/Schema.java | 10 ++++- .../activitystreams/registry/HttpFetch.java | 4 +- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/com/ibm/common/activitystreams/internal/GsonWrapper.java b/core/src/main/java/com/ibm/common/activitystreams/internal/GsonWrapper.java index 0d0c20d..9c6db62 100755 --- a/core/src/main/java/com/ibm/common/activitystreams/internal/GsonWrapper.java +++ b/core/src/main/java/com/ibm/common/activitystreams/internal/GsonWrapper.java @@ -212,19 +212,11 @@ public final class GsonWrapper { Schema.make().get(); ASObjectAdapter base = new ASObjectAdapter(schema); - GsonBuilder b = initGsonBuilder(builder,schema,base); - for (AdapterEntry entry : builder.adapters.build()) { - if (entry.hier) - b.registerTypeHierarchyAdapter( - entry.type, - entry.adapter!=null ? - entry.adapter : base); - else - b.registerTypeAdapter( - entry.type, - entry.adapter!=null ? - entry.adapter:base); - } + GsonBuilder b = initGsonBuilder( + builder, + schema, + base, + builder.adapters.build()); if (builder.pretty) b.setPrettyPrinting(); this.gson = b.create(); @@ -239,12 +231,29 @@ public final class GsonWrapper { private static GsonBuilder initGsonBuilder( Builder builder, Schema schema, - ASObjectAdapter base) { - return new GsonBuilder() - .registerTypeHierarchyAdapter(TypeValue.class, new TypeValueAdapter(schema)) - .registerTypeHierarchyAdapter(LinkValue.class, new LinkValueAdapter(schema)) + ASObjectAdapter base, + Iterable> adapters) { + + GsonBuilder gson = new GsonBuilder() + .registerTypeHierarchyAdapter(TypeValue.class, new TypeValueAdapter(schema)) + .registerTypeHierarchyAdapter(LinkValue.class, new LinkValueAdapter(schema)) + .registerTypeHierarchyAdapter(Iterable.class, ITERABLE); + + for (AdapterEntry entry : adapters) { + if (entry.hier) + gson.registerTypeHierarchyAdapter( + entry.type, + entry.adapter!=null ? + entry.adapter : base); + else + gson.registerTypeAdapter( + entry.type, + entry.adapter!=null ? + entry.adapter:base); + } + + return gson .registerTypeHierarchyAdapter(NLV.class, NLV) - .registerTypeHierarchyAdapter(Iterable.class, ITERABLE) .registerTypeHierarchyAdapter(ActionsValue.class, ACTIONS) .registerTypeHierarchyAdapter(Optional.class, OPTIONAL) .registerTypeHierarchyAdapter(Range.class, RANGE) diff --git a/core/src/main/java/com/ibm/common/activitystreams/internal/Schema.java b/core/src/main/java/com/ibm/common/activitystreams/internal/Schema.java index 3bc3062..1e56433 100755 --- a/core/src/main/java/com/ibm/common/activitystreams/internal/Schema.java +++ b/core/src/main/java/com/ibm/common/activitystreams/internal/Schema.java @@ -200,10 +200,16 @@ public final class Schema { return this; } + public Model model(String objectType) { + return objectTypeMap.get(objectType); + } + + public Model model() { + return objectClassMap.get(ASObject.Builder.class); + } + /** * Method get. - - * @return Schema * @see com.google.common.base.Supplier#get() */ public Schema get() { return new Schema(this); diff --git a/typext/src/main/java/com/ibm/common/activitystreams/registry/HttpFetch.java b/typext/src/main/java/com/ibm/common/activitystreams/registry/HttpFetch.java index 8243956..813fb41 100644 --- a/typext/src/main/java/com/ibm/common/activitystreams/registry/HttpFetch.java +++ b/typext/src/main/java/com/ibm/common/activitystreams/registry/HttpFetch.java @@ -18,6 +18,7 @@ import org.apache.http.config.RegistryBuilder; import org.apache.http.config.SocketConfig; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; @@ -43,7 +44,8 @@ public final class HttpFetch implements Supplier { private final RegistryBuilder csfr = - RegistryBuilder.create(); + RegistryBuilder.create() + .register("http", PlainConnectionSocketFactory.INSTANCE); private ConnectionConfig defaultConnectionConfig; private SocketConfig defaultSocketConfig; private final ImmutableMap.Builder connectionConfigs =