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,5 +2,4 @@ eclipse.preferences.version=1
2 encoding//src/main/java=UTF-8 2 encoding//src/main/java=UTF-8
3 encoding//src/main/resources=UTF-8 3 encoding//src/main/resources=UTF-8
4 encoding//src/test/java=UTF-8 4 encoding//src/test/java=UTF-8
5 -encoding//target/generated-sources=UTF-8  
6 encoding/<project>=UTF-8 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,10 +12,12 @@ import javax.ws.rs.core.MultivaluedMap;
12 import javax.ws.rs.core.Response; 12 import javax.ws.rs.core.Response;
13 13
14 import org.glassfish.jersey.client.ClientProperties; 14 import org.glassfish.jersey.client.ClientProperties;
  15 +import org.glassfish.jersey.jackson.JacksonFeature;
15 import org.slf4j.Logger; 16 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
17 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants; 18 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
18 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException; 19 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  20 +import org.um.dsi.gavea.orcid.client.jackson.JacksonConfigurator;
19 import org.um.dsi.gavea.orcid.client.util.RecordUtil; 21 import org.um.dsi.gavea.orcid.client.util.RecordUtil;
20 import org.um.dsi.gavea.orcid.model.error.Error; 22 import org.um.dsi.gavea.orcid.model.error.Error;
21 23
@@ -84,7 +86,7 @@ public class BaseOrcidOAuthClient implements Serializable { @@ -84,7 +86,7 @@ public class BaseOrcidOAuthClient implements Serializable {
84 Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData)); 86 Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
85 _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus()); 87 _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus());
86 _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase()); 88 _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
87 - 89 +
88 exceptionBuilder(response); 90 exceptionBuilder(response);
89 91
90 return response; 92 return response;
@@ -163,6 +165,8 @@ public class BaseOrcidOAuthClient implements Serializable { @@ -163,6 +165,8 @@ public class BaseOrcidOAuthClient implements Serializable {
163 restClient = ClientBuilder.newClient(); 165 restClient = ClientBuilder.newClient();
164 restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT); 166 restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
165 restClient.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT); 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 target = restClient.target(apiUri).path(buildPath(endpoint, orcidId, putCode)); 172 target = restClient.target(apiUri).path(buildPath(endpoint, orcidId, putCode));
@@ -192,11 +196,9 @@ public class BaseOrcidOAuthClient implements Serializable { @@ -192,11 +196,9 @@ public class BaseOrcidOAuthClient implements Serializable {
192 if (response.getStatus() > 300) { 196 if (response.getStatus() > 300) {
193 if (response.getStatus() == 400) { 197 if (response.getStatus() == 400) {
194 Error error = response.readEntity(Error.class); 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 } else 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 @@ @@ -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 +}