diff options
author | Roberto E. Escobar | 2014-06-12 02:11:13 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-08-28 23:58:39 +0000 |
commit | d4a7765ec05b4f124de987004505b5510b50d36a (patch) | |
tree | c9f7e8dca41e9021a4fe9bdcb9659564550493a9 /plugins/org.eclipse.osee.account.rest.client | |
parent | 87185d728b0628e8562b5046ec092eb44ff5ba8c (diff) | |
download | org.eclipse.osee-d4a7765ec05b4f124de987004505b5510b50d36a.tar.gz org.eclipse.osee-d4a7765ec05b4f124de987004505b5510b50d36a.tar.xz org.eclipse.osee-d4a7765ec05b4f124de987004505b5510b50d36a.zip |
feature[ats_ATS55930]: Upgrade JAX-RS to 2.0 API using Apache CXF
Change JAX-RS endpoints to comply with 2.0 API
Change JAX-RS clients to use JAX-RS 2.0 Client API instead
of using Jersey's client implementation.
Remove all Jersey dependencies.
Integrate Apache CXF with OSEE JAX-RS
Change-Id: I866dff8516b91dbcde07b07819cf0bbc89b5d293
Diffstat (limited to 'plugins/org.eclipse.osee.account.rest.client')
4 files changed, 119 insertions, 218 deletions
diff --git a/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF index 5cfc1053951..2292204b7e8 100644 --- a/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.account.rest.client/META-INF/MANIFEST.MF @@ -9,19 +9,13 @@ Import-Package: com.google.inject, com.google.inject.binder, com.google.inject.matcher, com.google.inject.spi, - com.sun.jersey.api.client;version="1.18.0", - com.sun.jersey.api.client.async;version="1.18.0", - com.sun.jersey.api.client.config;version="1.18.0", - com.sun.jersey.api.client.filter;version="1.18.0", - javax.ws.rs, - javax.ws.rs.core, + javax.ws.rs;version="2.0.0", + javax.ws.rs.client;version="2.0.0", + javax.ws.rs.core;version="2.0.0", org.eclipse.osee.account.rest.model, org.eclipse.osee.framework.jdk.core.type, - org.eclipse.osee.jaxrs.client, - org.eclipse.osee.jaxrs + org.eclipse.osee.jaxrs, + org.eclipse.osee.jaxrs.client Export-Package: org.eclipse.osee.account.rest.client Bundle-Vendor: Eclipse Open System Engineering Environment -Require-Bundle: org.codehaus.jackson.core;bundle-version="1.9.2", - org.codehaus.jackson.jaxrs;bundle-version="1.9.2", - org.codehaus.jackson.mapper;bundle-version="1.9.2" Bundle-ActivationPolicy: lazy 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 6f92a29d103..ac2a7f1211f 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 @@ -12,9 +12,6 @@ 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.JaxRsClientFactory; -import com.google.inject.Module; /** * Class to use when using the API in a non-OSGI environment @@ -28,7 +25,8 @@ public final class AccountClientStandaloneSetup { } public static AccountClient createClient(Map<String, Object> config) { - Module module = new AccountClientModule(config); - return JaxRsClientFactory.createClient(AccountClientImpl.class, config, module); + AccountClientImpl client = new AccountClientImpl(); + client.start(config); + return client; } } 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 336cf5f6913..5d0840ad6b3 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,19 +10,30 @@ *******************************************************************************/ package org.eclipse.osee.account.rest.client.internal; -import static org.eclipse.osee.jaxrs.client.JaxRsClientConstants.JAXRS_CLIENT_SERVER_ADDRESS; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNTS; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_ACTIVE; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_ID_PARAM; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_ID_TEMPLATE; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_LOGIN; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_LOGOUT; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_PREFERENCES; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_SESSSIONS; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_USERNAME; +import static org.eclipse.osee.account.rest.model.AccountContexts.ACCOUNT_USERNAME_TEMPLATE; 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.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.account.rest.client.AccountClient; import org.eclipse.osee.account.rest.model.AccountActiveData; -import org.eclipse.osee.account.rest.model.AccountContexts; import org.eclipse.osee.account.rest.model.AccountDetailsData; import org.eclipse.osee.account.rest.model.AccountInfoData; import org.eclipse.osee.account.rest.model.AccountInput; @@ -35,11 +46,7 @@ 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.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; +import org.eclipse.osee.jaxrs.client.JaxRsExceptions; /** * @author Roberto E. Escobar @@ -47,156 +54,127 @@ 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 WebTarget baseTarget; + private WebTarget accountTarget; public void start(Map<String, Object> properties) { update(properties); } public void stop() { - client = null; + baseTarget = null; + accountTarget = null; } 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.fromPath(AccountContexts.ACCOUNTS); - } + JaxRsClient client = JaxRsClient.newBuilder().properties(properties).build(); - private <T> T get(URI uri, Class<T> clazz) { - WebResource resource = client.createResource(uri); - try { - return resource.accept(MediaType.APPLICATION_JSON_TYPE).get(clazz); - } catch (UniformInterfaceException ex) { - throw client.handleException(ex); + String address = properties != null ? (String) properties.get(OSEE_APPLICATION_SERVER) : null; + if (address == null) { + address = System.getProperty(OSEE_APPLICATION_SERVER, ""); } + + URI uri = UriBuilder.fromUri(address).build(); + baseTarget = client.target(uri); + accountTarget = baseTarget.path(ACCOUNTS); } @Override public AccountSessionData login(String scheme, String username, String password) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_LOGIN)// - .build(); - AccountLoginData data = new AccountLoginData(); data.setUsername(username); data.setPassword(password); data.setScheme(scheme); - WebResource resource = client.createResource(uri); + WebTarget resource = accountTarget.path(ACCOUNT_LOGIN); try { - return resource.post(AccountSessionData.class, data); - } catch (UniformInterfaceException ex) { - throw client.handleException(ex); + return resource.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(data), AccountSessionData.class); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } } @Override public boolean logout(AccountSessionData session) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_LOGOUT)// - .build(); - - WebResource resource = client.createResource(uri); - int status; + WebTarget resource = accountTarget.path(ACCOUNT_LOGOUT); try { - ClientResponse response = resource.post(ClientResponse.class, session); - status = response.getStatus(); - } catch (UniformInterfaceException ex) { - ClientResponse clientResponse = ex.getResponse(); - status = clientResponse.getStatus(); - if (Status.NOT_MODIFIED.getStatusCode() != status) { - throw client.handleException(ex); - } + Response response = resource.request().post(Entity.json(session)); + return Status.OK.getStatusCode() == response.getStatus(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } - return Status.OK.getStatusCode() == status; } @Override public AccountInfoData createAccount(String userName, AccountInput input) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_USERNAME_TEMPLATE)// - .build(userName); - - WebResource resource = client.createResource(uri); + WebTarget resource = accountTarget.path(ACCOUNT_USERNAME_TEMPLATE).resolveTemplate(ACCOUNT_USERNAME, userName); try { - AccountInfoData data = - resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).post( - AccountInfoData.class, input); - return data; - } catch (UniformInterfaceException ex) { - throw client.handleException(ex); + return resource.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(input), AccountInfoData.class); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } } @Override public boolean deleteAccount(String accountId) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .build(accountId); - WebResource resource = client.createResource(uri); - - ClientResponse response; + WebTarget resource = accountTarget.path(ACCOUNT_ID_TEMPLATE).resolveTemplate(ACCOUNT_ID_PARAM, accountId); try { - response = resource.delete(ClientResponse.class); - } catch (UniformInterfaceException ex) { - throw client.handleException(ex); + Response response = resource.request().delete(); + return Status.OK.getStatusCode() == response.getStatus(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } - int status = response.getStatus(); - return Status.OK.getStatusCode() == status; } @Override public ResultSet<AccountSessionDetailsData> getAccountSessionDataByUniqueField(String accountId) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE) // - .path(AccountContexts.ACCOUNT_SESSSIONS)// - .build(accountId); - AccountSessionDetailsData[] data = get(uri, AccountSessionDetailsData[].class); - return ResultSets.newResultSet(data); + WebTarget resource = + accountTarget.path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_SESSSIONS).resolveTemplate(ACCOUNT_ID_PARAM, accountId); + try { + AccountSessionDetailsData[] data = + resource.request(MediaType.APPLICATION_JSON_TYPE).get(AccountSessionDetailsData[].class); + return ResultSets.newResultSet(data); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } @Override public ResultSet<AccountInfoData> getAllAccounts() { - URI uri = newBuilder()// - .build(); - AccountInfoData[] accounts = get(uri, AccountInfoData[].class); - return ResultSets.newResultSet(accounts); + try { + AccountInfoData[] accounts = + accountTarget.request(MediaType.APPLICATION_JSON_TYPE).get(AccountInfoData[].class); + return ResultSets.newResultSet(accounts); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } @Override public AccountDetailsData getAccountDetailsByUniqueField(String accountId) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .build(accountId); - return get(uri, AccountDetailsData.class); + WebTarget resource = accountTarget.path(ACCOUNT_ID_TEMPLATE).resolveTemplate(ACCOUNT_ID_PARAM, accountId); + try { + return resource.request(MediaType.APPLICATION_JSON_TYPE).get(AccountDetailsData.class); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } @Override public AccountPreferencesData getAccountPreferencesByUniqueField(String accountId) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .path(AccountContexts.ACCOUNT_PREFERENCES)// - .build(accountId); - AccountPreferencesData data = get(uri, AccountPreferencesData.class); - return data; + WebTarget resource = + accountTarget.path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_PREFERENCES).resolveTemplate(ACCOUNT_ID_PARAM, accountId); + try { + return resource.request(MediaType.APPLICATION_JSON_TYPE).get(AccountPreferencesData.class); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } @Override public boolean setAccountActive(String accountId, boolean active) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .path(AccountContexts.ACCOUNT_ACTIVE)// - .build(accountId); - WebResource resource = client.createResource(uri); + WebTarget resource = + accountTarget.path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_ACTIVE).resolveTemplate(ACCOUNT_ID_PARAM, accountId); boolean result; if (active) { result = setAccountActive(resource); @@ -208,79 +186,63 @@ public class AccountClientImpl implements AccountClient { @Override public boolean isAccountActive(String accountId) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .path(AccountContexts.ACCOUNT_ACTIVE)// - .build(accountId); - AccountActiveData data = get(uri, AccountActiveData.class); - return data.isActive(); + WebTarget resource = + accountTarget.path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_ACTIVE).resolveTemplate(ACCOUNT_ID_PARAM, accountId); + try { + AccountActiveData data = resource.request(MediaType.APPLICATION_JSON_TYPE).get(AccountActiveData.class); + return data.isActive(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } - private boolean setAccountActive(WebResource resource) { - int status; + private boolean setAccountActive(WebTarget resource) { try { - ClientResponse response = resource.put(ClientResponse.class); - status = response.getStatus(); - } catch (UniformInterfaceException ex) { - ClientResponse clientResponse = ex.getResponse(); - status = clientResponse.getStatus(); - if (Status.NOT_MODIFIED.getStatusCode() != status) { - throw client.handleException(ex); - } + Response response = resource.request().put(null); + return Status.OK.getStatusCode() == response.getStatus(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } - return Status.OK.getStatusCode() == status; } - private boolean setAccountInActive(WebResource resource) { - int status; + private boolean setAccountInActive(WebTarget resource) { try { - ClientResponse response = resource.delete(ClientResponse.class); - status = response.getStatus(); - } catch (UniformInterfaceException ex) { - ClientResponse clientResponse = ex.getResponse(); - status = clientResponse.getStatus(); - if (Status.NOT_MODIFIED.getStatusCode() != status) { - throw client.handleException(ex); - } + Response response = resource.request().delete(); + return Status.OK.getStatusCode() == response.getStatus(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } - return Status.OK.getStatusCode() == status; } @Override public boolean setAccountPreferences(String accountId, Map<String, String> preferences) { - URI uri = newBuilder()// - .path(AccountContexts.ACCOUNT_ID_TEMPLATE)// - .path(AccountContexts.ACCOUNT_PREFERENCES)// - .build(accountId); + WebTarget resource = + accountTarget.path(ACCOUNT_ID_TEMPLATE).path(ACCOUNT_PREFERENCES).resolveTemplate(ACCOUNT_ID_PARAM, accountId); AccountPreferencesInput input = new AccountPreferencesInput(); input.setMap(preferences); - - WebResource resource = client.createResource(uri); - int status; try { - ClientResponse response = resource.put(ClientResponse.class, input); - status = response.getStatus(); - } catch (UniformInterfaceException ex) { - ClientResponse clientResponse = ex.getResponse(); - status = clientResponse.getStatus(); - if (Status.NOT_MODIFIED.getStatusCode() != status) { - throw client.handleException(ex); - } + Response response = resource.request().put(Entity.json(input)); + return Status.OK.getStatusCode() == response.getStatus(); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); } - return Status.OK.getStatusCode() == status; } private ResultSet<SubscriptionData> getSubscriptionsForAccount(String userId) { - URI uri = - newBuilder().path("subscriptions").path("for-account").path("{account-id}").build( - userId); - SubscriptionData[] data = get(uri, SubscriptionData[].class); - return ResultSets.newResultSet(data); + WebTarget resource = + baseTarget.path("subscriptions/for-account/{account-id}").resolveTemplate(ACCOUNT_ID_PARAM, userId); + Builder builder = resource.request(MediaType.APPLICATION_JSON_TYPE); + try { + SubscriptionData[] data = builder.get(SubscriptionData[].class); + return ResultSets.newResultSet(data); + } catch (Exception ex) { + throw JaxRsExceptions.asOseeException(ex); + } } private UriBuilder newUnsubscribeBuilder() { - return newBuilder().path("unsubscribe").path("ui").path("{subscription-uuid}"); + return baseTarget.getUriBuilder().path("unsubscribe").path("ui").path("{subscription-uuid}"); } @Override @@ -289,6 +251,7 @@ public class AccountClientImpl implements AccountClient { ResultSet<SubscriptionData> results = getSubscriptionsForAccount(userUuid); if (!results.isEmpty()) { List<UnsubscribeInfo> infos = new ArrayList<UnsubscribeInfo>(); + UriBuilder builder = newUnsubscribeBuilder(); for (SubscriptionData subscription : results) { if (subscription.isActive() && groupNames.contains(subscription.getName())) { 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 deleted file mode 100644 index 195035fda66..00000000000 --- a/plugins/org.eclipse.osee.account.rest.client/src/org/eclipse/osee/account/rest/client/internal/AccountClientModule.java +++ /dev/null @@ -1,54 +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.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.spi.InjectionListener; -import com.google.inject.spi.TypeEncounter; -import com.google.inject.spi.TypeListener; - -/** - * @author Roberto E. Escobar - */ -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); - TypeListener listener = new TypeListener() { - - @Override - public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { - encounter.register(new InjectionListener<I>() { - - @Override - public void afterInjection(I injectee) { - AccountClientImpl client = (AccountClientImpl) injectee; - client.start(config); - } - }); - } - }; - bindListener(JaxRsClientUtils.subtypeOf(AccountClient.class), listener); - } - -} |