@Action("/pay/alipayWAP")
 public void alipayWAP() {
   if (payment()) {
     try {
       LOG.info("alipayWAP request init data:" + alipayWAPPostData.getRequestParams());
       // 获取授权令牌
       AlipayWAPResponseResult resResult = getRequestToken();
       log.info(StringUtil.printParam(resResult));
       String businessResult = "";
       if (resResult.isSuccess()) {
         businessResult = resResult.getBusinessResult();
       } else {
         // 授权令牌错误
         String errorMessage =
             "errorCode:"
                 + resResult.getErrorMessage().getCode()
                 + ",subErrorCode:"
                 + resResult.getErrorMessage().getSubCode()
                 + ",errorMsg:"
                 + resResult.getErrorMessage().getMsg()
                 + ",errorDetail:"
                 + resResult.getErrorMessage().getDetail();
         log.error(errorMessage);
         PayPayment payment = new PayPayment();
         payment.setPaymentTradeNo(alipayWAPPostData.getOutTradeNo());
         payment.setCallbackInfo(errorMessage);
         payment.setCallbackTime(new Date());
         getPayPaymentService().callBackPayPayment(payment, false);
         return;
       }
       XMap xmap = new XMap();
       xmap.register(AlipayWAPDirectTradeCreateRes.class);
       AlipayWAPDirectTradeCreateRes directTradeCreateRes =
           (AlipayWAPDirectTradeCreateRes)
               xmap.load(
                   new ByteArrayInputStream(
                       businessResult.getBytes(alipayWAPPostData.getCharset())));
       String requestToken = directTradeCreateRes.getRequestToken();
       // 封装交易参数
       Map<String, String> authParams = alipayWAPPostData.initExecuteParams(requestToken);
       String redirectURL = alipayWAPPostData.getReqUrl() + "?" + AlipayUtil.mapToUrl(authParams);
       log.info("redirectURL:" + redirectURL);
       // sendAjaxMsg(redirectURL);
       // getRequest().getRequestDispatcher(redirectURL).forward(getRequest(), getResponse());
       getResponse().sendRedirect(redirectURL);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
  public void addExtension(String target, String point, List<Object> contribs) throws Exception {
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    // create root element
    Element root = doc.createElement("extension");
    root.setAttribute("target", target);
    root.setAttribute("point", point);
    doc.appendChild(root);

    XMap xmap = new XMap();
    for (Object contrib : contribs) {
      xmap.register(contrib.getClass());
      xmap.toXML(contrib, root);
    }
    extensions.add(DOMSerializer.toStringOmitXml(root));
  }
 public Object[] loadContributions(RegistrationInfo owner, Extension extension) throws Exception {
   Object[] contribs = extension.getContributions();
   if (contribs != null) {
     // contributions already computed - this should e an overloaded (extended) extension point
     return contribs;
   }
   // should compute now the contributions
   if (contributions != null) {
     if (xmap == null) {
       xmap = new XMap();
       for (Class contrib : contributions) {
         xmap.register(contrib);
       }
     }
     contribs = xmap.loadAll(new XMapContext(extension.getContext()), extension.getElement());
     extension.setContributions(contribs);
   }
   return contribs;
 }
 /**
  * 解析获取的授权令牌
  *
  * @author ZHANG Nan
  * @param responseStr
  * @return
  * @throws Exception
  */
 private AlipayWAPResponseResult praseResult(String responseStr) throws Exception {
   AlipayWAPResponseResult result = new AlipayWAPResponseResult();
   if (responseStr.contains("<err>")) {
     result.setSuccess(false);
     String businessResult = AlipayUtil.getParameter(responseStr, "res_error");
     // 转换错误信息
     XMap xmap = new XMap();
     xmap.register(AlipayWAPErrorCode.class);
     AlipayWAPErrorCode errorCode =
         (AlipayWAPErrorCode)
             xmap.load(
                 new ByteArrayInputStream(
                     businessResult.getBytes(alipayWAPPostData.getCharset())));
     result.setErrorMessage(errorCode);
   } else {
     result.setSuccess(true);
     result.setBusinessResult(AlipayUtil.getParameter(responseStr, "res_data"));
   }
   return result;
 }
  @Test
  public void testBuildAndParse() throws Exception {

    String termsAndConditions = "You have to be crazy to use this package";

    PackageBuilder builder = new PackageBuilder();
    builder.name("nuxeo-automation").version("5.3.2").type(PackageType.ADDON);
    builder.platform("dm-5.3.2");
    builder.platform("dam-5.3.2");
    builder.dependency("nuxeo-core:5.3.1:5.3.2");
    builder.dependency("nuxeo-runtime:5.3.1");
    builder.title("Nuxeo Automation");
    builder.description(
        "A service that enable building complex business logic on top of Nuxeo services using scriptable operation chains");
    builder.classifier("Open Source");
    builder.vendor("Nuxeo");
    builder.installer(InstallTask.class.getName(), true);
    builder.uninstaller(UninstallTask.class.getName(), true);
    builder.addLicense("My test license. All rights reserved.");
    File file = File.createTempFile("nxinstall-file-", ".tmp");
    Framework.trackFile(file, builder);
    File tofile = File.createTempFile("nxinstall-tofile-", ".tmp");
    Framework.trackFile(tofile, builder);
    builder.addInstallScript(
        "<install>\n  <copy file=\""
            + file.getAbsolutePath()
            + "\" tofile=\""
            + tofile.getAbsolutePath()
            + "\" overwrite=\"true\"/>\n</install>\n");

    builder.addTermsAndConditions(termsAndConditions);
    builder.hotReloadSupport(true);
    builder.supported(true);
    builder.validationState(NuxeoValidationState.INPROCESS);
    builder.productionState(ProductionState.PRODUCTION_READY);
    builder.requireTermsAndConditionsAcceptance(true);
    builder.visibility(PackageVisibility.MARKETPLACE);

    // test on package def
    String manifest = builder.buildManifest();
    // System.out.println(manifest);
    XMap xmap = StandaloneUpdateService.createXmap();
    InputStream xmlIn = new ByteArrayInputStream(manifest.getBytes());
    PackageDefinitionImpl packageDef = (PackageDefinitionImpl) xmap.load(xmlIn);
    assertEquals("nuxeo-automation", packageDef.getName());
    assertEquals("Nuxeo", packageDef.getVendor());
    assertEquals(NuxeoValidationState.INPROCESS, packageDef.getValidationState());
    assertEquals(ProductionState.PRODUCTION_READY, packageDef.getProductionState());
    assertTrue(packageDef.requireTermsAndConditionsAcceptance());
    assertTrue(packageDef.isSupported());
    assertTrue(packageDef.supportsHotReload());
    assertEquals(PackageVisibility.MARKETPLACE, packageDef.getVisibility());

    // test on real unziped package
    File zipFile = builder.build();
    String tmpDirPath =
        System.getProperty("java.io.tmpdir") + "/TestPkg" + System.currentTimeMillis();
    File tmpDir = new File(tmpDirPath);
    tmpDir.mkdirs();
    ZipUtils.unzip(zipFile, tmpDir);
    LocalPackage pkg = new LocalPackageImpl(tmpDir, PackageState.REMOTE, service);
    Framework.trackFile(tmpDir, pkg);
    assertEquals(termsAndConditions, pkg.getTermsAndConditionsContent());
    assertEquals("nuxeo-automation", pkg.getName());
    assertEquals("Nuxeo", pkg.getVendor());
    assertEquals(NuxeoValidationState.INPROCESS, pkg.getValidationState());
    assertEquals(ProductionState.PRODUCTION_READY, pkg.getProductionState());
    assertTrue(pkg.requireTermsAndConditionsAcceptance());
    assertTrue(pkg.isSupported());
    assertTrue(pkg.supportsHotReload());
    assertEquals(PackageVisibility.MARKETPLACE, pkg.getVisibility());
  }