Search in sources :

Example 6 with HttpComponentsClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsClientHttpRequestFactory in project spring-framework by spring-projects.

the class RequestPartIntegrationTests method setup.

@Before
public void setup() {
    ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
    emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
    List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
    converters.add(emptyBodyConverter);
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter());
    AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
    converter.setPartConverters(converters);
    restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    restTemplate.setMessageConverters(Collections.singletonList(converter));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ArrayList(java.util.ArrayList) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Before(org.junit.Before)

Example 7 with HttpComponentsClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsClientHttpRequestFactory in project OpenClinica by OpenClinica.

the class RandomizationRegistrar method getRandomizationDTOObject.

// Rest Call to OCUI to get Randomization
public SeRandomizationDTO getRandomizationDTOObject(String studyOid) {
    String ocUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
    String randomizationUrl = CoreResources.getField("moduleManager") + "/app/rest/oc/se_randomizations?studyoid=" + studyOid + "&instanceurl=" + ocUrl;
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setReadTimeout(RANDOMIZATION_READ_TIMEOUT);
    RestTemplate rest = new RestTemplate(requestFactory);
    try {
        SeRandomizationDTO response = rest.getForObject(randomizationUrl, SeRandomizationDTO.class);
        if (response.getStudyOid() != null) {
            return response;
        } else {
            return null;
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        System.out.println(e.getMessage());
        System.out.println(ExceptionUtils.getStackTrace(e));
    }
    return null;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) MessagingException(javax.mail.MessagingException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MailException(org.springframework.mail.MailException)

Example 8 with HttpComponentsClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsClientHttpRequestFactory in project OpenClinica by OpenClinica.

the class ParticipantPortalRegistrar method loadRegistrationStatus.

private String loadRegistrationStatus(String studyOid) {
    String ocUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
    String pManageUrl = CoreResources.getField("portalURL") + "/app/rest/oc/authorizations?studyoid=" + studyOid + "&instanceurl=" + ocUrl;
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setReadTimeout(PARTICIPATE_READ_TIMEOUT);
    RestTemplate rest = new RestTemplate(requestFactory);
    try {
        Authorization[] response = rest.getForObject(pManageUrl, Authorization[].class);
        if (response.length > 0 && response[0].getAuthorizationStatus() != null)
            return response[0].getAuthorizationStatus().getStatus();
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.debug(ExceptionUtils.getStackTrace(e));
    }
    return "";
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) MalformedURLException(java.net.MalformedURLException)

Example 9 with HttpComponentsClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsClientHttpRequestFactory in project OpenClinica by OpenClinica.

the class ParticipantPortalRegistrar method getAuthorization.

public Authorization getAuthorization(String studyOid) {
    String ocUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
    String pManageUrl = CoreResources.getField("portalURL") + "/app/rest/oc/authorizations?studyoid=" + studyOid + "&instanceurl=" + ocUrl;
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setReadTimeout(PARTICIPATE_READ_TIMEOUT);
    RestTemplate rest = new RestTemplate(requestFactory);
    try {
        Authorization[] response = rest.getForObject(pManageUrl, Authorization[].class);
        if (response.length > 0 && response[0].getAuthorizationStatus() != null)
            return response[0];
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return null;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) MalformedURLException(java.net.MalformedURLException)

Example 10 with HttpComponentsClientHttpRequestFactory

use of org.springframework.http.client.HttpComponentsClientHttpRequestFactory in project OpenClinica by OpenClinica.

the class ParticipantPortalRegistrar method sendEmailThruMandrillViaOcui.

public String sendEmailThruMandrillViaOcui(ParticipantDTO participantDTO, String hostname) {
    String host = hostname.substring(0, hostname.indexOf("/#/login"));
    String pManageUrl = host + "/app/rest/oc/email";
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setReadTimeout(PARTICIPATE_READ_TIMEOUT);
    RestTemplate rest = new RestTemplate(requestFactory);
    try {
        ParticipantDTO response = rest.postForObject(pManageUrl, participantDTO, ParticipantDTO.class);
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return "";
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ParticipantDTO(org.akaza.openclinica.bean.login.ParticipantDTO) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) MalformedURLException(java.net.MalformedURLException)

Aggregations

HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)33 Test (org.junit.Test)18 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)16 RestTemplate (org.springframework.web.client.RestTemplate)16 HttpClient (org.apache.http.client.HttpClient)14 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)14 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)13 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)11 URI (java.net.URI)9 IOException (java.io.IOException)7 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)7 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)7 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)6 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)6 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)6 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)6 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)6 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)6 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)6 MalformedURLException (java.net.MalformedURLException)6