Search in sources :

Example 46 with RestTemplate

use of org.springframework.web.client.RestTemplate in project portal by ixinportal.

the class WeixinUtil method initRestTemplate.

// 自定义restTemplate
// @PostConstruct
public void initRestTemplate() {
    restTemplate = new RestTemplate(httpClientFactory);
    List<HttpMessageConverter<?>> messageConverters = new ArrayList();
    messageConverters.add(new ResourceHttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ArrayList(java.util.ArrayList) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter)

Example 47 with RestTemplate

use of org.springframework.web.client.RestTemplate in project portal by ixinportal.

the class RestTemplateUtils method main.

public static void main(String[] args) throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException {
    CloseableHttpClient httpClient = RestTemplateUtils.acceptsUntrustedCertsHttpClient();
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
    String result = restTemplate.getForObject("http://www.baidu.com", String.class);
    System.out.println(result);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory)

Example 48 with RestTemplate

use of org.springframework.web.client.RestTemplate in project portal by ixinportal.

the class ClientWebControllerTest method testgetAllInfo3.

@Test
public void testgetAllInfo3() {
    try {
        String url = "https://ixin.itrus.com.cn/clientWeb/getProductInfo";
        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
        // 项目id
        map.add("projectName", "宁波CA");
        // 
        map.add("type", 2);
        map.add("certSn", "4A52B8E3B7C7478BEDB2E7732496D699BA627F16");
        map.add("keySn", "TW15031122021634");
        map.add("isregister", 0);
        // enterprise
        map.add("enterprise_enterpriseName", "宁波高新区天威诚信数字证书技术服务有限公司");
        map.add("enterprise_enterpriseSn", "91330201677673485L");
        // map.add("enterprise_orgIndustry", 1);
        map.add("enterprise_enterpriseNature", 1);
        // userInfo
        map.add("userInfo_realName", "张琼艳");
        map.add("userInfo_trustMPhnoe", true);
        map.add("userInfo_trustEmail", true);
        map.add("userInfo_mPhone", "13123801307");
        map.add("userInfo_email", "153312045@qq.com");
        map.add("userInfo_telephone", "0574-87324610");
        // map.add("userInfo_userPosition", "java");
        map.add("userInfo_postalCode", "315000");
        map.add("userInfo_regionCodes", "");
        map.add("userInfo_userAdds", "宁波市海曙区华楼街8号");
        map.add("userInfo_orgIndustry", 9);
        // 营业执照businessLicense_
        // 
        map.add("businessLicense_enterpriseName", "宁波高新区天威诚信数字证书技术服务有限公司");
        // 
        map.add("businessLicense_licenseNo", "330215000008195");
        // 是否三证合一,是否三证合一
        map.add("businessLicense_isDateless", false);
        // 住所
        map.add("businessLicense_abode", "宁波高新区院士路66号创业大厦5-41室");
        // 住所
        map.add("businessLicense_businessScope", null);
        // 
        map.add("businessLicense_regFund", "100万元");
        // 
        map.add("businessLicense_operationStart", "2008-08-18 00:00:00");
        // 
        map.add("businessLicense_operationEnd", "2018-08-17 23:59:59");
        // 
        map.add("businessLicense_imgFile", ImageUtils.getImgBase64("/com/itrus/portal/controller/web/test/businessLicense_imgFile.txt"));
        // 组织机构信息
        // 
        map.add("orgCode_enterpriseName", "宁波高新区天威诚信数字证书技术服务有限公司");
        // 
        map.add("orgCode_orgCode", "677673485");
        // 
        map.add("orgCode_imgFile", ImageUtils.getImgBase64("/com/itrus/portal/controller/web/test/orgCode_imgFile.txt"));
        // 税务登记信息taxregisterCert_
        // 
        map.add("taxregisterCert_enterpriseName", "宁波高新区天威诚信数字证书技术服务有限公司");
        // 
        map.add("taxregisterCert_certNo", "330207677673485");
        // 
        map.add("taxregisterCert_imgFile", ImageUtils.getImgBase64("/com/itrus/portal/controller/web/test/taxregisterCert_imgFile.txt"));
        // 法人信息
        // 
        map.add("identityCard_enterpriseName", "宁波高新区天威诚信数字证书技术服务有限公司");
        // 
        map.add("identityCard_idCode", "330103196504191647");
        // 
        map.add("identityCard_name", "胥琳");
        map.add("identityCard_cardType", 1);
        // 
        map.add("identityCard_frontImg", ImageUtils.getImgBase64("/com/itrus/portal/controller/web/test/identityCard_frontImg.txt"));
        // 
        map.add("identityCard_backImg", ImageUtils.getImgBase64("/com/itrus/portal/controller/web/test/identityCard_backImg.txt"));
        CloseableHttpClient httpClient = RestTemplateUtils.acceptsUntrustedCertsHttpClient();
        HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
        RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
        String map2 = restTemplate.postForObject(url, map, String.class);
        System.out.println(map2);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractTest(com.itrus.portal.abstracttest.test.AbstractTest) Test(org.junit.Test)

Example 49 with RestTemplate

use of org.springframework.web.client.RestTemplate in project openmrs-module-pihcore by PIH.

the class RestBiometricEngine method update.

@Override
public BiometricSubject update(BiometricSubject subject) {
    RestTemplate restTemplate = new RestTemplate();
    String url = getSubjectUrl();
    ResponseEntity<BiometricSubject> response = restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<BiometricSubject>(subject), BiometricSubject.class);
    if (HttpStatus.OK.equals(response.getStatusCode()) || HttpStatus.CREATED.equals(response.getStatusCode())) {
        return response.getBody();
    } else {
        throw new IllegalStateException("Error updating biometric subject at URL <" + url + ">.  Response status code: " + response.getStatusCode());
    }
}
Also used : BiometricSubject(org.openmrs.module.registrationcore.api.biometrics.model.BiometricSubject) RestTemplate(org.springframework.web.client.RestTemplate)

Example 50 with RestTemplate

use of org.springframework.web.client.RestTemplate in project openmrs-module-pihcore by PIH.

the class RestBiometricEngine method enroll.

@Override
public BiometricSubject enroll(BiometricSubject subject) {
    RestTemplate restTemplate = new RestTemplate();
    String url = getSubjectUrl();
    ResponseEntity<BiometricSubject> response = restTemplate.postForEntity(url, subject, BiometricSubject.class);
    if (HttpStatus.OK.equals(response.getStatusCode()) || HttpStatus.CREATED.equals(response.getStatusCode())) {
        return response.getBody();
    } else {
        throw new IllegalStateException("Error enrolling biometric subject at URL <" + url + ">.  Response status code: " + response.getStatusCode());
    }
}
Also used : BiometricSubject(org.openmrs.module.registrationcore.api.biometrics.model.BiometricSubject) RestTemplate(org.springframework.web.client.RestTemplate)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)519 Test (org.junit.Test)135 Test (org.junit.jupiter.api.Test)78 HttpHeaders (org.springframework.http.HttpHeaders)77 HttpEntity (org.springframework.http.HttpEntity)76 URI (java.net.URI)73 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)45 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)40 IOException (java.io.IOException)36 Bean (org.springframework.context.annotation.Bean)35 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)32 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)27 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)27 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)22 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)22 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)22