public static String getCatalogTopCategory(ServletRequest request, String defaultTopCategory) {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    Map<String, Object> requestParameters = UtilHttp.getParameterMap(httpRequest);
    String topCatName = null;
    boolean fromSession = false;

    // first see if a new category was specified as a parameter
    topCatName = (String) requestParameters.get("CATALOG_TOP_CATEGORY");
    // if no parameter, try from session
    if (topCatName == null) {
      topCatName = (String) httpRequest.getSession().getAttribute("CATALOG_TOP_CATEGORY");
      if (topCatName != null) fromSession = true;
    }
    // if nothing else, just use a default top category name
    if (topCatName == null) topCatName = defaultTopCategory;
    if (topCatName == null) topCatName = "CATALOG1";

    if (!fromSession) {
      if (Debug.infoOn())
        Debug.logInfo(
            "[CategoryWorker.getCatalogTopCategory] Setting new top category: " + topCatName,
            module);
      httpRequest.getSession().setAttribute("CATALOG_TOP_CATEGORY", topCatName);
    }
    return topCatName;
  }
Example #2
0
  @Override
  public T getObject(MethodContext methodContext) {
    T fieldVal = null;

    if (!mapAcsr.isEmpty()) {
      Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
      if (fromMap == null) {
        Debug.logWarning(
            "Map not found with name " + mapAcsr + ", not getting Object value, returning null.",
            module);
        return null;
      }
      fieldVal = fieldAcsr.get(fromMap, methodContext);
    } else {
      // no map name, try the env
      fieldVal = fieldAcsr.get(methodContext);
    }

    if (fieldVal == null) {
      if (Debug.infoOn())
        Debug.logInfo(
            "Field value not found with name "
                + fieldAcsr
                + " in Map with name "
                + mapAcsr
                + ", not getting Object value, returning null.",
            module);
      return null;
    }

    return fieldVal;
  }
Example #3
0
  @Override
  public boolean exec(MethodContext methodContext) {
    Object fieldVal = null;

    if (!mapAcsr.isEmpty()) {
      Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);

      if (fromMap == null) {
        if (Debug.infoOn())
          Debug.logInfo(
              "Map not found with name " + mapAcsr + ", not copying from this map", module);
        return true;
      }

      fieldVal = fieldAcsr.get(fromMap, methodContext);
    } else {
      // no map name, try the env
      fieldVal = fieldAcsr.get(methodContext);
    }

    if (fieldVal == null) {
      if (Debug.verboseOn())
        Debug.logVerbose(
            "Field value not found with name "
                + fieldAcsr
                + " in Map with name "
                + mapAcsr
                + ", not copying field",
            module);
      return true;
    }

    // note that going to an env field will only work if it came from an env
    // field because if not specified the to-map-name will be set to the map-name
    // to go from a map field to an env field, use the field-to-env operation
    Map<String, Object> toMap = null;

    if (!toMapAcsr.isEmpty()) {
      toMap = toMapAcsr.get(methodContext);
      if (toMap == null) {
        if (Debug.verboseOn())
          Debug.logVerbose("Map not found with name " + toMapAcsr + ", creating new map", module);
        toMap = FastMap.newInstance();
        toMapAcsr.put(methodContext, toMap);
      }
      toFieldAcsr.put(toMap, fieldVal, methodContext);
    } else {
      // no to-map, so put in env
      toFieldAcsr.put(methodContext, fieldVal);
    }

    return true;
  }
  public static void getRelatedCategories(
      ServletRequest request, String attributeName, boolean limitView) {
    Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request);
    String requestId = null;

    requestId =
        UtilFormatOut.checkNull(
            (String) requestParameters.get("catalog_id"),
            (String) requestParameters.get("CATALOG_ID"),
            (String) requestParameters.get("category_id"),
            (String) requestParameters.get("CATEGORY_ID"));

    if (requestId.equals("")) return;
    if (Debug.infoOn())
      Debug.logInfo("[CategoryWorker.getRelatedCategories] RequestID: " + requestId, module);
    getRelatedCategories(request, attributeName, requestId, limitView);
  }
  /** @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) */
  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (Debug.infoOn())
      Debug.logInfo(
          "LOADING WEBAPP ["
              + config.getServletContext().getContextPath().substring(1)
              + "] "
              + config.getServletContext().getServletContextName()
              + ", located at "
              + config.getServletContext().getRealPath("/"),
          module);

    // configure custom BSF engines
    configureBsf();
    // initialize the request handler
    getRequestHandler();
  }
  public String invoke(
      Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response)
      throws EventHandlerException {

    if (Debug.infoOn()) {
      Debug.logInfo("In GwtRpcGroovyEventHandler", module);
    }

    String requestPayload = null;

    try {

      requestPayload = GwtRpcPayloadUtil.getRequestPayload(request);

    } catch (IOException ioe) {
      throw new EventHandlerException("Exception while getting requestPayload", ioe);
    } catch (ServletException se) {
      throw new EventHandlerException("Exception while getting requestPayload", se);
    }

    HashMap<String, String> gwtParameters = GwtRpcPayloadUtil.getParameters(requestPayload);
    if (Debug.infoOn()) {
      Debug.logInfo("gwtParameters : " + gwtParameters, module);
    }

    if (null != gwtParameters) {

      HttpSession session = request.getSession();

      Map<String, Object> groovyContext = FastMap.newInstance();
      groovyContext.put("request", request);
      groovyContext.put("response", response);
      groovyContext.put("session", session);
      groovyContext.put("dispatcher", request.getAttribute("dispatcher"));
      groovyContext.put("delegator", request.getAttribute("delegator"));
      groovyContext.put("security", request.getAttribute("security"));
      groovyContext.put("locale", UtilHttp.getLocale(request));
      groovyContext.put("timeZone", UtilHttp.getTimeZone(request));
      groovyContext.put("userLogin", session.getAttribute("userLogin"));

      Map<String, Object> parameters =
          UtilHttp.getCombinedMap(
              request,
              UtilMisc.toSet(
                  "delegator", "dispatcher", "security", "locale", "timeZone", "userLogin"));
      if (Debug.infoOn()) {
        Debug.logInfo("parameters : " + parameters, module);
      }

      Set<String> keys = gwtParameters.keySet();
      Iterator<String> iter = keys.iterator();

      while (iter.hasNext()) {
        String key = iter.next();
        parameters.put(key, gwtParameters.get(key));
      }

      groovyContext.put("parameters", parameters);

      Object result = null;

      try {
        result = GroovyUtil.runScriptAtLocation(event.path + event.invoke, groovyContext);
        if (Debug.infoOn()) {
          Debug.logInfo("groovy script result : " + result, module);
        }
      } catch (GeneralException ge) {
        throw new EventHandlerException("Exception while executing groovy script : ", ge);
      }

      Map<String, Object> resultMap = (Map<String, Object>) result;

      // ServletContext sc = (ServletContext)request.getAttribute("servletContext");
      // RequestDispatcher rd = sc.getRequestDispatcher("/gwtrpc");

      request.setAttribute(GwtRpcPayload.OFBIZ_PAYLOAD, resultMap);
      request.setAttribute(GwtRpcPayload.REQUEST_PAYLOAD, requestPayload);

      /*try {
          rd.forward(request, response);
      } catch(IOException ioe) {
          throw new EventHandlerException("IO Exception while forwarding request to GWT RPC servlet  : ",ioe);
      } catch(ServletException se) {
          throw new EventHandlerException("Servlet Exception while forwarding request to GWT RPC servlet  : ",se);
      }*/

      try {

        GwtRpcServletUtil servletUtil = new GwtRpcServletUtil();
        String responsePayload = servletUtil.invokeServlet(request, response, requestPayload);
        servletUtil.writeResponse(servletContext, request, response, responsePayload);

      } catch (Exception e) {
        Debug.logError(e, "gwt remote servlet invocation failed " + e.getMessage(), module);
        throw new EventHandlerException(e);
      }

    } else {
      throw new EventHandlerException("GWT parameters are null  : " + gwtParameters);
    }

    return "success";
  }
Example #7
0
  /**
   * Makes a list of TrackingCodeOrder entities to be attached to the current order; called by the
   * createOrder event; the values in the returned List will not have the orderId set
   */
  public static List<GenericValue> makeTrackingCodeOrders(HttpServletRequest request) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();
    List<GenericValue> trackingCodeOrders = FastList.newInstance();

    Cookie[] cookies = request.getCookies();
    Timestamp affiliateReferredTimeStamp = null;
    String siteId = null;
    String isBillable = null;
    String trackingCodeId = null;
    if (cookies != null && cookies.length > 0) {
      for (int i = 0; i < cookies.length; i++) {
        String cookieName = cookies[i].getName();

        Debug.logInfo(" cookieName is " + cookieName, module);
        Debug.logInfo(" cookieValue is " + cookies[i].getValue(), module);
        // find the siteId cookie if it exists
        if ("Ofbiz.TKCD.SiteId".equals(cookieName)) {
          siteId = cookies[i].getValue();
        }

        // find the referred timestamp cookie if it exists
        if ("Ofbiz.TKCD.UpdatedTimeStamp".equals(cookieName)) {
          String affiliateReferredTime = cookies[i].getValue();
          if (affiliateReferredTime != null && !affiliateReferredTime.equals("")) {
            try {
              affiliateReferredTimeStamp = Timestamp.valueOf(affiliateReferredTime);
            } catch (IllegalArgumentException e) {
              Debug.logError(
                  e, "Error parsing affiliateReferredTimeStamp value from cookie", module);
            }
          }
        }

        // find any that start with TKCDB_ for billable tracking code cookies with isBillable=Y
        // also and for each TKCDT_ cookie that doesn't have a corresponding billable code add it to
        // the list with isBillable=N
        // This cookie value keeps trackingCodeId
        if (cookieName.startsWith("TKCDB_")) {
          isBillable = "Y";
          trackingCodeId = cookies[i].getValue();
        } else if (cookieName.startsWith("TKCDT_")) {
          isBillable = "N";
          trackingCodeId = cookies[i].getValue();
        }
      }
    }
    GenericValue trackingCode = null;
    try {
      trackingCode =
          delegator.findByPrimaryKeyCache(
              "TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId));
    } catch (GenericEntityException e) {
      Debug.logError(
          e,
          "Error looking up TrackingCode with trackingCodeId ["
              + trackingCodeId
              + "], ignoring this trackingCodeId",
          module);
    }

    if (trackingCode != null) {
      // check effective dates
      if (trackingCode.get("fromDate") != null
          && nowStamp.before(trackingCode.getTimestamp("fromDate"))) {
        if (Debug.infoOn())
          Debug.logInfo(
              "The TrackingCode with ID ["
                  + trackingCodeId
                  + "] has not yet gone into effect, ignoring this trackingCodeId",
              module);
      }
      if (trackingCode.get("thruDate") != null
          && nowStamp.after(trackingCode.getTimestamp("thruDate"))) {
        if (Debug.infoOn())
          Debug.logInfo(
              "The TrackingCode with ID ["
                  + trackingCodeId
                  + "] has expired, ignoring this trackingCodeId",
              module);
      }
      GenericValue trackingCodeOrder =
          delegator.makeValue(
              "TrackingCodeOrder",
              UtilMisc.toMap(
                  "trackingCodeTypeId",
                  trackingCode.get("trackingCodeTypeId"),
                  "trackingCodeId",
                  trackingCodeId,
                  "isBillable",
                  isBillable,
                  "siteId",
                  siteId,
                  "hasExported",
                  "N",
                  "affiliateReferredTimeStamp",
                  affiliateReferredTimeStamp));

      Debug.logInfo(" trackingCodeOrder is " + trackingCodeOrder, module);
      trackingCodeOrders.add(trackingCodeOrder);
    } else {
      // Only log an error if there was a trackingCodeId to begin with
      if (trackingCodeId != null) {
        Debug.logError(
            "TrackingCode not found for trackingCodeId ["
                + trackingCodeId
                + "], ignoring this trackingCodeId.",
            module);
      }
    }

    return trackingCodeOrders;
  }
Example #8
0
  public static String checkAccessTrackingCode(
      HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();

    String trackingCodeId = request.getParameter("autoTrackingCode");
    if (UtilValidate.isEmpty(trackingCodeId)) trackingCodeId = request.getParameter("atc");
    if (UtilValidate.isEmpty(trackingCodeId)) {
      Cookie[] cookies = request.getCookies();
      if (cookies != null) {
        for (Cookie cookie : cookies) {
          if ("TKCDT_ACCESS".equals(cookie.getName())) {
            trackingCodeId = cookie.getValue();
          }
        }
      }
    }

    if (UtilValidate.isNotEmpty(trackingCodeId)) {
      // find the tracking code object
      GenericValue trackingCode = null;
      try {
        trackingCode =
            delegator.findByPrimaryKeyCache(
                "TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId));
      } catch (GenericEntityException e) {
        Debug.logError(
            e,
            "Error looking up TrackingCode with trackingCodeId ["
                + trackingCodeId
                + "], ignoring this trackingCodeId",
            module);
      }
      if (trackingCode != null) {
        // verify the tracking code type
        if ("ACCESS".equals(trackingCode.getString("trackingCodeTypeId"))) {
          // verify the effective date
          if (trackingCode.get("fromDate") != null
              && nowStamp.after(trackingCode.getTimestamp("fromDate"))) {
            if (trackingCode.get("thruDate") != null
                && nowStamp.before(trackingCode.getTimestamp("thruDate"))) {
              // tracking code is valid
              return "success";
            } else {
              if (Debug.infoOn())
                Debug.logInfo(
                    "The TrackingCode with ID ["
                        + trackingCodeId
                        + "] has expired, ignoring this trackingCodeId",
                    module);
              request.setAttribute(
                  "_ERROR_MESSAGE_", "Access code [" + trackingCodeId + "], is not valid.");
            }
          } else {
            if (Debug.infoOn())
              Debug.logInfo(
                  "The TrackingCode with ID ["
                      + trackingCodeId
                      + "] has not yet gone into effect, ignoring this trackingCodeId",
                  module);
            request.setAttribute(
                "_ERROR_MESSAGE_", "Access code [" + trackingCodeId + "], is not valid.");
          }
        } else {
          Debug.logWarning(
              "Tracking code found ["
                  + trackingCodeId
                  + "] but was not of the type ACCESS; access denied",
              module);
          request.setAttribute(
              "_ERROR_MESSAGE_", "Access code [" + trackingCodeId + "] not found.");
        }
      } else {
        request.setAttribute("_ERROR_MESSAGE_", "Access code [" + trackingCodeId + "] not found.");
      }
    }

    // no tracking code or tracking code invalid; redirect to the access page (i.e. request named
    // 'protect')
    return ":_protect_:";
  }
Example #9
0
  /**
   * If attaching TrackingCode Cookies to the visit is desired this event should be added to the
   * list of events that run on the first hit in a visit.
   */
  public static String checkTrackingCodeCookies(
      HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();
    GenericValue visit = VisitHandler.getVisit(request.getSession());
    if (visit == null) {
      Debug.logWarning(
          "Could not get visit, not checking trackingCode cookies to associate with visit", module);
    } else {
      // loop through cookies and look for ones with a name that starts with TKCDT_ for trackable
      // cookies
      Cookie[] cookies = request.getCookies();

      if (cookies != null && cookies.length > 0) {
        for (int i = 0; i < cookies.length; i++) {
          if (cookies[i].getName().startsWith("TKCDT_")) {
            String trackingCodeId = cookies[i].getValue();
            GenericValue trackingCode;
            try {
              trackingCode =
                  delegator.findByPrimaryKeyCache(
                      "TrackingCode", UtilMisc.toMap("trackingCodeId", trackingCodeId));
            } catch (GenericEntityException e) {
              Debug.logError(
                  e,
                  "Error looking up TrackingCode with trackingCodeId ["
                      + trackingCodeId
                      + "], ignoring this trackingCodeId",
                  module);
              continue;
            }

            if (trackingCode == null) {
              Debug.logError(
                  "TrackingCode not found for trackingCodeId ["
                      + trackingCodeId
                      + "], ignoring this trackingCodeId.",
                  module);
              // this return value will be ignored, but we'll designate this as an error anyway
              continue;
            }

            // check effective dates
            if (trackingCode.get("fromDate") != null
                && nowStamp.before(trackingCode.getTimestamp("fromDate"))) {
              if (Debug.infoOn())
                Debug.logInfo(
                    "The TrackingCode with ID ["
                        + trackingCodeId
                        + "] has not yet gone into effect, ignoring this trackingCodeId",
                    module);
              continue;
            }
            if (trackingCode.get("thruDate") != null
                && nowStamp.after(trackingCode.getTimestamp("thruDate"))) {
              if (Debug.infoOn())
                Debug.logInfo(
                    "The TrackingCode with ID ["
                        + trackingCodeId
                        + "] has expired, ignoring this trackingCodeId",
                    module);
              continue;
            }

            // for each trackingCodeId found in this way attach to the visit with the TKCDSRC_COOKIE
            // sourceEnumId
            GenericValue trackingCodeVisit =
                delegator.makeValue(
                    "TrackingCodeVisit",
                    UtilMisc.toMap(
                        "trackingCodeId",
                        trackingCodeId,
                        "visitId",
                        visit.get("visitId"),
                        "fromDate",
                        nowStamp,
                        "sourceEnumId",
                        "TKCDSRC_COOKIE"));
            try {
              // not doing this inside a transaction, want each one possible to go in
              trackingCodeVisit.create();
            } catch (GenericEntityException e) {
              Debug.logError(e, "Error while saving TrackingCodeVisit", module);
              // don't return error, want to get as many as possible: return "error";
            }
          }
        }
      }
    }

    return "success";
  }
Example #10
0
  private static String processTrackingCode(
      GenericValue trackingCode, HttpServletRequest request, HttpServletResponse response) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    String trackingCodeId = trackingCode.getString("trackingCodeId");

    // check effective dates
    java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();
    if (trackingCode.get("fromDate") != null
        && nowStamp.before(trackingCode.getTimestamp("fromDate"))) {
      if (Debug.infoOn())
        Debug.logInfo(
            "The TrackingCode with ID ["
                + trackingCodeId
                + "] has not yet gone into effect, ignoring this trackingCodeId",
            module);
      return "success";
    }
    if (trackingCode.get("thruDate") != null
        && nowStamp.after(trackingCode.getTimestamp("thruDate"))) {
      if (Debug.infoOn())
        Debug.logInfo(
            "The TrackingCode with ID ["
                + trackingCodeId
                + "] has expired, ignoring this trackingCodeId",
            module);
      return "success";
    }

    // persist that info by associating with the current visit
    GenericValue visit = VisitHandler.getVisit(request.getSession());
    if (visit == null) {
      Debug.logWarning(
          "Could not get visit, not associating trackingCode [" + trackingCodeId + "] with visit",
          module);
    } else {
      GenericValue trackingCodeVisit =
          delegator.makeValue(
              "TrackingCodeVisit",
              UtilMisc.toMap(
                  "trackingCodeId",
                  trackingCodeId,
                  "visitId",
                  visit.get("visitId"),
                  "fromDate",
                  UtilDateTime.nowTimestamp(),
                  "sourceEnumId",
                  "TKCDSRC_URL_PARAM"));
      try {
        trackingCodeVisit.create();
      } catch (GenericEntityException e) {
        Debug.logError(e, "Error while saving TrackingCodeVisit", module);
      }
    }

    // write trackingCode cookies with the value set to the trackingCodeId
    // NOTE: just write these cookies and if others exist from other tracking codes they will be
    // overwritten, ie only keep the newest

    // load the properties from the website entity
    String cookieDomain = null;

    String webSiteId = WebSiteWorker.getWebSiteId(request);
    if (webSiteId != null) {
      try {
        GenericValue webSite =
            delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", webSiteId));
        if (webSite != null) {
          cookieDomain = webSite.getString("cookieDomain");
        }
      } catch (GenericEntityException e) {
        Debug.logWarning(
            e, "Problems with WebSite entity; using global default cookie domain", module);
      }
    }

    if (cookieDomain == null) {
      cookieDomain = UtilProperties.getPropertyValue("url", "cookie.domain", "");
    }

    // if trackingCode.trackableLifetime not null and is > 0 write a trackable cookie with name in
    // the form: TKCDT_{trackingCode.trackingCodeTypeId} and timeout will be
    // trackingCode.trackableLifetime
    Long trackableLifetime = trackingCode.getLong("trackableLifetime");
    if (trackableLifetime != null
        && (trackableLifetime.longValue() > 0 || trackableLifetime.longValue() == -1)) {
      Cookie trackableCookie =
          new Cookie(
              "TKCDT_" + trackingCode.getString("trackingCodeTypeId"),
              trackingCode.getString("trackingCodeId"));
      if (trackableLifetime.longValue() > 0)
        trackableCookie.setMaxAge(trackableLifetime.intValue());
      trackableCookie.setPath("/");
      if (cookieDomain.length() > 0) trackableCookie.setDomain(cookieDomain);
      response.addCookie(trackableCookie);
    }

    // if trackingCode.billableLifetime not null and is > 0 write a billable cookie with name in the
    // form: TKCDB_{trackingCode.trackingCodeTypeId} and timeout will be
    // trackingCode.billableLifetime
    Long billableLifetime = trackingCode.getLong("billableLifetime");
    if (billableLifetime != null
        && (billableLifetime.longValue() > 0 || billableLifetime.longValue() == -1)) {
      Cookie billableCookie =
          new Cookie(
              "TKCDB_" + trackingCode.getString("trackingCodeTypeId"),
              trackingCode.getString("trackingCodeId"));
      if (billableLifetime.longValue() > 0) billableCookie.setMaxAge(billableLifetime.intValue());
      billableCookie.setPath("/");
      if (cookieDomain.length() > 0) billableCookie.setDomain(cookieDomain);
      response.addCookie(billableCookie);
    }

    // if site id exist in cookies then it is not required to create it, if exist with different
    // site then create it
    int siteIdCookieAge = (60 * 60 * 24 * 365); // should this be configurable?
    String siteId = request.getParameter("siteId");
    if (UtilValidate.isNotEmpty(siteId)) {
      String visitorSiteIdCookieName = "Ofbiz.TKCD.SiteId";
      String visitorSiteId = null;
      // first try to get the current ID from the visitor cookie
      javax.servlet.http.Cookie[] cookies = request.getCookies();
      if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
          if (cookies[i].getName().equals(visitorSiteIdCookieName)) {
            visitorSiteId = cookies[i].getValue();
            break;
          }
        }
      }

      if (visitorSiteId == null || (visitorSiteId != null && !visitorSiteId.equals(siteId))) {
        // if trackingCode.siteId is  not null  write a trackable cookie with name in the form:
        // Ofbiz.TKCSiteId and timeout will be 60 * 60 * 24 * 365
        Cookie siteIdCookie = new Cookie("Ofbiz.TKCD.SiteId", siteId);
        siteIdCookie.setMaxAge(siteIdCookieAge);
        siteIdCookie.setPath("/");
        if (cookieDomain.length() > 0) siteIdCookie.setDomain(cookieDomain);
        response.addCookie(siteIdCookie);
        // if trackingCode.siteId is  not null  write a trackable cookie with name in the form:
        // Ofbiz.TKCSiteId and timeout will be 60 * 60 * 24 * 365
        Cookie updatedTimeStampCookie =
            new Cookie("Ofbiz.TKCD.UpdatedTimeStamp", UtilDateTime.nowTimestamp().toString());
        updatedTimeStampCookie.setMaxAge(siteIdCookieAge);
        updatedTimeStampCookie.setPath("/");
        if (cookieDomain.length() > 0) updatedTimeStampCookie.setDomain(cookieDomain);
        response.addCookie(updatedTimeStampCookie);
      }
    }

    // if we have overridden logo, css and/or catalogId set some session attributes
    HttpSession session = request.getSession();
    String overrideLogo = trackingCode.getString("overrideLogo");
    if (overrideLogo != null) session.setAttribute("overrideLogo", overrideLogo);
    String overrideCss = trackingCode.getString("overrideCss");
    if (overrideCss != null) session.setAttribute("overrideCss", overrideCss);
    String prodCatalogId = trackingCode.getString("prodCatalogId");
    if (UtilValidate.isNotEmpty(prodCatalogId)) {
      session.setAttribute("CURRENT_CATALOG_ID", prodCatalogId);
      CategoryWorker.setTrail(request, FastList.<String>newInstance());
    }

    // if forward/redirect is needed, do a response.sendRedirect and return null to tell the control
    // servlet to not do any other requests/views
    String redirectUrl = trackingCode.getString("redirectUrl");
    if (UtilValidate.isNotEmpty(redirectUrl)) {
      try {
        response.sendRedirect(redirectUrl);
      } catch (java.io.IOException e) {
        Debug.logError(
            e, "Could not redirect as requested in the trackingCode to: " + redirectUrl, module);
      }
      return null;
    }

    return "success";
  }
Example #11
0
  protected static Element getRootElement(HttpServletRequest request) {
    if (Debug.infoOn()) {
      Debug.log("Applet config file: " + ldapConfig);
    }
    File configFile = new File(ldapConfig);
    FileInputStream configFileIS = null;
    Element rootElement = null;
    try {
      configFileIS = new FileInputStream(configFile);
      Document configDoc =
          UtilXml.readXmlDocument(configFileIS, "LDAP configuration file " + ldapConfig);
      rootElement = configDoc.getDocumentElement();
    } catch (FileNotFoundException e) {
      Debug.logError(e, "Error calling userLogin service", module);
      Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
      String errMsg =
          UtilProperties.getMessage(
              resourceWebapp,
              "loginevents.following_error_occurred_during_login",
              messageMap,
              UtilHttp.getLocale(request));
      request.setAttribute("_ERROR_MESSAGE_", errMsg);
    } catch (SAXException e) {
      Debug.logError(e, "Error calling userLogin service", module);
      Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
      String errMsg =
          UtilProperties.getMessage(
              resourceWebapp,
              "loginevents.following_error_occurred_during_login",
              messageMap,
              UtilHttp.getLocale(request));
      request.setAttribute("_ERROR_MESSAGE_", errMsg);
    } catch (ParserConfigurationException e) {
      Debug.logError(e, "Error calling userLogin service", module);
      Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
      String errMsg =
          UtilProperties.getMessage(
              resourceWebapp,
              "loginevents.following_error_occurred_during_login",
              messageMap,
              UtilHttp.getLocale(request));
      request.setAttribute("_ERROR_MESSAGE_", errMsg);
    } catch (IOException e) {
      Debug.logError(e, "Error calling userLogin service", module);
      Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage());
      String errMsg =
          UtilProperties.getMessage(
              resourceWebapp,
              "loginevents.following_error_occurred_during_login",
              messageMap,
              UtilHttp.getLocale(request));
      request.setAttribute("_ERROR_MESSAGE_", errMsg);
    } finally {
      if (configFileIS != null) {
        try {
          configFileIS.close();
        } catch (IOException e) {
        }
      }
    }

    return rootElement;
  }
Example #12
0
  public boolean start() throws ContainerException {
    ContainerConfig.Container jc = ContainerConfig.getContainer("junit-container", configFile);

    // get the tests to run
    Iterator<ContainerConfig.Container.Property> ti = jc.properties.values().iterator();
    if (ti == null) {
      Debug.log("No tests to load", module);
      return true;
    }

    // load the tests into the suite
    TestSuite suite = new TestSuite();
    while (ti.hasNext()) {
      ContainerConfig.Container.Property prop = ti.next();
      Class<?> clz = null;
      try {
        clz = ObjectType.loadClass(prop.value);
        suite.addTestSuite(clz);
      } catch (Exception e) {
        Debug.logError(e, "Unable to load test suite class : " + prop.value, module);
      }
    }

    // holder for the results
    results = new TestResult();

    // run the tests
    suite.run(results);

    // dispay the results
    Debug.log(
        "[JUNIT] Pass: "******" | # Tests: "
            + results.runCount()
            + " | # Failed: "
            + results.failureCount()
            + " # Errors: "
            + results.errorCount(),
        module);
    if (Debug.infoOn()) {
      Debug.log(
          "[JUNIT] ----------------------------- ERRORS ----------------------------- [JUNIT]",
          module);
      Enumeration<?> err = results.errors();
      if (!err.hasMoreElements()) {
        Debug.log("None");
      } else {
        while (err.hasMoreElements()) {
          Debug.log("--> " + err.nextElement(), module);
        }
      }
      Debug.log(
          "[JUNIT] ------------------------------------------------------------------ [JUNIT]",
          module);
      Debug.log(
          "[JUNIT] ---------------------------- FAILURES ---------------------------- [JUNIT]",
          module);
      Enumeration<?> fail = results.failures();
      if (!fail.hasMoreElements()) {
        Debug.log("None");
      } else {
        while (fail.hasMoreElements()) {
          Debug.log("--> " + fail.nextElement(), module);
        }
      }
      Debug.log(
          "[JUNIT] ------------------------------------------------------------------ [JUNIT]",
          module);
    }

    return true;
  }