コード例 #1
0
  protected void runScript(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    String language = ParamUtil.getString(actionRequest, "language");
    String script = ParamUtil.getString(actionRequest, "script");

    PortletContext portletContext = portletConfig.getPortletContext();

    Map<String, Object> portletObjects =
        ScriptingUtil.getPortletObjects(
            portletConfig, portletContext, actionRequest, actionResponse);

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(unsyncByteArrayOutputStream);

    portletObjects.put("out", unsyncPrintWriter);

    try {
      SessionMessages.add(actionRequest, "language", language);
      SessionMessages.add(actionRequest, "script", script);

      ScriptingUtil.exec(null, portletObjects, language, script);

      unsyncPrintWriter.flush();

      SessionMessages.add(actionRequest, "scriptOutput", unsyncByteArrayOutputStream.toString());
    } catch (ScriptingException se) {
      SessionErrors.add(actionRequest, ScriptingException.class.getName(), se);

      _log.error(se.getMessage());
    }
  }
コード例 #2
0
  @Override
  public PrintWriter getWriter() throws IOException {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getWriter();
    } else {
      return UnsyncPrintWriterPool.borrow(new NullServletOutputStream());
    }
  }
コード例 #3
0
  @Override
  public InputStream getLoadIndexesInputStreamFromCluster(long companyId, Address bootupAddress) {

    if (!isLoadIndexFromClusterEnabled()) {
      return null;
    }

    InputStream inputStream = null;

    try {
      ObjectValuePair<String, URL> bootupClusterNodeObjectValuePair =
          _getBootupClusterNodeObjectValuePair(bootupAddress);

      URL url = bootupClusterNodeObjectValuePair.getValue();

      URLConnection urlConnection = url.openConnection();

      urlConnection.setDoOutput(true);

      UnsyncPrintWriter unsyncPrintWriter =
          UnsyncPrintWriterPool.borrow(urlConnection.getOutputStream());

      unsyncPrintWriter.write("transientToken=");
      unsyncPrintWriter.write(bootupClusterNodeObjectValuePair.getKey());
      unsyncPrintWriter.write("&companyId=");
      unsyncPrintWriter.write(String.valueOf(companyId));

      unsyncPrintWriter.close();

      inputStream = urlConnection.getInputStream();

      return inputStream;
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
コード例 #4
0
  @Override
  public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {

    long orderId = ParamUtil.getLong(request, PaypalConstants.PARAM_INVOICE);
    String status = ParamUtil.getString(request, PaypalConstants.PAYMENT_STATUS);

    LOG.info(String.format(LOG_NOTIFICATION, orderId, status));

    ShoppingOrder order = ShoppingOrderLocalServiceUtil.fetchShoppingOrder(orderId);
    List<ShoppingOrderItem> items = ShoppingOrderItemLocalServiceUtil.findByOrderId(orderId);

    if (items.isEmpty()) {
      LOG.error(String.format(LOG_UNKNOWN_ORDER, orderId));
      return null;
    }

    List<String> itemsIds = new ArrayList<String>();
    for (ShoppingOrderItem item : items) {
      itemsIds.add(Long.toString(item.getItemId()));
    }

    String query = PaypalConstants.PARAM_CMD + "=" + PaypalConstants.CMD_VALIDATE;

    Enumeration<String> enu = request.getParameterNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();
      String value = request.getParameter(name);
      if (LOG.isDebugEnabled()) LOG.debug(String.format(LOG_DEBUG_PARAM, name, value));
      query = query + "&" + name + "=" + HttpUtil.encodeURL(value);
    }

    if (LOG.isDebugEnabled()) LOG.debug(String.format(LOG_DEBUG_QUERY, query));

    URL url = new URL(PaypalConstants.PAYPAL_ENDPOINT);

    URLConnection urlc = url.openConnection();

    urlc.setDoOutput(true);
    urlc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    PrintWriter pw = UnsyncPrintWriterPool.borrow(urlc.getOutputStream());

    pw.println(query);

    pw.close();

    UnsyncBufferedReader unsyncBufferedReader =
        new UnsyncBufferedReader(new InputStreamReader(urlc.getInputStream()));

    String payPalStatus = unsyncBufferedReader.readLine();

    unsyncBufferedReader.close();

    LOG.info(String.format(LOG_STATUS_RESPONSE, payPalStatus));

    if (payPalStatus.equals(PaypalConstants.TRANSACTION_VERIFIED)
        && status.equals(PaypalConstants.PAYMENT_COMPLETE)) {

      LOG.info(LOG_TRX_VERIFIED);

      order.setOrderStatus(OrderStatusEnum.PAID.toString());
      ShoppingOrderLocalServiceUtil.updateOrder(order);

      EmailNotificationUtil.sendEmailNotification(orderId);

    } else {
      LOG.error(LOG_TRX_ERROR);
    }

    return "/portal/paypal.jsp";
  }