Search in sources :

Example 31 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project portal by ixinportal.

the class APIServiceTest method upload.

// @Test
public void upload() {
    String url = "http://192.168.101.246:8080/portal/api/auth/upload";
    // String url = "http://124.205.224.179:9018/portal/api/auth/upload";
    String appId = "6175a9f8ae6c46";
    String orderNumber = "20180103155436353349";
    String image1 = this.getImgBase64();
    String image2 = null;
    String type = "6";
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("appId", appId);
    map.add("orderNumber", orderNumber);
    map.add("image1", image1);
    // map.add("image2", image2);
    map.add("type", type);
    try {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Signature", "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(appId + orderNumber + image1 + image2 + type, "961cd91d5f7e4e658c2a133febf6cb5d"), false));
        System.out.println(Base64.encode(HMACSHA1.getHmacSHA1(getParam(), "961cd91d5f7e4e658c2a133febf6cb5d"), false));
        HttpEntity httpEntity = new HttpEntity(map, headers);
        ResponseEntity<String> resStr = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        System.out.println("statusCode:" + resStr.getStatusCode());
        System.out.println("body:" + resStr.getBody());
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project portal by ixinportal.

the class APIServiceTest method searchTest.

// @Test
public void searchTest() {
    String url = "http://124.205.224.179:9018/portal/api/auth/search";
    String appId = "41327e98e63e40";
    String orderNumber = "20180115105237670994";
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("appId", appId);
    map.add("orderNumber", orderNumber);
    try {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Signature", "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(appId + orderNumber, "71fe63307ea64d698655452d8f99ff12"), false));
        System.out.println(Base64.encode(HMACSHA1.getHmacSHA1(appId + orderNumber, "71fe63307ea64d698655452d8f99ff12"), false));
        HttpEntity httpEntity = new HttpEntity(map, headers);
        ResponseEntity<String> resStr = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        System.out.println("statusCode:" + resStr.getStatusCode());
        System.out.println("body:" + resStr.getBody());
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 33 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project portal by ixinportal.

the class CertServiceTest method testSm2.

// @Test
public void testSm2() {
    String url = "http://127.0.0.1:8080/portal/cert/make/sm2";
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("csr", "MIHVMHoCAQAwGDEWMBQGA1UEAxMNaVRydXNVS0VZIFNESzBZMBMGByqGSM49AgEGCCqBHM9VAYItA0IABCIF8ZOhgigFw6loNoM3y6Qh17/QkxNqjmPBZ/TlmcvqaIn8EWPhLT4W7AzKSc/CoY31oK1LfpuC1LcFDxqY3R6gADAMBggqgRzPVQGDdQUAA0kAMEYCIQCsmotzp7xI8JbZUClqeIGIpfD/rmuY51uHM0zkUEndUAIhAJPXkPB13inIxaX8ECWifUS7FNnFbXY1D3qkicmDTApj");
    map.add("userName", "zhanghl");
    map.add("userEmail", "zhang@sina.com");
    map.add("period", 10);
    try {
        HttpHeaders headers = new HttpHeaders();
        // headers.add("authHmac", Base64.encode(HMACSHA1.getHmacSHA1(csr+billId+uid+userId, "xe3T+vTjGaSORTtfN2/KnQjfmlY="), false));
        // System.out.println(Base64.encode(HMACSHA1.getHmacSHA1(csr+billId+uid+userId, "xe3T+vTjGaSORTtfN2/KnQjfmlY="), false));
        HttpEntity httpEntity = new HttpEntity(map, headers);
        ResponseEntity<String> resStr = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        System.out.println("statusCode:" + resStr.getStatusCode());
        System.out.println("body:" + resStr.getBody());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 34 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project portal by ixinportal.

the class DownVerifyTest method testName.

@Test
public void testName() throws Exception {
    String url = "http://192.168.100.104:5082/storage/download";
    String buid = "2cbf89ea555841b5a9b3fbd6b693e640";
    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("buid", buid);
    try {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization", AuthService.getHeader().get("Authorization"));
        HttpEntity httpEntity = new HttpEntity(map, headers);
        ResponseEntity<String> resStr = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        System.out.println("statusCode:" + resStr.getStatusCode());
        System.out.println("body:" + resStr.getBody());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) JSONObject(com.alibaba.fastjson.JSONObject) Test(org.junit.Test)

Example 35 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project portal by ixinportal.

the class GetRaInfoTask method getRaInfo.

/**
 * 定时获取RA信息的定时器 心跳更新。启动时执行一次,之后每一天执行一次 1000*60*60*24
 * @Scheduled(fixedRate = 1000 * 60 * 60 * 24)
 * 设置为每天凌晨2点触发
 * @Scheduled(cron = "0 0 2 * * ?")
 */
@Scheduled(cron = "0 0 2 * * ?")
public void getRaInfo() {
    // 系统是否配置同步ra信息主机
    SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
    if (null == sysConfigHost) {
        // LogUtil.syslog(sqlSession, type, info);
        return;
    }
    String host = sysConfigHost.getConfig();
    host = host.replaceAll(" ", "");
    String[] hosts = host.split(",");
    // 获取本机主机名称
    InetAddress ia = null;
    try {
        ia = ia.getLocalHost();
    } catch (UnknownHostException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return;
    }
    String hostName = ia.getHostName();
    boolean flag = false;
    for (String str : hosts) {
        if (hostName.equals(str.replaceAll(" ", ""))) {
            flag = true;
        }
    }
    // 判断本地主机名称是否与系统配置的ra信息同步主机名称一致,不一致则返回
    if (!flag) {
        // LogUtil.syslog(sqlSession, type, info);
        return;
    }
    // 系统是否配置同步ra信息开关
    SysConfig sysConfig = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "openGetRaInfo");
    if (null == sysConfig) {
        // LogUtil.syslog(sqlSession, type, info);
        return;
    }
    if (sysConfig.getConfig().equals("false")) {
        // LogUtil.syslog(sqlSession, type, info);
        return;
    }
    // 系统是否配置同步ra信息地址
    SysConfig sysConfigurl = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoUrl");
    if (null == sysConfigurl) {
        String type = "同步RA信息错误";
        String info = "系统未配置RA信息同步地址";
        LogUtil.syslog(sqlSession, type, info);
        return;
    }
    // if(!isSyncGetRa()){
    // return;
    // }
    // 证书ID的最大值
    Integer maxCertId = 0;
    // 每次更新的数目,默认是1000
    Integer limit = 1000;
    // 每天同步的数量
    Integer everyDayNum = 1;
    // 每天需要同步的次数
    Integer count = 0;
    // 每天成功同步的信息数量
    successNum = new AtomicInteger(0);
    SysConfig sysConfigNum = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoNum");
    if (null != sysConfigNum && StringUtils.isNotBlank(sysConfigNum.getConfig())) {
        everyDayNum = Integer.parseInt(sysConfigNum.getConfig());
    } else {
        String type = "同步RA信息";
        String info = "系统未配置RA信息同步数量";
        LogUtil.syslog(sqlSession, type, info);
    }
    // 请求的url
    String url = sysConfigurl.getConfig() + "/getRaList.jsp";
    String limitString = limit.toString();
    // 计算需要同步的次数
    count = (everyDayNum + limit - 1) / limit;
    for (int i = 0; i < count; i++) {
        maxCertId = sqlSession.selectOne("com.itrus.portal.db.RaInfoMapper.selectMaxCertId");
        if (null == maxCertId || maxCertId < 1) {
            maxCertId = 0;
        }
        String maxCertIdString = maxCertId.toString();
        // 设置请求参数
        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
        map.add("certId", maxCertIdString);
        map.add("limit", limitString);
        try {
            // 发送请求
            String resStr = restTemplate.postForObject(url, map, String.class);
            // 解析响应信息
            List<Map<String, Object>> list = jsonTool.readValue(resStr, List.class);
            // 获取状态信息,0为错误,1为成功
            Map<String, Object> statusMap = list.get(list.size() - 1);
            Integer status = (Integer) statusMap.get("status");
            if (0 == status) {
                String type = "同步RA信息错误";
                String info = (String) statusMap.get("message");
                LogUtil.syslog(sqlSession, type, info);
                return;
            } else {
                insertRaInfosIntoDB(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
            String type = "同步RA信息出现异常";
            String info = "成功同步:" + successNum + "条信息,异常信息:" + e.getMessage();
            LogUtil.syslog(sqlSession, type, info);
            log.error("ERRORLOG同步RA信息 {}", info);
            return;
        }
    }
    String type = "同步RA信息成功";
    String info = "成功同步:" + successNum + "条信息";
    LogUtil.syslog(sqlSession, type, info);
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) UnknownHostException(java.net.UnknownHostException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) UnknownHostException(java.net.UnknownHostException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)413 Test (org.junit.Test)153 HttpHeaders (org.springframework.http.HttpHeaders)126 MultiValueMap (org.springframework.util.MultiValueMap)94 Test (org.junit.jupiter.api.Test)88 HttpEntity (org.springframework.http.HttpEntity)60 List (java.util.List)42 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)40 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)37 HashMap (java.util.HashMap)36 MediaType (org.springframework.http.MediaType)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 URI (java.net.URI)33 Map (java.util.Map)31 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)30 ArrayList (java.util.ArrayList)27 UUID (java.util.UUID)27 lombok.val (lombok.val)27 IOException (java.io.IOException)26 Assert (org.junit.Assert)25