Search in sources :

Example 66 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCopyTest method testCopyAllChildren.

/**
     * Test for SLING-2415 Ability to move all child nodes, without the parent node
     * Using :applyTo value of "*"
     */
public void testCopyAllChildren() throws IOException {
    final String testPath = TEST_BASE_PATH + "/cpmultwc/" + System.currentTimeMillis();
    final String testRoot = testClient.createNode(HTTP_BASE_URL + testPath, null);
    // create multiple source nodes
    Map<String, String> props = new HashMap<String, String>();
    props.put("text", "Hello");
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src1", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src2", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src3", props);
    testClient.createNode(HTTP_BASE_URL + testPath + "/test/src4", props);
    // create destination parent
    testClient.createNode(HTTP_BASE_URL + testPath + "/dest", props);
    // copy the src? nodes
    List<NameValuePair> nvPairs = new ArrayList<NameValuePair>();
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_APPLY_TO, "*"));
    // we expect success
    assertPostStatus(testRoot + "/test", HttpServletResponse.SC_OK, nvPairs, "Expecting Copy Success");
    // assert existence of the src?/text properties
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src1/text", HttpServletResponse.SC_OK);
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src2/text", HttpServletResponse.SC_OK);
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src3/text", HttpServletResponse.SC_OK);
    assertHttpStatus(HTTP_BASE_URL + testPath + "/dest/src4/text", HttpServletResponse.SC_OK);
    testClient.delete(testRoot);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 67 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCopyTest method testCopyNodeAbsoluteBelowDest.

public void testCopyNodeAbsoluteBelowDest() throws IOException {
    final String testPath = TEST_BASE_PATH + "/abs/" + System.currentTimeMillis();
    Map<String, String> props = new HashMap<String, String>();
    props.put("text", "Hello");
    testClient.createNode(HTTP_BASE_URL + testPath + "/src", props);
    // first test: failure because dest (parent) does not exist
    List<NameValuePair> nvPairs = new ArrayList<NameValuePair>();
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY));
    nvPairs.add(new NameValuePair(SlingPostConstants.RP_DEST, testPath + "/dest/"));
    assertPostStatus(HTTP_BASE_URL + testPath + "/src", HttpServletResponse.SC_PRECONDITION_FAILED, nvPairs, "Expecting Copy Failure (dest must exist)");
    // create dest as parent
    testClient.createNode(HTTP_BASE_URL + testPath + "/dest", null);
    // copy now succeeds to below dest
    assertPostStatus(HTTP_BASE_URL + testPath + "/src", HttpServletResponse.SC_CREATED, nvPairs, "Expecting Copy Success");
    // assert content at new location
    String content = getContent(HTTP_BASE_URL + testPath + "/dest.-1.json", CONTENT_TYPE_JSON);
    assertJavascript("Hello", content, "out.println(data.src.text)");
    // assert content at old location
    content = getContent(HTTP_BASE_URL + testPath + "/src.json", CONTENT_TYPE_JSON);
    assertJavascript("Hello", content, "out.println(data.text)");
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 68 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCopyTest method testCopyAncestor.

/** Copying an ancestor to a descendant should fail */
public void testCopyAncestor() throws IOException {
    final String testPath = TEST_BASE_PATH + "/tcanc/" + System.currentTimeMillis();
    final String testRoot = testClient.createNode(HTTP_BASE_URL + testPath, null);
    final String parentPath = testPath + "/a/b";
    final String childPath = parentPath + "/child";
    final String parentUrl = testClient.createNode(HTTP_BASE_URL + parentPath, null);
    assertFalse("child node must not exist before copy", getContent(parentUrl + ".2.json", CONTENT_TYPE_JSON).contains("child"));
    final List<NameValuePair> opt = new ArrayList<NameValuePair>();
    opt.add(new NameValuePair(SlingPostConstants.RP_OPERATION, SlingPostConstants.OPERATION_COPY));
    opt.add(new NameValuePair(SlingPostConstants.RP_DEST, childPath));
    final int expectedStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    assertPostStatus(testRoot, expectedStatus, opt, "Expecting status " + expectedStatus);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList)

Example 69 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class PostServletCreateTest method testCreatingNodeUnderFile.

public void testCreatingNodeUnderFile() throws IOException {
    final String baseWebDavUrl = WEBDAV_BASE_URL + "/CreateFileTest";
    testClient.mkdir(baseWebDavUrl);
    final String testFile = "/integration-test/testfile.txt";
    final InputStream data = getClass().getResourceAsStream(testFile);
    final String webdavUrl = baseWebDavUrl + "/" + System.currentTimeMillis() + ".txt";
    try {
        assertNotNull("Local test file " + testFile + " must be found", data);
        // Upload a file via WebDAV, verify, delete and verify
        assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist before test");
        int status = testClient.upload(webdavUrl, data);
        assertEquals("upload must return status code 201", 201, status);
        assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after upload");
    } finally {
        if (data != null) {
            data.close();
        }
    }
    final String childUrl = webdavUrl + "/*";
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    list.add(new NameValuePair(":nameHint", "child"));
    list.add(new NameValuePair("prop", "value"));
    list.add(new NameValuePair("jcr:primaryType", "nt:unstructured"));
    assertPostStatus(childUrl, 500, list, "Response to creating a child under nt:file should fail.");
// we shouldn't check for a specific exception as that one is implementation specific (see SLING-2763)
// a result of 500 is enough.
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList)

Example 70 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project portal by ixinportal.

the class BaiWangTask method query.

/**
 * 、 CA 申请记录查询接口服务
 *2.1、 请求报文
 *接口说明: 用于第三方开票服务商查看已提交的企业 CA 申请结果信息
 *调用方式: HTTPS 请求方式 POST 请求
 *测试环境 URL:
 *https://ip:port/Entoauth/thirdInviceService?sign=caResult&xml=
 *<REQUEST>
 *<HEAD>
 *<client_id>企业的 client_id</client_id>
 *<access_token>二.1 接口获取到</access_token>
 *<openID>二.2 接口获取到</openID>
 *</HEAD>
 *<BODY>
 *<SQM>代办 CA 授权码</SQM>
 *<TAX_REGISTER_NO>企业证件号码</TAX_REGISTER_NO>
 *</BODY>
 *</REQUEST>
 */
// 2.订单状态
@Scheduled(cron = "0 0/10 * * * ?")
public void query() {
    synchronized (BaiWangTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        if (!isConnection() || !isBaiWangDanJiConnection()) {
            initBaiWang();
        }
        List<ExtraProduct> products = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = null;
        try {
            // 1.先判断有没有该接口类型的产品,没有则返回
            products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_BWFPTPT);
            if (null == products || products.isEmpty()) {
                return;
            }
            for (ExtraProduct product : products) {
                // 筛选是该产品,并且订单状态是服务商审核中
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("productId", product.getId());
                paramMap.put("isquery", 1);
                paramMap.put("desc", 1);
                // 2.查找是该产品的订单,并且订单状态是已支付,待服务商审核的订单.然后遍历订单信息
                List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_BAIWANG", paramMap);
                if (null == Extrabills || Extrabills.isEmpty()) {
                    continue;
                }
                Integer count = 0;
                Integer count_danji = 0;
                Map resultMap = new HashMap<>();
                for (Map<String, Object> bill : Extrabills) {
                    Long id = (Long) bill.get("id");
                    Boolean is_sendfpt = (Boolean) bill.get("is_sendfpt");
                    Boolean is_passfpt = (Boolean) bill.get("is_passfpt");
                    Boolean is_senddj = (Boolean) bill.get("is_senddj");
                    Boolean is_passdj = (Boolean) bill.get("is_passdj");
                    // 其他附加信息
                    // 营业执照
                    BusinessLicense businessLicense = businessService.getBusinessByExtraBillId(id, null);
                    // 企业信息
                    Enterprise enterprise = enterpriseService.getEnterpriseById((Long) bill.get("enterprise"));
                    // 开户行信息
                    OpenBankInfo openBankInfo = openBankInfoService.getOpenBankInfoByExtraBillId(id, null);
                    // 税务登记
                    TaxRegisterCert taxRegisterCert = taxCertService.getTaxRegisterCertByExtraBillId(id, null);
                    // 0:税号 1:信用代码号
                    Integer credentialsType = null;
                    if (null != businessLicense && businessLicense.getBusinessType().equals(1)) {
                        credentialsType = 1;
                    } else if (null != taxRegisterCert) {
                        credentialsType = 0;
                    }
                    String TAX_REGISTER_NO = credentialsType == 1 ? businessLicense.getLicenseNo() : taxRegisterCert.getCertNo();
                    String param2 = "";
                    try {
                        if (null != is_sendfpt && is_sendfpt.equals(true) && ((null == is_passfpt || is_passfpt.equals(false)))) {
                            /**
                             * 、 CA 申请记录查询接口服务
                             *							2.1、 请求报文
                             *							接口说明: 用于第三方开票服务商查看已提交的企业 CA 申请结果信息
                             *							调用方式: HTTPS 请求方式 POST 请求
                             *							测试环境 URL:
                             *							https://ip:port/Entoauth/thirdInviceService?sign=caResult&xml=
                             *							<REQUEST>
                             *							<HEAD>
                             *							<client_id>企业的 client_id</client_id>
                             *							<access_token>二.1 接口获取到</access_token>
                             *							<openID>二.2 接口获取到</openID>
                             *							</HEAD>
                             *							<BODY>
                             *							<SQM>代办 CA 授权码</SQM>
                             *							<TAX_REGISTER_NO>企业证件号码</TAX_REGISTER_NO>
                             *							</BODY>
                             *							</REQUEST>
                             */
                            param2 = "<REQUEST><HEAD>" + "<client_id>" + client_id + "</client_id>" + "<access_token>" + access_token + "</access_token>" + "<openID>" + openID + "</openID>" + "</HEAD>" + "<BODY>" + "<SQM>" + SQM + "</SQM>" + "<TAX_REGISTER_NO>" + TAX_REGISTER_NO + "</TAX_REGISTER_NO>" + "</BODY>" + "</REQUEST>";
                            String param = URLEncoder.encode(new String(Base64.encode(param2.getBytes())), "UTF-8");
                            LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
                            String urlAccessToken = baseUrl + "thirdInvoiceService";
                            URI uri;
                            uri = new URI(urlAccessToken);
                            map.add("sign", "caResult");
                            map.add("xml", param);
                            String xml = restTemplate.postForObject(uri, map, String.class);
                            resultMap = parseXml(xml);
                            String recode = resultMap.get("REPLYCODE").toString();
                            ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                            if (StringUtils.isNotBlank(recode) && recode.equals("0000")) {
                                // 当单机的已经审核通过之后,才能修改订单状态
                                if (null != extraBill.getIsPassdj() && extraBill.getIsPassdj().equals(true)) {
                                    if (null != extraBill.geteInvoice()) {
                                        // 订单需要开票.判断是否开票了.
                                        Boolean isinvoiced = extraBill.getIsInvoiced();
                                        if (null == isinvoiced || isinvoiced.equals(false)) {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_6);
                                        } else {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                            extraBill.setFinishTime(new Date());
                                        }
                                    } else {
                                        // 订单不需要开票,直接完成
                                        extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                        extraBill.setFinishTime(new Date());
                                    }
                                    extraBill.setCheckTime(new Date());
                                }
                                extraBill.setIsPassfpt(true);
                                is_passfpt = true;
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                count++;
                            } else if (StringUtils.isNotBlank(recode) && recode.equals("0003")) {
                                extraBill.setRefuseReason(resultMap.get("REPLYMSG").toString());
                                extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_5);
                                extraBill.setIsRefuse(true);
                                extraBill.setIsPassfpt(false);
                                extraBill.setIsSendfpt(false);
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                log.error("审核拒绝_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "拒绝信息:" + resultMap.get("REPLYMSG") + ", 参数:" + param2);
                                LogUtil.syslog(sqlSession, "审核拒绝_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "拒绝信息:" + resultMap.get("REPLYMSG"));
                                count++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("查询订单_百旺发票通", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage() + ", 参数:" + param2);
                        LogUtil.syslog(sqlSession, "查询订单_百旺发票通", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage());
                    }
                    // 查询单机
                    if (null != is_senddj && is_senddj.equals(true) && (null == is_passdj || is_passdj.equals(false))) {
                        StringBuffer stringBuffer = new StringBuffer();
                        String url = dan_ji_url + "/fpfw/api/kpbusiness";
                        /**
                         *								<?xml version="1.0" encoding="utf-8"?>
                         *								<business comment="查询申请结果" id="CXSQJG">
                         *								<head>
                         *								    <login_name><![CDATA[itruschina]]></login_name>
                         *								    <passwd><![CDATA[12345678]]></passwd>
                         *								    <skpbh><![CDATA[ceshi2017071311222333]]></skpbh>
                         *								    <nsrsbh><![CDATA[911101088020176222333]]></nsrsbh>
                         *								</head>
                         *								</business>
                         */
                        stringBuffer.append("<?xml version='1.0' encoding='utf-8'?>");
                        stringBuffer.append("<business comment='查询申请结果' id='CXSQJG'>");
                        stringBuffer.append("<head>");
                        stringBuffer.append("<login_name><![CDATA[" + dan_ji_userName + "]]></login_name>");
                        stringBuffer.append("<passwd><![CDATA[" + dan_ji_passWord + "]]></passwd>");
                        stringBuffer.append("<skpbh><![CDATA[" + openBankInfo.getTaxNumber() + "]]></skpbh>");
                        stringBuffer.append("<nsrsbh><![CDATA[" + enterprise.getNsrsbh() + "]]></nsrsbh>");
                        stringBuffer.append("</head>");
                        stringBuffer.append("</business>");
                        try {
                            resultMap = new HashMap<>();
                            HttpClient client = new HttpClient();
                            client.getHostConfiguration().setHost(dan_ji_url, dan_ji_port, dan_ji_protocol);
                            HttpMethod method = null;
                            PostMethod post = new PostMethod("/fpfw/api/kpbusiness");
                            NameValuePair bw = new NameValuePair("bw", stringBuffer.toString());
                            NameValuePair[] nameValuePairs = { bw };
                            post.setRequestBody(nameValuePairs);
                            method = post;
                            client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
                            method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                            client.executeMethod(method);
                            String xml = new String(method.getResponseBodyAsString().getBytes("UTF-8"));
                            resultMap = parseXml(xml);
                            /**
                             *								 返回报文:
                             *								<?xml version="1.0" encoding="utf-8"?>
                             *								<business id="CXSQJG" version='1.0'>
                             *								<head>
                             *								</head>
                             *								<body>
                             *								<sq_date>申请日期</sq_date>
                             *								<yxqq>有效期起</yxqq>
                             *								<yxqz>有效期止</yxqz>
                             *								<kt_date>开通日期</kt_date>
                             *								<downloadurl>下载地址</downloadurl>
                             *								<returncode>返回</returncode>
                             *								<returnmsg>返回信息</returnmsg>
                             *								</body>
                             *								</business>
                             */
                            String returncode = resultMap.get("returncode").toString();
                            ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                            if (StringUtils.isNotBlank(returncode) && returncode.equals(BW_DANJI_SHEN_HE_TONG_GUO)) {
                                // 当发票通的已经审核通过之后,才能修改订单状态
                                if (null != extraBill.getIsPassfpt() && extraBill.getIsPassfpt().equals(true)) {
                                    if (null != extraBill.geteInvoice()) {
                                        // 订单需要开票.判断是否开票了.
                                        Boolean isinvoiced = extraBill.getIsInvoiced();
                                        if (null == isinvoiced || isinvoiced.equals(false)) {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_6);
                                        } else {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                            extraBill.setFinishTime(new Date());
                                        }
                                    } else {
                                        // 订单不需要开票,直接完成
                                        extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                        extraBill.setFinishTime(new Date());
                                    }
                                    extraBill.setCheckTime(new Date());
                                }
                                extraBill.setIsPassdj(true);
                                is_passdj = true;
                                bwdjRecordService.insertOneRecored(resultMap, extraBill.getId());
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                count_danji++;
                            } else if (StringUtils.isNotBlank(returncode) && returncode.equals(BW_DANJI_SHEN_HE_JU_JUE)) {
                                status = transactionManager.getTransaction(def);
                                String refuseReason = (String) resultMap.get("returnmsg");
                                extraBill.setRefuseReason(refuseReason);
                                refuseDanJi(extraBill);
                                transactionManager.commit(status);
                                log.error("审核拒绝_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + "错误信息:" + resultMap.get("returnmsg") + ", 参数:" + stringBuffer.toString());
                                LogUtil.syslog(sqlSession, "审核拒绝_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + "错误信息:" + resultMap.get("returnmsg"));
                            }
                        } catch (Exception e) {
                            log.error("查询订单_百旺单机", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage() + ", 参数:" + stringBuffer.toString());
                            LogUtil.syslog(sqlSession, "查询订单_百旺单机", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage());
                        }
                    }
                }
                LogUtil.syslog(sqlSession, "查询订单_百旺发票通", "总共:" + Extrabills.size() + "条,成功:" + count + "条");
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "查询订单失败_百旺", "错误信息:" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (status != null && !status.isCompleted()) {
                transactionManager.rollback(status);
            }
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ExtraBill(com.itrus.portal.db.ExtraBill) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) URI(java.net.URI) OpenBankInfo(com.itrus.portal.db.OpenBankInfo) NameValuePair(org.apache.commons.httpclient.NameValuePair) Date(java.util.Date) ExtraProduct(com.itrus.portal.db.ExtraProduct) BusinessLicense(com.itrus.portal.db.BusinessLicense) HttpClient(org.apache.commons.httpclient.HttpClient) Enterprise(com.itrus.portal.db.Enterprise) Map(java.util.Map) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) HttpMethod(org.apache.commons.httpclient.HttpMethod) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8