Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-06-10 18:27:50 +0000
committerRoberto E. Escobar2014-08-28 23:58:34 +0000
commit56ed1da4a2ae6d59e163e7b4ae1fd05df0ec5775 (patch)
tree3d3647cdbd778e3689d081a429a06691b77eea95 /plugins/org.eclipse.osee.account.rest.client
parent21a3c5b7427ef9991dc88c1e8b498bc8d59f84e7 (diff)
downloadorg.eclipse.osee-56ed1da4a2ae6d59e163e7b4ae1fd05df0ec5775.tar.gz
org.eclipse.osee-56ed1da4a2ae6d59e163e7b4ae1fd05df0ec5775.tar.xz
org.eclipse.osee-56ed1da4a2ae6d59e163e7b4ae1fd05df0ec5775.zip
bug[ats_ATS64246]: Fix JAX-RS Client server address config
Use OSGI style properties to configure JAX-RS clients Setup JAX-RS Client as a static factory library instead of OSGI service. Change-Id: Icd6798214da9264670a46f134638bd0b41963fb8
Diffstat (limited to 'plugins/org.eclipse.osee.account.rest.client')
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml3
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java6
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java30
-rw-r--r--plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java33
4 files changed, 33 insertions, 39 deletions
diff --git a/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml b/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml
index 85b25f48752..b7f7404b4c2 100644
--- a/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml
+++ b/plugins/org.eclipse.osee.account.rest.client/OSGI-INF/account.rest.client.xml
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" modified="update">
<implementation class="org.eclipse.osee.account.rest.client.internal.AccountClientImpl"/>
<service>
<provide interface="org.eclipse.osee.account.rest.client.AccountClient"/>
</service>
- <reference bind="setJaxRsClient" cardinality="1..1" interface="org.eclipse.osee.jaxrs.client.JaxRsClient" name="JaxRsClient" policy="static"/>
</scr:component>
diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java
index f0afbf58795..6f92a29d103 100644
--- a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java
+++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/AccountClientStandaloneSetup.java
@@ -10,9 +10,9 @@
*******************************************************************************/
package org.eclipse.osee.account.rest.client;
+import java.util.Map;
import org.eclipse.osee.account.rest.client.internal.AccountClientImpl;
import org.eclipse.osee.account.rest.client.internal.AccountClientModule;
-import org.eclipse.osee.jaxrs.client.OseeClientConfig;
import org.eclipse.osee.jaxrs.client.JaxRsClientFactory;
import com.google.inject.Module;
@@ -27,8 +27,8 @@ public final class AccountClientStandaloneSetup {
// Utility class
}
- public static AccountClient createClient(OseeClientConfig config) {
- Module module = new AccountClientModule();
+ public static AccountClient createClient(Map<String, Object> config) {
+ Module module = new AccountClientModule(config);
return JaxRsClientFactory.createClient(AccountClientImpl.class, config, module);
}
}
diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java
index 04485d28b33..336cf5f6913 100644
--- a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java
+++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientImpl.java
@@ -10,9 +10,11 @@
*******************************************************************************/
package org.eclipse.osee.account.rest.client.internal;
+import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_SERVER_ADDRESS;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.MediaType;
@@ -33,8 +35,8 @@ import org.eclipse.osee.account.rest.model.SubscriptionData;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.type.ResultSets;
import org.eclipse.osee.jaxrs.client.JaxRsClient;
-import org.eclipse.osee.jaxrs.client.OseeClientProperties;
-import com.google.inject.Inject;
+import org.eclipse.osee.jaxrs.client.JaxRsClientFactory;
+import org.eclipse.osee.jaxrs.client.JaxRsClientUtils;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
@@ -44,25 +46,29 @@ import com.sun.jersey.api.client.WebResource;
*/
public class AccountClientImpl implements AccountClient {
+ private static final String OSEE_APPLICATION_SERVER = "osee.application.server";
private JaxRsClient client;
- private URI serverUri;
- @Inject
- public void setJaxRsClient(JaxRsClient client) {
- this.client = client;
+ public void start(Map<String, Object> properties) {
+ update(properties);
}
- public void start() {
- String appServer = OseeClientProperties.getApplicationServerAddress();
- serverUri = URI.create(appServer);
+ public void stop() {
+ client = null;
}
- public void stop() {
- //
+ public void update(Map<String, Object> properties) {
+ Map<String, Object> propsToUse = properties;
+ String newServerAddress = JaxRsClientUtils.get(propsToUse, JAXRS_CLIENT_SERVER_ADDRESS, null);
+ if (newServerAddress == null) {
+ propsToUse = new HashMap<String, Object>(properties);
+ propsToUse.put(JAXRS_CLIENT_SERVER_ADDRESS, System.getProperty(OSEE_APPLICATION_SERVER, ""));
+ }
+ client = JaxRsClientFactory.createClient(propsToUse);
}
private UriBuilder newBuilder() {
- return UriBuilder.fromUri(serverUri).path(AccountContexts.ACCOUNTS);
+ return UriBuilder.fromPath(AccountContexts.ACCOUNTS);
}
private <T> T get(URI uri, Class<T> clazz) {
diff --git a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java
index aa70fb9f854..195035fda66 100644
--- a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java
+++ b/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java
@@ -10,11 +10,11 @@
*******************************************************************************/
package org.eclipse.osee.account.rest.client.internal;
+import java.util.Map;
import org.eclipse.osee.account.rest.client.AccountClient;
+import org.eclipse.osee.jaxrs.client.JaxRsClientUtils;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
-import com.google.inject.matcher.AbstractMatcher;
-import com.google.inject.matcher.Matcher;
import com.google.inject.spi.InjectionListener;
import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;
@@ -24,6 +24,13 @@ import com.google.inject.spi.TypeListener;
*/
public class AccountClientModule extends AbstractModule {
+ private final Map<String, Object> config;
+
+ public AccountClientModule(Map<String, Object> config) {
+ super();
+ this.config = config;
+ }
+
@Override
protected void configure() {
bind(AccountClient.class).to(AccountClientImpl.class);
@@ -36,30 +43,12 @@ public class AccountClientModule extends AbstractModule {
@Override
public void afterInjection(I injectee) {
AccountClientImpl client = (AccountClientImpl) injectee;
- client.start();
+ client.start(config);
}
});
}
};
- bindListener(subtypeOf(AccountClientImpl.class), listener);
- }
-
- private static Matcher<? super TypeLiteral<?>> subtypeOf(Class<?> superclass) {
- return new SubTypeOfMatcher(TypeLiteral.get(AccountClientImpl.class));
- }
-
- private static final class SubTypeOfMatcher extends AbstractMatcher<TypeLiteral<?>> {
- private final TypeLiteral<AccountClientImpl> superType;
-
- public SubTypeOfMatcher(TypeLiteral<AccountClientImpl> superType) {
- super();
- this.superType = superType;
- }
-
- @Override
- public boolean matches(TypeLiteral<?> subType) {
- return subType.equals(superType) || superType.getRawType().isAssignableFrom(subType.getRawType());
- }
+ bindListener(JaxRsClientUtils.subtypeOf(AccountClient.class), listener);
}
}

Back to the top