diff --git a/WebPortal/Java/src/main/java/acme/storefront/InsightsInterceptor.java b/WebPortal/Java/src/main/java/acme/storefront/InsightsInterceptor.java index cf2d175..7c219af 100644 --- a/WebPortal/Java/src/main/java/acme/storefront/InsightsInterceptor.java +++ b/WebPortal/Java/src/main/java/acme/storefront/InsightsInterceptor.java @@ -28,11 +28,11 @@ public Object intercept(ActionRequest actionRequest) throws Exception { HttpSession session = servletRequest.getSession(); String username = (String) session.getAttribute("username"); - if(username != null && !username.equals("")) { + if(!Util.isEmpty(username)) { JavaAgentFacade.addCustomParameter("username", username); } String userid = (String) session.getAttribute("userid"); - if(userid != null && !userid.equals("")) { + if(!Util.isEmpty(userid)) { JavaAgentFacade.addCustomParameter("userid", userid); } diff --git a/WebPortal/Java/src/main/java/acme/storefront/Util.java b/WebPortal/Java/src/main/java/acme/storefront/Util.java new file mode 100644 index 0000000..b762063 --- /dev/null +++ b/WebPortal/Java/src/main/java/acme/storefront/Util.java @@ -0,0 +1,10 @@ +package acme.storefront; + +public class Util { + public static boolean isEmpty(String str) { + if (str == null) { + return true; + } + return str.trim().length() == 0; + } +} diff --git a/WebPortal/Java/src/main/java/acme/storefront/action/BrowsePhoneAction.java b/WebPortal/Java/src/main/java/acme/storefront/action/BrowsePhoneAction.java index 000ff85..4e73458 100644 --- a/WebPortal/Java/src/main/java/acme/storefront/action/BrowsePhoneAction.java +++ b/WebPortal/Java/src/main/java/acme/storefront/action/BrowsePhoneAction.java @@ -41,6 +41,8 @@ public class BrowsePhoneAction { public String browsePhone() throws IOException { String productId = id.toString(); + long start = System.currentTimeMillis(); + logger.debug("Starting Browse Phone ("+ productId +") transaction"); String username = (String) sessionMap.get("username"); @@ -66,7 +68,9 @@ public String browsePhone() throws IOException { JavaAgentFacade.addCustomParameter("BrowsePhoneResult", "success"); - logger.debug("Finished Browse Phone ("+ productId +") transaction"); + long end = System.currentTimeMillis() - start; + + logger.debug("Finished Browse Phone ("+ productId +") transaction in " + String.valueOf(end) + "ms"); return "/browse/phone.jsp"; } diff --git a/WebPortal/Java/src/main/java/acme/storefront/serviceproxy/CouponServiceProxy.java b/WebPortal/Java/src/main/java/acme/storefront/serviceproxy/CouponServiceProxy.java index 791fdd2..071acb3 100644 --- a/WebPortal/Java/src/main/java/acme/storefront/serviceproxy/CouponServiceProxy.java +++ b/WebPortal/Java/src/main/java/acme/storefront/serviceproxy/CouponServiceProxy.java @@ -6,11 +6,14 @@ import com.newrelic.api.agent.Trace; import jodd.json.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class CouponServiceProxy extends ServiceProxy { private String _root; private static final String _route = "/api/v1/coupons"; + private static final Logger logger = LogManager.getLogger(CouponServiceProxy.class); public CouponServiceProxy(String root) { @@ -32,15 +35,16 @@ public String getCoupon(String product_id) throws IOException String url = getServiceUri() + "/" + product_id + "/getCoupon"; String coupon = ""; + logger.info("Calling getCoupon at " + getServiceUri()); String responseJson = getResponse(url); - try{ + try { Map map = jsonParser.parse(responseJson); coupon = (String) map.get("id"); JavaAgentFacade.addCustomParameter("couponCode", coupon); String amount = (String) map.get("id"); JavaAgentFacade.addCustomParameter("couponAmount", amount); - }catch(Exception e){ + } catch(Exception e) { JavaAgentFacade.addCustomParameter("coupon", "FAIL!!!"); }