Commit 7909843205f26a255227dd511fb1b886a4a71799

Authored by Luis Pedro
1 parent 32c25351f9
Exists in master and in 1 other branch API_v3.0

C5067

.settings/org.eclipse.core.resources.prefs
... ... @@ -2,5 +2,4 @@ eclipse.preferences.version=1
2 2 encoding//src/main/java=UTF-8
3 3 encoding//src/main/resources=UTF-8
4 4 encoding//src/test/java=UTF-8
5   -encoding//target/generated-sources=UTF-8
6 5 encoding/<project>=UTF-8
... ...
src/main/java/org/um/dsi/gavea/orcid/client/BaseOrcidOAuthClient.java
... ... @@ -12,10 +12,12 @@ import javax.ws.rs.core.MultivaluedMap;
12 12 import javax.ws.rs.core.Response;
13 13  
14 14 import org.glassfish.jersey.client.ClientProperties;
  15 +import org.glassfish.jersey.jackson.JacksonFeature;
15 16 import org.slf4j.Logger;
16 17 import org.slf4j.LoggerFactory;
17 18 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
18 19 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  20 +import org.um.dsi.gavea.orcid.client.jackson.JacksonConfigurator;
19 21 import org.um.dsi.gavea.orcid.client.util.RecordUtil;
20 22 import org.um.dsi.gavea.orcid.model.error.Error;
21 23  
... ... @@ -84,7 +86,7 @@ public class BaseOrcidOAuthClient implements Serializable {
84 86 Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
85 87 _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus());
86 88 _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
87   -
  89 +
88 90 exceptionBuilder(response);
89 91  
90 92 return response;
... ... @@ -163,6 +165,8 @@ public class BaseOrcidOAuthClient implements Serializable {
163 165 restClient = ClientBuilder.newClient();
164 166 restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
165 167 restClient.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT);
  168 + restClient.register(JacksonFeature.class);
  169 + restClient.register(JacksonConfigurator.class);
166 170 }
167 171  
168 172 target = restClient.target(apiUri).path(buildPath(endpoint, orcidId, putCode));
... ... @@ -192,11 +196,9 @@ public class BaseOrcidOAuthClient implements Serializable {
192 196 if (response.getStatus() > 300) {
193 197 if (response.getStatus() == 400) {
194 198 Error error = response.readEntity(Error.class);
195   - throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(),
196   - error.getDeveloperMessage());
  199 + throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(), error.getDeveloperMessage());
197 200 } else
198   - throw new OrcidClientException(response.getStatus(),
199   - response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
  201 + throw new OrcidClientException(response.getStatus(), response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
200 202 }
201 203 }
202 204  
... ...
src/main/java/org/um/dsi/gavea/orcid/client/jackson/JacksonConfigurator.java
... ... @@ -0,0 +1,34 @@
  1 +/**
  2 + * Universidade do Minho
  3 + * Departamento de Sistemas de Informação
  4 + * Grupo Gávea
  5 + */
  6 +package org.um.dsi.gavea.orcid.client.jackson;
  7 +
  8 +import javax.ws.rs.ext.ContextResolver;
  9 +import javax.ws.rs.ext.Provider;
  10 +
  11 +import com.fasterxml.jackson.databind.DeserializationFeature;
  12 +import com.fasterxml.jackson.databind.ObjectMapper;
  13 +
  14 +/**
  15 +* @author Luís Pedro
  16 +*
  17 +* Created: 10 Oct 2018 - 15:27:59
  18 +*/
  19 +@Provider
  20 +public class JacksonConfigurator implements ContextResolver<ObjectMapper> {
  21 +
  22 + private final ObjectMapper mapper;
  23 +
  24 + public JacksonConfigurator() {
  25 + mapper = new ObjectMapper();
  26 + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  27 + }
  28 +
  29 + @Override
  30 + public ObjectMapper getContext(Class<?> type) {
  31 + return mapper;
  32 + }
  33 +
  34 +}
... ...