Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M Finkbeiner2013-06-03 16:46:24 -0400
committerGerrit Code Review @ Eclipse.org2013-06-24 13:05:18 -0400
commitec2a4b213f464cff38204510d91c150cf3d5e479 (patch)
treef4d98cc762997ae3d6e1a15526fbfe13d91c2027 /plugins/org.eclipse.osee.ote.master.rest.client
parent70e46b9f76a0a8032cf9cc2c1581acddded94061 (diff)
downloadorg.eclipse.osee-ec2a4b213f464cff38204510d91c150cf3d5e479.tar.gz
org.eclipse.osee-ec2a4b213f464cff38204510d91c150cf3d5e479.tar.xz
org.eclipse.osee-ec2a4b213f464cff38204510d91c150cf3d5e479.zip
feature[ats_LJNN0]: Update OTE Server Lookup
Initial commit of ote master server. This is a rest server that will be used for server lookup. This commit includes the rest implementation a rest client api and the backing service. Change-Id: If9113aacaf32bc5379a5b17d42b0b2f41706e6b9
Diffstat (limited to 'plugins/org.eclipse.osee.ote.master.rest.client')
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/.classpath7
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/.project33
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF16
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.webclientprovider.xml7
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.xml8
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/build.properties5
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java12
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java27
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java21
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java9
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java65
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java38
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java24
-rw-r--r--plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java58
16 files changed, 406 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/.classpath b/plugins/org.eclipse.osee.ote.master.rest.client/.classpath
new file mode 100644
index 0000000000..ad32c83a78
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/.project b/plugins/org.eclipse.osee.ote.master.rest.client/.project
new file mode 100644
index 0000000000..e4b3b68aff
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.ote.master.rest.client</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..e417a489a3
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Client
+Bundle-SymbolicName: org.eclipse.osee.ote.master.rest.client
+Bundle-Version: 0.11.1.qualifier
+Require-Bundle: org.eclipse.core.runtime
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: com.sun.jersey.api.client,
+ com.sun.jersey.api.client.config,
+ com.sun.jersey.client.apache,
+ com.sun.jersey.client.apache.config,
+ javax.ws.rs.core,
+ org.eclipse.osee.ote.master.rest.model
+Export-Package: org.eclipse.osee.ote.master.rest.client
+Service-Component: OSGI-INF/*.xml
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.webclientprovider.xml b/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.webclientprovider.xml
new file mode 100644
index 0000000000..63e9df3ff6
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.webclientprovider.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.ote.master.rest.client..webclientprovider">
+ <implementation class="org.eclipse.osee.ote.master.rest.client.internal.WebClientProviderImpl"/>
+ <service>
+ <provide interface="org.eclipse.osee.ote.master.rest.client.internal.WebClientProvider"/>
+ </service>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.xml b/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.xml
new file mode 100644
index 0000000000..0bfaa47b1d
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/OSGI-INF/ote.master.rest.client.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.ote.master.rest.client">
+ <implementation class="org.eclipse.osee.ote.master.rest.client.internal.OTEMasterServerImpl"/>
+ <reference bind="bindWebClientProvider" cardinality="1..1" interface="org.eclipse.osee.ote.master.rest.client.internal.WebClientProvider" name="WebClientProvider" policy="static" unbind="unbindWebClientProvider"/>
+ <service>
+ <provide interface="org.eclipse.osee.ote.master.rest.client.OTEMasterServer"/>
+ </service>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/build.properties b/plugins/org.eclipse.osee.ote.master.rest.client/build.properties
new file mode 100644
index 0000000000..6210e849b5
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/build.properties
@@ -0,0 +1,5 @@
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/
+source.. = src/
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java
new file mode 100644
index 0000000000..3ef9077bc9
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServer.java
@@ -0,0 +1,12 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+import java.net.URI;
+import java.util.concurrent.Future;
+
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public interface OTEMasterServer {
+ Future<OTEMasterServerAvailableNodes> getAvailableServers(URI uri);
+ Future<OTEMasterServerResult> addServer(URI uri, OTEServer server);
+ Future<OTEMasterServerResult> removeServer(URI uri, OTEServer server);
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java
new file mode 100644
index 0000000000..1909e9ac10
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerAvailableNodes.java
@@ -0,0 +1,27 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public class OTEMasterServerAvailableNodes extends OTEMasterServerResult {
+
+ private List<OTEServer> oteServers;
+
+ public OTEMasterServerAvailableNodes(){
+ oteServers = new ArrayList<OTEServer>();
+ }
+
+ public List<OTEServer> getServers(){
+ return oteServers;
+ }
+
+ public void setServers(OTEServer[] servers) {
+ oteServers.clear();
+ for(OTEServer server:servers){
+ oteServers.add(server);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java
new file mode 100644
index 0000000000..df14451b74
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/OTEMasterServerResult.java
@@ -0,0 +1,21 @@
+package org.eclipse.osee.ote.master.rest.client;
+
+public class OTEMasterServerResult {
+
+ private Throwable th = null;
+ private boolean success = true;
+
+ public Throwable getThrowable() {
+ return th;
+ }
+ public void setThrowable(Throwable th) {
+ this.th = th;
+ }
+ public boolean isSuccess() {
+ return success;
+ }
+ public void setSuccess(boolean success) {
+ this.success = success;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java
new file mode 100644
index 0000000000..6450e61837
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class AddServer implements Callable<OTEMasterServerResult> {
+
+ private WebClientProvider webClientProvider;
+ private OTEServer server;
+ private URI uri;
+
+ public AddServer(WebClientProvider webClientProvider, URI uri, OTEServer server) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ this.server = server;
+ }
+
+ @Override
+ public OTEMasterServerResult call() throws Exception {
+ OTEMasterServerResult result = new OTEMasterServerResult();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).post(server);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java
new file mode 100644
index 0000000000..0ef39942ca
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/GetAvailableServers.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerAvailableNodes;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class GetAvailableServers implements Callable<OTEMasterServerAvailableNodes> {
+
+ private WebClientProvider webClientProvider;
+ private URI uri;
+
+ public GetAvailableServers(WebClientProvider webClientProvider, URI uri) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ }
+
+ @Override
+ public OTEMasterServerAvailableNodes call() throws Exception {
+ OTEMasterServerAvailableNodes result = new OTEMasterServerAvailableNodes();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ OTEServer[] servers = resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).get(OTEServer[].class);
+ result.setServers(servers);
+ result.setSuccess(true);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java
new file mode 100644
index 0000000000..49a65bb364
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/MasterServerCallable.java
@@ -0,0 +1,9 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.util.concurrent.Callable;
+
+public abstract class MasterServerCallable<V> implements Callable<V> {
+
+
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java
new file mode 100644
index 0000000000..533201e202
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java
@@ -0,0 +1,65 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServer;
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerAvailableNodes;
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+public class OTEMasterServerImpl implements OTEMasterServer {
+
+ static final String CONTEXT_NAME = "otemaster";
+ static final String CONTEXT_SERVERS = "servers";
+
+ private WebClientProvider webClientProvider;
+ private ExecutorService executor;
+
+ public OTEMasterServerImpl(){
+ executor = Executors.newCachedThreadPool(new ThreadFactory(){
+ @Override
+ public Thread newThread(Runnable arg0) {
+ Thread th = new Thread(arg0);
+ th.setName("OTE Master Client " + th.getId());
+ th.setDaemon(true);
+ return th;
+ }
+ });
+ }
+
+ public void start(){
+
+ }
+
+ public void stop(){
+
+ }
+
+ public void bindWebClientProvider(WebClientProvider webClientProvider){
+ this.webClientProvider = webClientProvider;
+ }
+
+ public void unbindWebClientProvider(WebClientProvider webClientProvider){
+ this.webClientProvider = null;
+ }
+
+ @Override
+ public Future<OTEMasterServerAvailableNodes> getAvailableServers(URI uri) {
+ return executor.submit(new GetAvailableServers(webClientProvider, uri));
+ }
+
+ @Override
+ public Future<OTEMasterServerResult> addServer(URI uri, OTEServer server) {
+ return executor.submit(new AddServer(webClientProvider, uri, server));
+ }
+
+ @Override
+ public Future<OTEMasterServerResult> removeServer(URI uri, OTEServer server) {
+ return executor.submit(new RemoveServer(webClientProvider, uri, server));
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java
new file mode 100644
index 0000000000..f087640a59
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java
@@ -0,0 +1,38 @@
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.concurrent.Callable;
+
+import javax.ws.rs.core.MediaType;
+
+import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult;
+import org.eclipse.osee.ote.master.rest.model.OTEServer;
+
+import com.sun.jersey.api.client.WebResource;
+
+public class RemoveServer implements Callable<OTEMasterServerResult> {
+
+ private WebClientProvider webClientProvider;
+ private OTEServer server;
+ private URI uri;
+
+ public RemoveServer(WebClientProvider webClientProvider, URI uri, OTEServer server) {
+ this.webClientProvider = webClientProvider;
+ this.uri = uri;
+ this.server = server;
+ }
+
+ @Override
+ public OTEMasterServerResult call() throws Exception {
+ OTEMasterServerResult result = new OTEMasterServerResult();
+ try{
+ WebResource resource = webClientProvider.createResource(uri);
+ resource.path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).accept(MediaType.APPLICATION_XML).delete(server);
+ } catch (Throwable th){
+ result.setSuccess(false);
+ result.setThrowable(th);
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java
new file mode 100644
index 0000000000..65c40e8475
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProvider.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+
+import com.sun.jersey.api.client.AsyncWebResource;
+import com.sun.jersey.api.client.WebResource;
+
+public interface WebClientProvider {
+
+ WebResource createResource(URI uri) throws Exception;
+
+ AsyncWebResource createAsyncResource(URI uri) throws Exception;
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java
new file mode 100644
index 0000000000..8f7fbf77c9
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/WebClientProviderImpl.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ote.master.rest.client.internal;
+
+import java.net.URI;
+import java.util.Map;
+
+import com.sun.jersey.api.client.AsyncWebResource;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.client.apache.ApacheHttpClient;
+import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
+
+public class WebClientProviderImpl implements WebClientProvider {
+
+ private Client client;
+
+ public void start() {
+
+ }
+
+ public void stop() {
+ }
+
+ @Override
+ public WebResource createResource(URI uri) {
+ Client client = createClient(uri);
+ return client.resource(uri);
+ }
+
+ @Override
+ public AsyncWebResource createAsyncResource(URI uri) {
+ Client client = createClient(uri);
+ return client.asyncResource(uri);
+ }
+
+ private Client createClient(URI uri) {
+ if (client == null) {
+ DefaultApacheHttpClientConfig clientConfig = new DefaultApacheHttpClientConfig();
+ Map<String, Object> properties = clientConfig.getProperties();
+
+ properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
+
+ client = ApacheHttpClient.create(clientConfig);
+ }
+ return client;
+ }
+
+} \ No newline at end of file

Back to the top