use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project goci by EBISPOT.
the class EuropepmcPubMedSearchService method createStudyByPubmed.
public EuropePMCData createStudyByPubmed(String pubmedId) throws PubmedLookupException {
EuropePMCData europePMCData = new EuropePMCData();
String urlRequest;
if (europepmcRoot != null && europepmcSearch != null) {
urlRequest = europepmcRoot.concat(europepmcSearch);
} else {
throw new PubmedLookupException("Unable to search pubmed - no URL configured. " + "Set europepmc properties in your config!");
}
String queryUrl = urlRequest.replace("{idlist}", pubmedId);
ResponseEntity<String> out;
RestResponseResult result = new RestResponseResult();
RestTemplate restTemplate = new RestTemplate();
// restTemplate.setErrorHandler(new CustomResponseErrorHandler());
// Add the Jackson message converter
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_HTML);
mediaTypes.add(MediaType.APPLICATION_JSON);
mediaTypes.add(MediaType.ALL);
headers.setAccept(mediaTypes);
// headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON,MediaType.TEXT_HTML));
HttpEntity<Object> entity = new HttpEntity<Object>(headers);
getLog().debug("Querying " + queryUrl);
// and do I need this JSON media type for my use case?
try {
out = restTemplate.exchange(queryUrl, HttpMethod.GET, entity, String.class);
result.setStatus(out.getStatusCode().value());
result.setUrl(queryUrl);
System.out.println(queryUrl);
JsonNode body = new JsonNode(out.getBody().toString());
result.setRestResult(body);
} catch (Exception e) {
throw new PubmedLookupException("EuropePMC : REST API Failed");
}
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(EuropePMCData.class, new EuropePMCDeserializer());
mapper.registerModule(module);
try {
europePMCData = mapper.readValue(result.getRestResult().toString(), EuropePMCData.class);
} catch (IOException ioe) {
System.out.println("EuropePMC : IO Exception - JSON conversion");
throw new PubmedLookupException("EuropePMC : IO Exception - JSON conversion");
} catch (Exception e) {
System.out.println("EuropePMC : Generic Error conversion JSON");
throw new PubmedLookupException("EuropePMC : Generic Error conversion JSON");
}
return europePMCData;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project goci by EBISPOT.
the class DepositionSyncApp method mappingJackson2HttpMessageConverter.
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(getObjectMapper());
converter.setPrettyPrint(true);
return converter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-cloud-microservice-example by kbastani.
the class Application method mappingJackson2HttpMessageConverter.
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.registerModule(new Jackson2HalModule());
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-boot-admin by codecentric.
the class AdminServerWebConfiguration method extendMessageConverters.
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
if (!hasConverter(converters, MappingJackson2HttpMessageConverter.class)) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
}
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project mirrorgate-jira-stories-collector by BBVA.
the class Config method getJiraRestTemplate.
@Bean(JIRA_REST_TEMPLATE)
public RestTemplate getJiraRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
restTemplate.getMessageConverters().add(jsonHttpMessageConverter);
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(jiraUserName, jiraPassword));
return restTemplate;
}
Aggregations