From 56ed1da4a2ae6d59e163e7b4ae1fd05df0ec5775 Mon Sep 17 00:00:00 2001 From: Roberto E. Escobar Date: Tue, 10 Jun 2014 11:27:50 -0700 Subject: 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 --- .../OSGI-INF/account.rest.client.xml | 3 +- .../rest/client/AccountClientStandaloneSetup.java | 6 +- .../rest/client/internal/AccountClientImpl.java | 30 ++++--- .../rest/client/internal/AccountClientModule.java | 33 +++----- .../META-INF/MANIFEST.MF | 2 - .../OSGI-INF/web.client.provider.xml | 7 -- .../org.eclipse.osee.jaxrs.client/build.properties | 4 +- .../osee/jaxrs/client/JaxRsClientConstants.java | 40 +++++++++ .../osee/jaxrs/client/JaxRsClientFactory.java | 17 ++-- .../osee/jaxrs/client/JaxRsClientUtils.java | 65 +++++++++++++++ .../osee/jaxrs/client/OseeClientConfig.java | 46 ---------- .../osee/jaxrs/client/OseeClientProperties.java | 29 ------- .../osee/jaxrs/client/OseeHttpProxyAddress.java | 27 ------ .../osee/jaxrs/client/OseeServerAddress.java | 27 ------ .../jaxrs/client/internal/JaxRsClientImpl.java | 97 ++++++++++++++++++---- .../internal/StandadloneWebClientProvider.java | 41 --------- .../jaxrs/client/internal/StandaloneModule.java | 35 ++++++-- .../OSGI-INF/osee.client.xml | 3 +- .../rest/client/OseeClientStandaloneSetup.java | 6 +- .../rest/client/internal/OrcsClientModule.java | 10 ++- .../orcs/rest/client/internal/OseeClientImpl.java | 49 ++++++----- .../client/internal/search/QueryExecutorV1.java | 10 +-- .../OSGI-INF/ote.master.rest.client.xml | 3 +- .../rest/client/internal/OTEMasterServerImpl.java | 16 ++-- .../OSGI-INF/ote.client.xml | 3 +- .../ote/rest/client/internal/OteClientImpl.java | 16 ++-- .../tests/performance/IntegrationUtil.java | 13 +-- 27 files changed, 335 insertions(+), 303 deletions(-) delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/OSGI-INF/web.client.provider.xml create mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientConstants.java create mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientUtils.java delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientConfig.java delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientProperties.java delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeHttpProxyAddress.java delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeServerAddress.java delete mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandadloneWebClientProvider.java 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 @@ - + - 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 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 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 properties) { + Map propsToUse = properties; + String newServerAddress = JaxRsClientUtils.get(propsToUse, JAXRS_CLIENT_SERVER_ADDRESS, null); + if (newServerAddress == null) { + propsToUse = new HashMap(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 get(URI uri, Class 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 config; + + public AccountClientModule(Map 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> subtypeOf(Class superclass) { - return new SubTypeOfMatcher(TypeLiteral.get(AccountClientImpl.class)); - } - - private static final class SubTypeOfMatcher extends AbstractMatcher> { - private final TypeLiteral superType; - - public SubTypeOfMatcher(TypeLiteral 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); } } diff --git a/plugins/org.eclipse.osee.jaxrs.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.jaxrs.client/META-INF/MANIFEST.MF index 7e38b4d572a..d101cf05a5c 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.jaxrs.client/META-INF/MANIFEST.MF @@ -6,7 +6,6 @@ Bundle-Version: 0.18.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: Eclipse Open System Engineering Environment Bundle-ActivationPolicy: lazy -Service-Component: OSGI-INF/*.xml Import-Package: com.google.inject, com.google.inject.binder, com.google.inject.matcher, @@ -16,7 +15,6 @@ Import-Package: com.google.inject, javax.inject, javax.ws.rs, javax.ws.rs.core, - org.eclipse.core.net.proxy, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.jaxrs diff --git a/plugins/org.eclipse.osee.jaxrs.client/OSGI-INF/web.client.provider.xml b/plugins/org.eclipse.osee.jaxrs.client/OSGI-INF/web.client.provider.xml deleted file mode 100644 index cdd564872f8..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/OSGI-INF/web.client.provider.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/plugins/org.eclipse.osee.jaxrs.client/build.properties b/plugins/org.eclipse.osee.jaxrs.client/build.properties index 6d4f3aa975c..34d2e4d2dad 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/build.properties +++ b/plugins/org.eclipse.osee.jaxrs.client/build.properties @@ -1,6 +1,4 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - .,\ - OSGI-INF/ -additional.bundles = com.sun.jersey + . diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientConstants.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientConstants.java new file mode 100644 index 00000000000..d6a5bf519fc --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientConstants.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2014 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.jaxrs.client; + +/** + * @author Roberto E. Escobar + */ +public final class JaxRsClientConstants { + + private JaxRsClientConstants() { + // Utility class + } + + public static final String NAMESPACE = "jaxrs.client"; + + private static String qualify(String value) { + return String.format("%s.%s", NAMESPACE, value); + } + + public static final boolean DEFAULT_JAXRS_CLIENT_FOLLOW_REDIRECTS = true; + public static final int DEFAULT_JAXRS_CLIENT_THREADPOOL_SIZE = -1; // cached thread pool - no limit + public static final int DEFAULT_JAXRS_CLIENT_CONNECT_TIMEOUT = 30 * 1000; // 30 seconds + public static final int DEFAULT_JAXRS_CLIENT_READ_TIMEOUT = -1; // infinity + + public static final String JAXRS_CLIENT_SERVER_ADDRESS = qualify("server.address"); + public static final String JAXRS_CLIENT_PROXY_SERVER_ADDRESS = qualify("proxy.server.address"); + public static final String JAXRS_CLIENT_FOLLOW_REDIRECTS = qualify("follow.redirects"); + public static final String JAXRS_CLIENT_CONNECT_TIMEOUT = qualify("connect.timeout"); + public static final String JAXRS_CLIENT_READ_TIMEOUT = qualify("read.timeout"); + public static final String JAXRS_CLIENT_THREADPOOL_SIZE = qualify("threadpool.size"); + +} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientFactory.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientFactory.java index 0691f0fd175..181b223b9dd 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientFactory.java +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Boeing. + * Copyright (c) 2014 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 @@ -12,14 +12,13 @@ package org.eclipse.osee.jaxrs.client; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.eclipse.osee.jaxrs.client.internal.StandaloneModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; /** - * Class to use when using the API in a non-OSGI environment - * * @author Roberto E. Escobar */ public final class JaxRsClientFactory { @@ -28,14 +27,18 @@ public final class JaxRsClientFactory { // Utility class } - public static T createClient(Class api, OseeClientConfig config, Module... modules) { - Injector injector = createInjector(config, modules); + public static JaxRsClient createClient(Map props) { + return createClient(JaxRsClient.class, props); + } + + public static T createClient(Class api, Map props, Module... modules) { + Injector injector = createInjector(props, modules); return injector.getInstance(api); } - private static Injector createInjector(OseeClientConfig config, Module... modules) { + private static Injector createInjector(Map props, Module... modules) { List moduleList = new ArrayList(); - moduleList.add(new StandaloneModule(config)); + moduleList.add(new StandaloneModule(props)); for (Module module : modules) { moduleList.add(module); } diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientUtils.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientUtils.java new file mode 100644 index 00000000000..063464cb248 --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClientUtils.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 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.jaxrs.client; + +import java.util.Map; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import com.google.inject.TypeLiteral; +import com.google.inject.matcher.AbstractMatcher; +import com.google.inject.matcher.Matcher; + +/** + * @author Roberto E. Escobar + */ +public final class JaxRsClientUtils { + + private JaxRsClientUtils() { + // Utility class + } + + public static Integer getInt(Map props, String key, int defaultValue) { + String toReturn = get(props, key, String.valueOf(defaultValue)); + return Strings.isNumeric(toReturn) ? Integer.parseInt(toReturn) : -1; + } + + public static boolean getBoolean(Map props, String key, boolean defaultValue) { + String toReturn = get(props, key, String.valueOf(defaultValue)); + return Boolean.parseBoolean(toReturn); + } + + public static String get(Map props, String key, String defaultValue) { + String toReturn = defaultValue; + Object object = props != null ? props.get(key) : null; + if (object != null) { + toReturn = String.valueOf(object); + } + return toReturn; + } + + public static Matcher> subtypeOf(Class superclass) { + return new SubTypeOfMatcher(TypeLiteral.get(superclass)); + } + + private static final class SubTypeOfMatcher extends AbstractMatcher> { + private final TypeLiteral superType; + + public SubTypeOfMatcher(TypeLiteral superType) { + super(); + this.superType = superType; + } + + @Override + public boolean matches(TypeLiteral subType) { + return subType.equals(superType) || superType.getRawType().isAssignableFrom(subType.getRawType()); + } + } + +} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientConfig.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientConfig.java deleted file mode 100644 index a4975f6d80d..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.jaxrs.client; - -/** - * @author Roberto E. Escobar - */ -public class OseeClientConfig { - - private String serverAddress = ""; - private String proxyAddress = ""; - - public OseeClientConfig(String serverAddress) { - this.serverAddress = serverAddress; - } - - public String getServerAddress() { - return serverAddress; - } - - public void setServerAddress(String serverAddress) { - this.serverAddress = serverAddress; - } - - public String getProxyAddress() { - return proxyAddress; - } - - public void setProxyAddress(String proxyAddress) { - this.proxyAddress = proxyAddress; - } - - @Override - public String toString() { - return "OseeClientConfig [serverAddress=" + serverAddress + ", proxyAddress=" + proxyAddress + "]"; - } - -} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientProperties.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientProperties.java deleted file mode 100644 index b974319af35..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeClientProperties.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 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.jaxrs.client; - -/** - * @author Roberto E. Escobar - */ -public final class OseeClientProperties { - - private OseeClientProperties() { - // Utility class - } - - private static final String OSEE_APPLICATION_SERVER = "osee.application.server"; - - public static String getApplicationServerAddress() { - String appServer = System.getProperty(OSEE_APPLICATION_SERVER, ""); - return appServer; - } - -} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeHttpProxyAddress.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeHttpProxyAddress.java deleted file mode 100644 index 9ee0ca6b30d..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeHttpProxyAddress.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.jaxrs.client; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import com.google.inject.BindingAnnotation; - -/** - * @author Roberto E. Escobar - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.PARAMETER}) -@BindingAnnotation -public @interface OseeHttpProxyAddress { - // -} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeServerAddress.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeServerAddress.java deleted file mode 100644 index 3085a768a43..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/OseeServerAddress.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.jaxrs.client; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import com.google.inject.BindingAnnotation; - -/** - * @author Roberto E. Escobar - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD, ElementType.PARAMETER}) -@BindingAnnotation -public @interface OseeServerAddress { - // -} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/JaxRsClientImpl.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/JaxRsClientImpl.java index 30b9bfcbc2c..843b80a89e4 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/JaxRsClientImpl.java +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/JaxRsClientImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Boeing. + * Copyright (c) 2014 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 @@ -10,17 +10,34 @@ *******************************************************************************/ package org.eclipse.osee.jaxrs.client.internal; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.DEFAULT_JAXRS_CLIENT_CONNECT_TIMEOUT; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.DEFAULT_JAXRS_CLIENT_FOLLOW_REDIRECTS; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.DEFAULT_JAXRS_CLIENT_READ_TIMEOUT; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.DEFAULT_JAXRS_CLIENT_THREADPOOL_SIZE; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_CONNECT_TIMEOUT; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_FOLLOW_REDIRECTS; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_PROXY_SERVER_ADDRESS; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_READ_TIMEOUT; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_SERVER_ADDRESS; +import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_THREADPOOL_SIZE; +import static org.eclipse.osee.jaxrs.client.JaxRsClientUtils.get; +import static org.eclipse.osee.jaxrs.client.JaxRsClientUtils.getBoolean; +import static org.eclipse.osee.jaxrs.client.JaxRsClientUtils.getInt; import java.net.URI; import java.util.Map; +import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.jaxrs.ErrorResponse; import org.eclipse.osee.jaxrs.client.JaxRsClient; +import org.eclipse.osee.jaxrs.client.JaxRsClientUtils; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.UniformInterfaceException; 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.ApacheHttpClientConfig; import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig; /** @@ -28,12 +45,19 @@ import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig; */ public class JaxRsClientImpl implements JaxRsClient { - private Client client; + public interface JaxRsClientHolder { + WebResource target(URI uri); + } + + private volatile JaxRsClientHolder client; @Override public WebResource createResource(URI uri) { - Client client = createClient(uri); - return client.resource(uri); + return client.target(uri); + } + + public void configure(Map properties) { + client = newJaxRsClient(properties); } @Override @@ -49,19 +73,62 @@ public class JaxRsClientImpl implements JaxRsClient { return new OseeCoreException(ex, message); } - protected void configure(URI uri, Map properties) { - properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); - } + private JaxRsClientHolder newJaxRsClient(Map props) { + DefaultApacheHttpClientConfig clientConfig = new DefaultApacheHttpClientConfig(); + Map properties = clientConfig.getProperties(); + + String proxyAddress = get(props, JAXRS_CLIENT_PROXY_SERVER_ADDRESS, ""); + if (Strings.isValid(proxyAddress)) { + properties.put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyAddress); + } + + //@formatter:off + properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, getBoolean(props, JAXRS_CLIENT_FOLLOW_REDIRECTS, DEFAULT_JAXRS_CLIENT_FOLLOW_REDIRECTS)); + properties.put(ClientConfig.PROPERTY_THREADPOOL_SIZE, getInt(props, JAXRS_CLIENT_THREADPOOL_SIZE, DEFAULT_JAXRS_CLIENT_THREADPOOL_SIZE)); + properties.put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, minZero(getInt(props, JAXRS_CLIENT_CONNECT_TIMEOUT, DEFAULT_JAXRS_CLIENT_CONNECT_TIMEOUT))); + properties.put(ClientConfig.PROPERTY_READ_TIMEOUT, minZero(getInt(props, JAXRS_CLIENT_READ_TIMEOUT, DEFAULT_JAXRS_CLIENT_READ_TIMEOUT))); + //@formatter:on - private Client createClient(URI uri) { - if (client == null) { - DefaultApacheHttpClientConfig clientConfig = new DefaultApacheHttpClientConfig(); - Map properties = clientConfig.getProperties(); - properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); - configure(uri, properties); - client = ApacheHttpClient.create(clientConfig); + Client delegate = ApacheHttpClient.create(clientConfig); + JaxRsClientHolder toReturn; + String serverAddress = JaxRsClientUtils.get(props, JAXRS_CLIENT_SERVER_ADDRESS, ""); + if (Strings.isValid(serverAddress)) { + toReturn = newClient(delegate, serverAddress); + } else { + toReturn = newClient(delegate); } - return client; + return toReturn; } + private static int minZero(int value) { + return value < 0 ? 0 : value; + } + + private JaxRsClientHolder newClient(final Client delegate) { + return new JaxRsClientHolder() { + + @Override + public WebResource target(URI uri) { + return delegate.resource(uri); + } + }; + } + + private JaxRsClientHolder newClient(final Client delegate, final String serverAddress) { + return new JaxRsClientHolder() { + + private boolean isPartialAddress(URI uri) { + return uri != null && !uri.isAbsolute(); + } + + @Override + public WebResource target(URI uri) { + URI uriToContact = uri; + if (isPartialAddress(uriToContact)) { + uriToContact = UriBuilder.fromUri(serverAddress).path(uri.toASCIIString()).build(); + } + return delegate.resource(uriToContact); + } + }; + } } diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandadloneWebClientProvider.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandadloneWebClientProvider.java deleted file mode 100644 index 009f75631af..00000000000 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandadloneWebClientProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 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.jaxrs.client.internal; - -import java.net.URI; -import java.util.Map; -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.jaxrs.client.OseeHttpProxyAddress; -import com.google.inject.Inject; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.client.apache.config.ApacheHttpClientConfig; - -/** - * @author Roberto E. Escobar - */ -public class StandadloneWebClientProvider extends JaxRsClientImpl { - - private final String proxyAddress; - - @Inject - public StandadloneWebClientProvider(@OseeHttpProxyAddress String proxyAddress) { - this.proxyAddress = proxyAddress; - } - - @Override - protected void configure(URI uri, Map properties) { - properties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); - if (Strings.isValid(proxyAddress)) { - properties.put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyAddress); - } - } - -} diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandaloneModule.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandaloneModule.java index a3c08826cb2..3a62d6247ed 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandaloneModule.java +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/StandaloneModule.java @@ -10,28 +10,45 @@ *******************************************************************************/ package org.eclipse.osee.jaxrs.client.internal; -import org.eclipse.osee.jaxrs.client.OseeClientConfig; -import org.eclipse.osee.jaxrs.client.OseeHttpProxyAddress; -import org.eclipse.osee.jaxrs.client.OseeServerAddress; +import static org.eclipse.osee.jaxrs.client.JaxRsClientUtils.subtypeOf; +import java.util.Map; import org.eclipse.osee.jaxrs.client.JaxRsClient; import com.google.inject.AbstractModule; +import com.google.inject.TypeLiteral; +import com.google.inject.spi.InjectionListener; +import com.google.inject.spi.TypeEncounter; +import com.google.inject.spi.TypeListener; /** * @author Roberto E. Escobar */ public class StandaloneModule extends AbstractModule { - private final OseeClientConfig config; + private final Map props; - public StandaloneModule(OseeClientConfig config) { - this.config = config; + public StandaloneModule(Map props) { + this.props = props; } @Override protected void configure() { - bindConstant().annotatedWith(OseeServerAddress.class).to(config.getServerAddress()); - bindConstant().annotatedWith(OseeHttpProxyAddress.class).to(config.getProxyAddress()); + bind(JaxRsClient.class).to(JaxRsClientImpl.class); - bind(JaxRsClient.class).to(StandadloneWebClientProvider.class); + TypeListener listener = new TypeListener() { + + @Override + public void hear(TypeLiteral type, TypeEncounter encounter) { + encounter.register(new InjectionListener() { + + @Override + public void afterInjection(I injectee) { + JaxRsClientImpl client = (JaxRsClientImpl) injectee; + client.configure(props); + } + }); + } + }; + bindListener(subtypeOf(JaxRsClient.class), listener); } + } diff --git a/plugins/org.eclipse.osee.orcs.rest.client/OSGI-INF/osee.client.xml b/plugins/org.eclipse.osee.orcs.rest.client/OSGI-INF/osee.client.xml index d8217c57541..19a1595ffcc 100644 --- a/plugins/org.eclipse.osee.orcs.rest.client/OSGI-INF/osee.client.xml +++ b/plugins/org.eclipse.osee.orcs.rest.client/OSGI-INF/osee.client.xml @@ -1,8 +1,7 @@ - + - diff --git a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/OseeClientStandaloneSetup.java b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/OseeClientStandaloneSetup.java index 6da5b7e2f4a..42f8a772516 100644 --- a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/OseeClientStandaloneSetup.java +++ b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/OseeClientStandaloneSetup.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.orcs.rest.client; -import org.eclipse.osee.jaxrs.client.OseeClientConfig; +import java.util.Map; import org.eclipse.osee.jaxrs.client.JaxRsClientFactory; import org.eclipse.osee.orcs.rest.client.internal.OrcsClientModule; import org.eclipse.osee.orcs.rest.client.internal.OseeClientImpl; @@ -27,8 +27,8 @@ public final class OseeClientStandaloneSetup { // Utility class } - public static OseeClient createClient(OseeClientConfig config) { - Module module = new OrcsClientModule(); + public static OseeClient createClient(Map config) { + Module module = new OrcsClientModule(config); return JaxRsClientFactory.createClient(OseeClientImpl.class, config, module); } } diff --git a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OrcsClientModule.java b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OrcsClientModule.java index 245802ce930..654ec465bac 100644 --- a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OrcsClientModule.java +++ b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OrcsClientModule.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.orcs.rest.client.internal; +import java.util.Map; import org.eclipse.osee.orcs.rest.client.OseeClient; import com.google.inject.AbstractModule; import com.google.inject.TypeLiteral; @@ -24,6 +25,13 @@ import com.google.inject.spi.TypeListener; */ public class OrcsClientModule extends AbstractModule { + private final Map config; + + public OrcsClientModule(Map config) { + super(); + this.config = config; + } + @Override protected void configure() { bind(OseeClient.class).to(OseeClientImpl.class); @@ -36,7 +44,7 @@ public class OrcsClientModule extends AbstractModule { @Override public void afterInjection(I injectee) { OseeClientImpl client = (OseeClientImpl) injectee; - client.start(); + client.start(config); } }); } diff --git a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OseeClientImpl.java b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OseeClientImpl.java index da8aef52280..66b6a7abc75 100644 --- a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OseeClientImpl.java +++ b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/OseeClientImpl.java @@ -10,15 +10,19 @@ *******************************************************************************/ package org.eclipse.osee.orcs.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.HashMap; import java.util.List; +import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.OseeCodeVersion; import org.eclipse.osee.jaxrs.client.JaxRsClient; -import org.eclipse.osee.jaxrs.client.OseeClientProperties; +import org.eclipse.osee.jaxrs.client.JaxRsClientFactory; +import org.eclipse.osee.jaxrs.client.JaxRsClientUtils; import org.eclipse.osee.orcs.rest.client.OseeClient; import org.eclipse.osee.orcs.rest.client.QueryBuilder; import org.eclipse.osee.orcs.rest.client.internal.search.PredicateFactory; @@ -29,7 +33,6 @@ import org.eclipse.osee.orcs.rest.client.internal.search.QueryExecutorV1.BaseUri import org.eclipse.osee.orcs.rest.client.internal.search.QueryOptions; import org.eclipse.osee.orcs.rest.model.Client; import org.eclipse.osee.orcs.rest.model.search.artifact.Predicate; -import com.google.inject.Inject; import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; @@ -39,24 +42,38 @@ import com.sun.jersey.api.client.WebResource; */ public class OseeClientImpl implements OseeClient, BaseUriBuilder { - private PredicateFactory predicateFactory; - private QueryExecutorV1 executor; + private static final String OSEE_APPLICATION_SERVER = "osee.application.server"; - private JaxRsClient client; + private volatile PredicateFactory predicateFactory; + private volatile QueryExecutorV1 executor; + private volatile JaxRsClient client; - @Inject - public void setJaxRsClient(JaxRsClient client) { - this.client = client; - } - - public void start() { + public void start(Map properties) { predicateFactory = new PredicateFactoryImpl(); - executor = new QueryExecutorV1(client, this); + + update(properties); } public void stop() { - predicateFactory = null; executor = null; + client = null; + predicateFactory = null; + } + + public void update(Map properties) { + Map propsToUse = properties; + String newServerAddress = JaxRsClientUtils.get(propsToUse, JAXRS_CLIENT_SERVER_ADDRESS, null); + if (newServerAddress == null) { + propsToUse = new HashMap(properties); + propsToUse.put(JAXRS_CLIENT_SERVER_ADDRESS, System.getProperty(OSEE_APPLICATION_SERVER, "")); + } + client = JaxRsClientFactory.createClient(propsToUse); + executor = new QueryExecutorV1(client, this); + } + + @Override + public UriBuilder newBuilder() { + return UriBuilder.fromPath("orcs"); } @Override @@ -66,12 +83,6 @@ public class OseeClientImpl implements OseeClient, BaseUriBuilder { return new QueryBuilderImpl(branch, predicates, options, predicateFactory, executor); } - @Override - public UriBuilder newBuilder() { - String serverUri = OseeClientProperties.getApplicationServerAddress(); - return UriBuilder.fromUri(serverUri).path("orcs"); - } - @Override public boolean isClientVersionSupportedByApplicationServer() { boolean result = false; diff --git a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/search/QueryExecutorV1.java b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/search/QueryExecutorV1.java index 38bc14bedf4..54793ebf061 100644 --- a/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/search/QueryExecutorV1.java +++ b/plugins/org.eclipse.osee.orcs.rest.client/src/org/eclipse/osee/orcs/rest/client/internal/search/QueryExecutorV1.java @@ -35,12 +35,12 @@ public class QueryExecutorV1 implements QueryExecutor { UriBuilder newBuilder(); } - private final JaxRsClient clientProvider; + private final JaxRsClient client; private final BaseUriBuilder baseUriBuilder; - public QueryExecutorV1(JaxRsClient clientProvider, BaseUriBuilder baseUriBuilder) { + public QueryExecutorV1(JaxRsClient client, BaseUriBuilder baseUriBuilder) { super(); - this.clientProvider = clientProvider; + this.client = client; this.baseUriBuilder = baseUriBuilder; } @@ -77,14 +77,14 @@ public class QueryExecutorV1 implements QueryExecutor { requestType.name().toLowerCase(), fromTx, includeDeleted); URI uri = getQueryUri(branch.getUuid()); - WebResource resource = clientProvider.createResource(uri); + WebResource resource = client.createResource(uri); SearchResponse searchResult = null; try { searchResult = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post( SearchResponse.class, params); } catch (UniformInterfaceException ex) { - throw clientProvider.handleException(ex); + throw client.handleException(ex); } return searchResult; } 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 index a2fd3832043..6c2a6e593a3 100644 --- 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 @@ -1,8 +1,7 @@ - + - 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 index a395da7fe2d..3456be01f3f 100644 --- 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 @@ -1,11 +1,13 @@ package org.eclipse.osee.ote.master.rest.client.internal; import java.net.URI; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import org.eclipse.osee.jaxrs.client.JaxRsClient; +import org.eclipse.osee.jaxrs.client.JaxRsClientFactory; 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; @@ -16,14 +18,10 @@ public class OTEMasterServerImpl implements OTEMasterServer { static final String CONTEXT_NAME = "otemaster"; static final String CONTEXT_SERVERS = "servers"; - private JaxRsClient client; + private volatile JaxRsClient client; private ExecutorService executor; - public void setJaxRsClient(JaxRsClient client) { - this.client = client; - } - - public void start() { + public void start(Map props) { executor = Executors.newCachedThreadPool(new ThreadFactory() { @Override public Thread newThread(Runnable arg0) { @@ -33,12 +31,18 @@ public class OTEMasterServerImpl implements OTEMasterServer { return th; } }); + update(props); } public void stop() { if (executor != null) { executor.shutdown(); } + client = null; + } + + public void update(Map props) { + client = JaxRsClientFactory.createClient(props); } @Override diff --git a/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml index 8d857e8f933..239d14858d2 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml +++ b/plugins/org.eclipse.osee.ote.rest.client/OSGI-INF/ote.client.xml @@ -1,8 +1,7 @@ - + - diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java index 78b9cd4e6c0..b717364f334 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/OteClientImpl.java @@ -13,11 +13,13 @@ package org.eclipse.osee.ote.rest.client.internal; import java.io.File; import java.net.URI; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; import org.eclipse.osee.jaxrs.client.JaxRsClient; +import org.eclipse.osee.jaxrs.client.JaxRsClientFactory; import org.eclipse.osee.ote.rest.client.OTECacheItem; import org.eclipse.osee.ote.rest.client.OteClient; import org.eclipse.osee.ote.rest.client.Progress; @@ -31,13 +33,9 @@ import org.eclipse.osee.ote.rest.model.OTETestRun; public class OteClientImpl implements OteClient { private ExecutorService executor; - private JaxRsClient client; + private volatile JaxRsClient client; - public void setJaxRsClient(JaxRsClient client) { - this.client = client; - } - - public void start() { + public void start(Map props) { executor = Executors.newCachedThreadPool(new ThreadFactory() { @Override public Thread newThread(Runnable arg0) { @@ -47,12 +45,18 @@ public class OteClientImpl implements OteClient { return th; } }); + update(props); } public void stop() { if (executor != null) { executor.shutdown(); } + client = null; + } + + public void update(Map props) { + client = JaxRsClientFactory.createClient(props); } @Override diff --git a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java index 41f2b0102ce..13ee1d854e7 100644 --- a/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java +++ b/plugins/org.eclipse.osee.x.server.integration.tests/src/org/eclipse/osee/x/server/integration/tests/performance/IntegrationUtil.java @@ -10,13 +10,15 @@ *******************************************************************************/ package org.eclipse.osee.x.server.integration.tests.performance; +import java.util.HashMap; +import java.util.Map; import org.databene.contiperf.junit.ContiPerfRule; import org.databene.contiperf.report.CSVLatencyReportModule; import org.databene.contiperf.report.CSVSummaryReportModule; import org.databene.contiperf.report.HtmlReportModule; import org.eclipse.osee.account.rest.client.AccountClient; import org.eclipse.osee.account.rest.client.AccountClientStandaloneSetup; -import org.eclipse.osee.jaxrs.client.OseeClientConfig; +import org.eclipse.osee.jaxrs.client.JaxRsClientConstants; import org.eclipse.osee.orcs.rest.client.OseeClient; import org.eclipse.osee.orcs.rest.client.OseeClientStandaloneSetup; import org.junit.rules.MethodRule; @@ -35,18 +37,19 @@ public final class IntegrationUtil { } public static OseeClient createClient() { - OseeClientConfig config = createClientConfig(); + Map config = createClientConfig(); return OseeClientStandaloneSetup.createClient(config); } - private static OseeClientConfig createClientConfig() { + private static Map createClientConfig() { + Map config = new HashMap(); String serverAddress = System.getProperty(OSEE_APPLICATION_SERVER, DEFAULT_OSEE_APPLICATION_SERVER); - OseeClientConfig config = new OseeClientConfig(serverAddress); + config.put(JaxRsClientConstants.JAXRS_CLIENT_SERVER_ADDRESS, serverAddress); return config; } public static AccountClient createAccountClient() { - OseeClientConfig config = createClientConfig(); + Map config = createClientConfig(); return AccountClientStandaloneSetup.createClient(config); } -- cgit v1.2.3