Commit 7584f8eb7072f6d8736fe3049a31a1be2673ff9f

Authored by Luís Pedro
1 parent 63d5dc1600

only one webresource instance

src/main/java/org/um/dsi/gavea/orcid/client/BaseOrcidOAuthClient.java
... ... @@ -44,26 +44,13 @@ public class BaseOrcidOAuthClient implements Serializable {
44 44 this.clientSecret = clientSecret;
45 45 this.redirectUri = redirectUri;
46 46 }
47   -
48   - protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData) throws OrcidClientException {
49   - createConnection(OrcidConstants.ENDPOINT_OAUTH_TOKEN, null, null);
50   -
51   - Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
52   - _log.debug("[getAccessTokens].[Response.Status] " + response.getStatus());
53   - _log.debug("[getAccessTokens].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
54   -
55   - exceptionBuilder(response);
56   -
57   - return response;
58   - }
59   -
  47 +
60 48 protected <T> Response get(final String endpoint, final OrcidAccessToken token, final String putCode) throws OrcidClientException {
61   - Response response;
  49 + Response response = null;
62 50 try {
63 51 createConnection(endpoint, token.getOrcid(), putCode);
64 52  
65   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
66   - .header("Authorization", "Bearer" + token.getAccess_token()).get();
  53 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).get();
67 54 _log.debug("[get].[Response.Status] " + response.getStatus());
68 55 _log.debug("[get].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
69 56  
... ... @@ -76,6 +63,18 @@ public class BaseOrcidOAuthClient implements Serializable {
76 63 return response;
77 64 }
78 65  
  66 + protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData) throws OrcidClientException {
  67 + createConnection(OrcidConstants.ENDPOINT_OAUTH_TOKEN, null, null);
  68 +
  69 + Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
  70 + _log.debug("[getAccessTokens].[Response.Status] " + response.getStatus());
  71 + _log.debug("[getAccessTokens].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  72 +
  73 + exceptionBuilder(response);
  74 +
  75 + return response;
  76 + }
  77 +
79 78 protected <T> Response post(final String endpoint, final OrcidAccessToken token, final Entity<T> entity) throws OrcidClientException {
80 79 Response response;
81 80 try {
... ... @@ -133,15 +132,13 @@ public class BaseOrcidOAuthClient implements Serializable {
133 132 return response;
134 133 }
135 134  
136   -
137 135 private void createConnection(final String endpoint, final String orcidId, final String putCode) {
138   - if (client != null)
139   - client.close();
140   -
141   - client = ClientBuilder.newClient();
142   - client.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
143   - client.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT);
144   -
  136 + if (client == null) {
  137 + client = ClientBuilder.newClient();
  138 + client.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
  139 + client.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT);
  140 + }
  141 +
145 142 target = client.target(apiUri).path(buildPath(endpoint, orcidId, putCode));
146 143 }
147 144  
... ...