Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out isEmpty #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions WebPortal/Java/src/main/java/acme/storefront/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package acme.storefront;

public class Util {
public static boolean isEmpty(String str) {
if (str == null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this ever be null?

return true;
}
return str.trim().length() == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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!!!");
}

Expand Down