Example #1
0
 public void ifCmd(Element elem) throws TestCaseException {
   String isRun = replaceParam(elem.getAttributeValue("condition"));
   if (isRun != null && !isRun.equals("") && Boolean.valueOf(isRun)) {
     List<Element> children = UtilGenerics.cast(elem.getChildren());
     this.runCommands(children);
   } else {
     Element child = elem.getChild("else");
     List<Element> children = UtilGenerics.cast(child.getChildren());
     this.runCommands(children);
   }
 }
Example #2
0
  public static Map<String, Object> convertOrderIdListToHeaders(
      DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();

    List<GenericValue> orderHeaderList = UtilGenerics.checkList(context.get("orderHeaderList"));
    List<String> orderIdList = UtilGenerics.checkList(context.get("orderIdList"));

    // we don't want to process if there is already a header list
    if (orderHeaderList == null) {
      // convert the ID list to headers
      if (orderIdList != null) {
        List<EntityCondition> conditionList1 = FastList.newInstance();
        List<EntityCondition> conditionList2 = FastList.newInstance();

        // we are only concerned about approved sales orders
        conditionList2.add(
            EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ORDER_APPROVED"));
        conditionList2.add(
            EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"));

        // build the expression list from the IDs
        for (String orderId : orderIdList) {
          conditionList1.add(
              EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId));
        }

        // create the conditions
        EntityCondition idCond = EntityCondition.makeCondition(conditionList1, EntityOperator.OR);
        conditionList2.add(idCond);

        EntityCondition cond = EntityCondition.makeCondition(conditionList2, EntityOperator.AND);

        // run the query
        try {
          orderHeaderList =
              delegator.findList(
                  "OrderHeader", cond, null, UtilMisc.toList("+orderDate"), null, false);
        } catch (GenericEntityException e) {
          Debug.logError(e, module);
          return ServiceUtil.returnError(e.getMessage());
        }
        Debug.logInfo("Recieved orderIdList  - " + orderIdList, module);
        Debug.logInfo("Found orderHeaderList - " + orderHeaderList, module);
      }
    }

    Map<String, Object> result = ServiceUtil.returnSuccess();
    result.put("orderHeaderList", orderHeaderList);
    return result;
  }
  protected void logRequestInfo(HttpServletRequest request) {
    ServletContext servletContext = this.getServletContext();
    HttpSession session = request.getSession();

    Debug.logVerbose("--- Start Request Headers: ---", module);
    Enumeration<String> headerNames = UtilGenerics.cast(request.getHeaderNames());
    while (headerNames.hasMoreElements()) {
      String headerName = headerNames.nextElement();
      Debug.logVerbose(headerName + ":" + request.getHeader(headerName), module);
    }
    Debug.logVerbose("--- End Request Headers: ---", module);

    Debug.logVerbose("--- Start Request Parameters: ---", module);
    Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames());
    while (paramNames.hasMoreElements()) {
      String paramName = paramNames.nextElement();
      Debug.logVerbose(paramName + ":" + request.getParameter(paramName), module);
    }
    Debug.logVerbose("--- End Request Parameters: ---", module);

    Debug.logVerbose("--- Start Request Attributes: ---", module);
    Enumeration<String> reqNames = UtilGenerics.cast(request.getAttributeNames());
    while (reqNames != null && reqNames.hasMoreElements()) {
      String attName = reqNames.nextElement();
      Debug.logVerbose(attName + ":" + request.getAttribute(attName), module);
    }
    Debug.logVerbose("--- End Request Attributes ---", module);

    Debug.logVerbose("--- Start Session Attributes: ---", module);
    Enumeration<String> sesNames = null;
    try {
      sesNames = UtilGenerics.cast(session.getAttributeNames());
    } catch (IllegalStateException e) {
      Debug.logVerbose("Cannot get session attributes : " + e.getMessage(), module);
    }
    while (sesNames != null && sesNames.hasMoreElements()) {
      String attName = sesNames.nextElement();
      Debug.logVerbose(attName + ":" + session.getAttribute(attName), module);
    }
    Debug.logVerbose("--- End Session Attributes ---", module);

    Enumeration<String> appNames = UtilGenerics.cast(servletContext.getAttributeNames());
    Debug.logVerbose("--- Start ServletContext Attributes: ---", module);
    while (appNames != null && appNames.hasMoreElements()) {
      String attName = appNames.nextElement();
      Debug.logVerbose(attName + ":" + servletContext.getAttribute(attName), module);
    }
    Debug.logVerbose("--- End ServletContext Attributes ---", module);
  }
Example #4
0
  public void remoteRequest(Element elem) {

    String requestUrl = elem.getAttributeValue("url");
    String host = elem.getAttributeValue("host");
    if (host == null || host.length() == 0) {
      host = props.getProperty("startUrl");
    }
    String responseHandlerMode = elem.getAttributeValue("responseHandlerMode");
    List<Element> children = UtilGenerics.cast(elem.getChildren());
    List<Element> loginAs = UtilGenerics.cast(elem.getChildren("login-as"));
    logger.info("remoteRequest: children=" + children + " loginAs=" + loginAs);
    RemoteRequest loader =
        new RemoteRequest(this, children, loginAs, requestUrl, host, responseHandlerMode);
    loader.runTest();
  }
  public <X> void getListLimits(Map<String, Object> context, List<X> items) {
    listSize = items.size();

    if (getPaginate(context)) {
      try {
        Map<String, String> params = UtilGenerics.cast(context.get("parameters"));
        String viewIndexString = params.get("VIEW_INDEX" + "_" + getPaginatorNumber(context));
        String viewSizeString = params.get("VIEW_SIZE" + "_" + getPaginatorNumber(context));
        viewIndex = Integer.parseInt(viewIndexString);
        viewSize = Integer.parseInt(viewSizeString);
      } catch (Exception e) {
        try {
          viewIndex = ((Integer) context.get("viewIndex")).intValue();
        } catch (Exception e2) {
          viewIndex = 0;
        }
      }
      context.put("viewIndex", Integer.valueOf(this.viewIndex));

      lowIndex = viewIndex * viewSize;
      highIndex = (viewIndex + 1) * viewSize;
    } else {
      viewIndex = 0;
      viewSize = MAX_PAGE_SIZE;
      lowIndex = 0;
      highIndex = MAX_PAGE_SIZE;
    }
  }
Example #6
0
 public void partialRunDependency(Element elem) throws TestCaseException {
   String isRun = replaceParam(elem.getAttributeValue("isRun"));
   if (isRun != null && Boolean.valueOf(isRun)) {
     List<Element> children = UtilGenerics.cast(elem.getChildren());
     this.runCommands(children);
   }
 }
  public void renderPortalPageBegin(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.PortalPage portalPage)
      throws GeneralException, IOException {
    String portalPageId = portalPage.getActualPortalPageId();
    String originalPortalPageId = portalPage.getOriginalPortalPageId();
    String confMode = portalPage.getConfMode(context);

    Map<String, String> uiLabelMap = UtilGenerics.cast(context.get("uiLabelMap"));
    String addColumnLabel = "";
    String addColumnHint = "";
    if (uiLabelMap == null) {
      Debug.logWarning("Could not find uiLabelMap in context", module);
    } else {
      addColumnLabel = uiLabelMap.get("CommonAddColumn");
      addColumnHint = uiLabelMap.get("CommonAddAColumnToThisPortalPage");
    }

    StringWriter sr = new StringWriter();
    sr.append("<@renderPortalPageBegin ");
    sr.append("originalPortalPageId=\"");
    sr.append(originalPortalPageId);
    sr.append("\" portalPageId=\"");
    sr.append(portalPageId);
    sr.append("\" confMode=\"");
    sr.append(confMode);
    sr.append("\" addColumnLabel=\"");
    sr.append(addColumnLabel);
    sr.append("\" addColumnHint=\"");
    sr.append(addColumnHint);
    sr.append("\" />");
    executeMacro(writer, sr.toString());
  }
    @Override
    public void renderWidgetString(
        Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) {
      // isolate the scope
      MapStack<String> contextMs;
      if (!(context instanceof MapStack)) {
        contextMs = MapStack.create(context);
        context = contextMs;
      } else {
        contextMs = UtilGenerics.cast(context);
      }

      // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a
      // new "screens" object just for it so it is isolated and doesn't follow the stack down
      MapStack<String> standAloneStack = contextMs.standAloneChildStack();
      standAloneStack.put(
          "screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer));
      SectionsRenderer sections =
          new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer);

      // put the sectionMap in the context, make sure it is in the sub-scope, ie after calling push
      // on the MapStack
      contextMs.push();
      context.put("sections", sections);

      renderHtmlTemplate(writer, this.locationExdr, context);
      contextMs.pop();
    }
Example #9
0
  public void dataLoop(Element elem) throws TestCaseException {

    String dataListName = elem.getAttributeValue("dataListName");
    List<Element> children = UtilGenerics.cast(elem.getChildren());

    DataLoop looper = new DataLoop(dataListName, this, children);
    looper.runTest();
  }
 public ComponentDef(Element element) {
   Properties systemProps = System.getProperties();
   if ("load-component".equals(element.getNodeName())) {
     name = element.getAttribute("component-name");
     location =
         FlexibleStringExpander.expandString(
             element.getAttribute("component-location"),
             UtilGenerics.<String, Object>checkMap(systemProps));
     type = SINGLE_COMPONENT;
   } else if ("load-components".equals(element.getNodeName())) {
     name = null;
     location =
         FlexibleStringExpander.expandString(
             element.getAttribute("parent-directory"),
             UtilGenerics.<String, Object>checkMap(systemProps));
     type = COMPONENT_DIRECTORY;
   }
 }
Example #11
0
 @Override
 public Class<T> getTypeClass(ClassLoader loader) {
   try {
     return UtilGenerics.cast(ObjectType.loadClass(type, loader));
   } catch (ClassNotFoundException e) {
     Debug.logError(e, "Could not find class for type: " + type, module);
     return null;
   }
 }
Example #12
0
  public void loadData(Element elem) throws TestCaseException {

    String file = elem.getAttributeValue("file");
    String iterations = elem.getAttributeValue("iterations");
    List<Element> children = UtilGenerics.cast(elem.getChildren());

    DataLoader loader = new DataLoader(file, iterations, this, children);
    loader.runTest();
  }
 public List<Map<String, Object>> getAdItemTemplates(String temGroupId) {
   List<Map<String, Object>> themes = FastList.newInstance();
   for (Map<String, Object> temp : this.adItemTemplates) {
     if (temp.get("TemplateGroupId").equals(temGroupId)) {
       themes = UtilGenerics.checkList(temp.get("Templates"));
       break;
     }
   }
   return themes;
 }
Example #14
0
 /**
  * Returns an appropriate <code>Converter</code> instance for <code>sourceClass</code> and <code>
  * targetClass</code>. If no matching <code>Converter</code> is found, the method throws <code>
  * ClassNotFoundException</code>.
  *
  * <p>This method is intended to be used when the source or target <code>Object</code> types are
  * unknown at compile time. If the source and target <code>Object</code> types are known at
  * compile time, then one of the "ready made" converters should be used.
  *
  * @param sourceClass The object class to convert from
  * @param targetClass The object class to convert to
  * @return A matching <code>Converter</code> instance
  * @throws ClassNotFoundException
  */
 public static <S, T> Converter<S, T> getConverter(Class<S> sourceClass, Class<T> targetClass)
     throws ClassNotFoundException {
   String key = sourceClass.getName().concat(DELIMITER).concat(targetClass.getName());
   if (Debug.verboseOn()) {
     Debug.logVerbose("Getting converter: " + key, module);
   }
   OUTER:
   do {
     Converter<?, ?> result = converterMap.get(key);
     if (result != null) {
       return UtilGenerics.cast(result);
     }
     if (noConversions.contains(key)) {
       throw new ClassNotFoundException("No converter found for " + key);
     }
     Class<?> foundSourceClass = null;
     Converter<?, ?> foundConverter = null;
     for (Converter<?, ?> value : converterMap.values()) {
       if (value.canConvert(sourceClass, targetClass)) {
         // this converter can deal with the source/target pair
         if (foundSourceClass == null
             || foundSourceClass.isAssignableFrom(value.getSourceClass())) {
           // remember the current target source class; if we find another converter, check
           // to see if it's source class is assignable to this one, and if so, it means it's
           // a child class, so we'll then take that converter.
           foundSourceClass = value.getSourceClass();
           foundConverter = value;
         }
       }
     }
     if (foundConverter != null) {
       converterMap.putIfAbsent(key, foundConverter);
       continue OUTER;
     }
     for (ConverterCreator value : creators) {
       result = createConverter(value, sourceClass, targetClass);
       if (result != null) {
         converterMap.putIfAbsent(key, result);
         continue OUTER;
       }
     }
     if (noConversions.add(key)) {
       Debug.logWarning(
           "*** No converter found, converting from "
               + sourceClass.getName()
               + " to "
               + targetClass.getName()
               + ". Please report this message to the developer community so "
               + "a suitable converter can be created. ***",
           module);
     }
     throw new ClassNotFoundException("No converter found for " + key);
   } while (true);
 }
Example #15
0
 public static void incrementPaginatorNumber(Map<String, Object> context) {
   Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext"));
   if (globalCtx != null) {
     Boolean NO_PAGINATOR = (Boolean) globalCtx.get("NO_PAGINATOR");
     if (UtilValidate.isNotEmpty(NO_PAGINATOR)) {
       globalCtx.remove("NO_PAGINATOR");
     } else {
       Integer paginateNumberInt = Integer.valueOf(getPaginatorNumber(context) + 1);
       globalCtx.put("PAGINATOR_NUMBER", paginateNumberInt);
     }
   }
 }
  private String getUserLoginSession(HttpSession session) {
    Map<String, ?> userLoginSession = UtilGenerics.cast(session.getAttribute("userLoginSession"));

    String sessionData = null;
    if (UtilValidate.isNotEmpty(userLoginSession)) {
      try {
        sessionData = XmlSerializer.serialize(userLoginSession);
      } catch (Exception e) {
        Debug.logWarning(e, "Problems serializing UserLoginSession", module);
      }
    }
    return sessionData;
  }
 private static Locale getLocale(Locale locale, Map<String, ? extends Object> context) {
   if (locale == null) {
     locale = (Locale) context.get("locale");
     if (locale == null && context.containsKey("autoUserLogin")) {
       Map<String, Object> autoUserLogin = UtilGenerics.cast(context.get("autoUserLogin"));
       locale = UtilMisc.ensureLocale(autoUserLogin.get("lastLocale"));
     }
     if (locale == null) {
       locale = Locale.getDefault();
     }
   }
   return locale;
 }
 private static TimeZone getTimeZone(TimeZone timeZone, Map<String, ? extends Object> context) {
   if (timeZone == null) {
     timeZone = (TimeZone) context.get("timeZone");
     if (timeZone == null && context.containsKey("autoUserLogin")) {
       Map<String, String> autoUserLogin = UtilGenerics.cast(context.get("autoUserLogin"));
       timeZone = UtilDateTime.toTimeZone(autoUserLogin.get("lastTimeZone"));
     }
     if (timeZone == null) {
       timeZone = TimeZone.getDefault();
     }
   }
   return timeZone;
 }
Example #19
0
 public static int getPaginatorNumber(Map<String, Object> context) {
   int paginator_number = 0;
   Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext"));
   if (globalCtx != null) {
     Integer paginateNumberInt = (Integer) globalCtx.get("PAGINATOR_NUMBER");
     if (paginateNumberInt == null) {
       paginateNumberInt = Integer.valueOf(0);
       globalCtx.put("PAGINATOR_NUMBER", paginateNumberInt);
     }
     paginator_number = paginateNumberInt.intValue();
   }
   return paginator_number;
 }
Example #20
0
 private void validateSOAPBody(SOAPBody reqBody) throws EventHandlerException {
   // ensure the SOAPBody contains only one service call request
   Integer numServiceCallRequests = 0;
   Iterator<Object> serviceIter = UtilGenerics.cast(reqBody.getChildElements());
   while (serviceIter.hasNext()) {
     numServiceCallRequests++;
     serviceIter.next();
   }
   if (numServiceCallRequests != 1) {
     throw new EventHandlerException(
         "One service call expected, but received: " + numServiceCallRequests.toString());
   }
 }
Example #21
0
  private GenericMessageListener loadListener(String serverKey, Element server)
      throws GenericServiceException {
    String serverName = server.getAttribute("jndi-server-name");
    String jndiName = server.getAttribute("jndi-name");
    String queueName = server.getAttribute("topic-queue");
    String type = server.getAttribute("type");
    String userName = server.getAttribute("username");
    String password = server.getAttribute("password");
    String className = server.getAttribute("listener-class");

    if (UtilValidate.isEmpty(className)) {
      if (type.equals("topic")) className = JmsListenerFactory.TOPIC_LISTENER_CLASS;
      else if (type.equals("queue")) className = JmsListenerFactory.QUEUE_LISTENER_CLASS;
    }

    GenericMessageListener listener = listeners.get(serverKey);

    if (listener == null) {
      synchronized (this) {
        listener = listeners.get(serverKey);
        if (listener == null) {
          ClassLoader cl = this.getClass().getClassLoader();

          try {
            Class<?> c = cl.loadClass(className);
            Constructor<GenericMessageListener> cn =
                UtilGenerics.cast(
                    c.getConstructor(
                        ServiceDispatcher.class,
                        String.class,
                        String.class,
                        String.class,
                        String.class,
                        String.class));

            listener =
                cn.newInstance(dispatcher, serverName, jndiName, queueName, userName, password);
          } catch (Exception e) {
            throw new GenericServiceException(e.getMessage(), e);
          }
          if (listener != null) listeners.put(serverKey, listener);
          loadable++;
        }
      }
    }
    if (listener != null && !listener.isConnected()) {
      listener.load();
      if (listener.isConnected()) connected++;
    }
    return listener;
  }
Example #22
0
  /**
   * JavaMail Service that gets body content from a URL
   *
   * @param ctx The DispatchContext that this service is operating in
   * @param rcontext Map containing the input parameters
   * @return Map with the result of the service, the output parameters
   */
  public static Map<String, Object> sendMailFromUrl(
      DispatchContext ctx, Map<String, ? extends Object> rcontext) {
    // pretty simple, get the content and then call the sendMail method below
    Map<String, Object> sendMailContext = UtilMisc.makeMapWritable(rcontext);
    String bodyUrl = (String) sendMailContext.remove("bodyUrl");
    Map<String, Object> bodyUrlParameters =
        UtilGenerics.checkMap(sendMailContext.remove("bodyUrlParameters"));
    Locale locale = (Locale) rcontext.get("locale");
    LocalDispatcher dispatcher = ctx.getDispatcher();

    URL url = null;

    try {
      url = new URL(bodyUrl);
    } catch (MalformedURLException e) {
      Debug.logWarning(e, module);
      return ServiceUtil.returnError(
          UtilProperties.getMessage(
              resource,
              "CommonEmailSendMalformedUrl",
              UtilMisc.toMap("bodyUrl", bodyUrl, "errorString", e.toString()),
              locale));
    }

    HttpClient httpClient = new HttpClient(url, bodyUrlParameters);
    String body = null;

    try {
      body = httpClient.post();
    } catch (HttpClientException e) {
      Debug.logWarning(e, module);
      return ServiceUtil.returnError(
          UtilProperties.getMessage(
              resource,
              "CommonEmailSendGettingError",
              UtilMisc.toMap("errorString", e.toString()),
              locale));
    }

    sendMailContext.put("body", body);
    Map<String, Object> sendMailResult;
    try {
      sendMailResult = dispatcher.runSync("sendMail", sendMailContext);
    } catch (GenericServiceException e) {
      Debug.logError(e, module);
      return ServiceUtil.returnError(e.getMessage());
    }

    // just return the same result; it contains all necessary information
    return sendMailResult;
  }
Example #23
0
  public static String getJSONuiLabelArray(
      HttpServletRequest request, HttpServletResponse response) {
    String requiredLabels = request.getParameter("requiredLabels");

    JSONObject uiLabelObject = null;
    if (UtilValidate.isNotEmpty(requiredLabels)) {
      // Transform JSON String to Object
      uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
    }

    JSONObject jsonUiLabel = new JSONObject();
    Locale locale = request.getLocale();
    if (!uiLabelObject.isEmpty()) {
      Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
      // Iterate over the resouce set
      for (String resource : resourceSet) {
        JSONArray labels = uiLabelObject.getJSONArray(resource);
        if (labels.isEmpty() || labels == null) {
          continue;
        }

        // Iterate over the uiLabel List
        Iterator<String> jsonLabelIterator = UtilGenerics.cast(labels.iterator());
        JSONArray resourceLabelList = new JSONArray();
        while (jsonLabelIterator.hasNext()) {
          String label = jsonLabelIterator.next();
          String receivedLabel = UtilProperties.getMessage(resource, label, locale);
          if (UtilValidate.isNotEmpty(receivedLabel)) {
            resourceLabelList.add(receivedLabel);
          }
        }
        jsonUiLabel.element(resource, resourceLabelList);
      }
    }

    writeJSONtoResponse(jsonUiLabel, response);
    return "success";
  }
  private boolean defineElement() {
    element = null;
    pageContext.removeAttribute(name, PageContext.PAGE_SCOPE);
    boolean verboseOn = Debug.verboseOn();

    if (this.iterator.hasNext()) {
      element = this.iterator.next();
      if (verboseOn) Debug.logVerbose("iterator has another object: " + element, module);
    } else {
      if (verboseOn) Debug.logVerbose("iterator has no more objects", module);
    }
    if (element != null) {
      if (verboseOn)
        Debug.logVerbose(
            "set attribute " + name + " to be " + element + " as next value from iterator", module);
      pageContext.setAttribute(name, element);

      // expand a map element here if requested
      if (expandMap) {
        Map<String, ?> tempMap = UtilGenerics.cast(element);
        Iterator<Map.Entry<String, ?>> mapEntries =
            UtilGenerics.cast(tempMap.entrySet().iterator());

        while (mapEntries.hasNext()) {
          Map.Entry<String, ?> entry = mapEntries.next();
          Object value = entry.getValue();

          if (value == null) value = "";
          pageContext.setAttribute(entry.getKey(), value);
        }
      }

      return true;
    }
    if (verboseOn) Debug.logVerbose("no more iterations; element = " + element, module);
    return false;
  }
Example #25
0
  /**
   * Runs the service defined in the MapMessage
   *
   * @param message
   * @return Map
   */
  protected Map<String, Object> runService(MapMessage message) {
    Map<String, ? extends Object> context = null;
    String serviceName = null;
    String xmlContext = null;

    try {
      serviceName = message.getString("serviceName");
      xmlContext = message.getString("serviceContext");
      if (serviceName == null || xmlContext == null) {
        Debug.logError("Message received is not an OFB service message. Ignored!", module);
        return null;
      }

      Object o = XmlSerializer.deserialize(xmlContext, dispatcher.getDelegator());

      if (Debug.verboseOn()) Debug.logVerbose("De-Serialized Context --> " + o, module);
      if (ObjectType.instanceOf(o, "java.util.Map")) context = UtilGenerics.checkMap(o);
    } catch (JMSException je) {
      Debug.logError(je, "Problems reading message.", module);
    } catch (Exception e) {
      Debug.logError(e, "Problems deserializing the service context.", module);
    }

    try {
      ModelService model = dispatcher.getDispatchContext().getModelService(serviceName);
      if (!model.export) {
        Debug.logWarning("Attempt to invoke a non-exported service: " + serviceName, module);
        return null;
      }
    } catch (GenericServiceException e) {
      Debug.logError(e, "Unable to get ModelService for service : " + serviceName, module);
    }

    if (Debug.verboseOn()) Debug.logVerbose("Running service: " + serviceName, module);

    Map<String, Object> result = null;
    if (context != null) {
      try {
        result = dispatcher.runSync(serviceName, context);
      } catch (GenericServiceException gse) {
        Debug.logError(gse, "Problems with service invocation.", module);
      }
    }
    return result;
  }
 public void logStats(HttpSession session, GenericValue visit) {
   if (Debug.verboseOn() || session.getAttribute("org.ofbiz.log.session.stats") != null) {
     Debug.log("<===================================================================>", module);
     Debug.log("Session ID     : " + session.getId(), module);
     Debug.log("Created Time   : " + session.getCreationTime(), module);
     Debug.log("Last Access    : " + session.getLastAccessedTime(), module);
     Debug.log("Max Inactive   : " + session.getMaxInactiveInterval(), module);
     Debug.log("--------------------------------------------------------------------", module);
     Debug.log("Total Sessions : " + ControlEventListener.getTotalActiveSessions(), module);
     Debug.log("Total Active   : " + ControlEventListener.getTotalActiveSessions(), module);
     Debug.log("Total Passive  : " + ControlEventListener.getTotalPassiveSessions(), module);
     Debug.log("** note : this session has been counted as destroyed.", module);
     Debug.log("--------------------------------------------------------------------", module);
     Debug.log("Visit ID       : " + visit.getString("visitId"), module);
     Debug.log("Party ID       : " + visit.getString("partyId"), module);
     Debug.log("Client IP      : " + visit.getString("clientIpAddress"), module);
     Debug.log("Client Host    : " + visit.getString("clientHostName"), module);
     Debug.log("Client User    : "******"clientUser"), module);
     Debug.log("WebApp         : " + visit.getString("webappName"), module);
     Debug.log("Locale         : " + visit.getString("initialLocale"), module);
     Debug.log("UserAgent      : " + visit.getString("initialUserAgent"), module);
     Debug.log("Referrer       : " + visit.getString("initialReferrer"), module);
     Debug.log("Initial Req    : " + visit.getString("initialRequest"), module);
     Debug.log("Visit From     : " + visit.getString("fromDate"), module);
     Debug.log("Visit Thru     : " + visit.getString("thruDate"), module);
     Debug.log("--------------------------------------------------------------------", module);
     Debug.log("--- Start Session Attributes: ---", module);
     Enumeration<String> sesNames = null;
     try {
       sesNames = UtilGenerics.cast(session.getAttributeNames());
     } catch (IllegalStateException e) {
       Debug.log("Cannot get session attributes : " + e.getMessage(), module);
     }
     while (sesNames != null && sesNames.hasMoreElements()) {
       String attName = sesNames.nextElement();
       Debug.log(attName + ":" + session.getAttribute(attName), module);
     }
     Debug.log("--- End Session Attributes ---", module);
     Debug.log("<===================================================================>", module);
   }
 }
Example #27
0
  public static String getJSONuiLabel(HttpServletRequest request, HttpServletResponse response) {
    String requiredLabels = request.getParameter("requiredLabel");

    JSONObject uiLabelObject = null;
    if (UtilValidate.isNotEmpty(requiredLabels)) {
      // Transform JSON String to Object
      uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
    }

    JSONArray jsonUiLabel = new JSONArray();
    Locale locale = request.getLocale();
    if (!uiLabelObject.isEmpty()) {
      Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
      // Iterate over the resource set
      // here we need a keySet because we don't now which label resource to load
      // the key set should have the size one, if greater or empty error should returned
      if (UtilValidate.isEmpty(resourceSet)) {
        Debug.logError("No resource and labels found", module);
        return "error";
      } else if (resourceSet.size() > 1) {
        Debug.logError(
            "More than one resource found, please use the method: getJSONuiLabelArray", module);
        return "error";
      }

      for (String resource : resourceSet) {
        String label = uiLabelObject.getString(resource);
        if (UtilValidate.isEmail(label)) {
          continue;
        }

        String receivedLabel = UtilProperties.getMessage(resource, label, locale);
        jsonUiLabel.add(receivedLabel);
      }
    }

    writeJSONtoResponse(jsonUiLabel, response);
    return "success";
  }
 public void renderScreenletSubWidget(
     Appendable writer,
     Map<String, Object> context,
     ModelScreenWidget subWidget,
     ModelScreenWidget.Screenlet screenlet)
     throws GeneralException, IOException {
   if (subWidget.equals(screenlet.getNavigationForm())) {
     HttpServletRequest request = (HttpServletRequest) context.get("request");
     HttpServletResponse response = (HttpServletResponse) context.get("response");
     if (request != null && response != null) {
       Map<String, Object> globalCtx = UtilGenerics.checkMap(context.get("globalContext"));
       globalCtx.put("NO_PAGINATOR", true);
       FormStringRenderer savedRenderer = (FormStringRenderer) context.get("formStringRenderer");
       HtmlFormRenderer renderer = new HtmlFormRenderer(request, response);
       renderer.setRenderPagination(false);
       context.put("formStringRenderer", renderer);
       subWidget.renderWidgetString(writer, context, this);
       context.put("formStringRenderer", savedRenderer);
     }
   } else {
     subWidget.renderWidgetString(writer, context, this);
   }
 }
 public static List<String> getTrail(ServletRequest request) {
   HttpSession session = ((HttpServletRequest) request).getSession();
   List<String> crumb = UtilGenerics.checkList(session.getAttribute("_BREAD_CRUMB_TRAIL_"));
   return crumb;
 }
  public List<Map<String, Object>> syncAdItemTemplates()
      throws ApiException, SdkSoapException, SdkException {
    GetDescriptionTemplatesRequestType req = null;
    GetDescriptionTemplatesResponseType resp = null;
    List<Map<String, Object>> temGroupList = FastList.newInstance();

    GetDescriptionTemplatesCall call = new GetDescriptionTemplatesCall(this.apiContext);
    req = new GetDescriptionTemplatesRequestType();
    req.setCategoryID(this.catId);
    resp = (GetDescriptionTemplatesResponseType) call.execute(req);
    if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
      DescriptionTemplateType[] descriptionTemplateTypeList = resp.getDescriptionTemplate();
      Debug.logInfo("layout of category " + this.catId + ":" + resp.getLayoutTotal(), module);
      for (DescriptionTemplateType descTemplateType : descriptionTemplateTypeList) {
        List<Map<String, Object>> templateList = null;
        Map<String, Object> templateGroup = null;
        if ("THEME".equals(String.valueOf(descTemplateType.getType()))) {
          Map<String, Object> template = FastMap.newInstance();
          template.put("TemplateId", String.valueOf(descTemplateType.getID()));
          template.put("TemplateImageURL", descTemplateType.getImageURL());
          template.put("TemplateName", descTemplateType.getName());
          template.put("TemplateType", descTemplateType.getType());

          // check group template by groupId
          for (Map<String, Object> temGroup : temGroupList) {
            if (temGroup.get("TemplateGroupId").equals(descTemplateType.getGroupID().toString())) {
              templateGroup = temGroup;
              break;
            }
          }
          if (templateGroup == null) {
            templateGroup = FastMap.newInstance();
            templateList = FastList.newInstance();
            templateGroup.put("TemplateGroupId", descTemplateType.getGroupID().toString());
            templateList.add(template);
            templateGroup.put("Templates", templateList);
            temGroupList.add(templateGroup);
          } else {
            if (templateGroup.get("Templates") != null) {
              templateList = UtilGenerics.checkList(templateGroup.get("Templates"));
              templateList.add(template);
            }
          }
        } else if ("Layout".equals(String.valueOf(descTemplateType.getType()))) {
        }
      }
      ThemeGroupType[] themes = resp.getThemeGroup();
      if (themes != null && temGroupList != null) {
        for (Map<String, Object> temGroup : temGroupList) {
          for (ThemeGroupType theme : themes) {
            if (theme.getGroupID()
                == Integer.parseInt(temGroup.get("TemplateGroupId").toString())) {
              if (theme != null) temGroup.put("TemplateGroupName", theme.getGroupName());
              break;
            } else {
              if (theme != null) temGroup.put("TemplateGroupName", "_NA_");
            }
          }
        }
      }
    }
    return adItemTemplates = temGroupList;
  }