Skip to content

Instantly share code, notes, and snippets.

@nshaw
Created September 11, 2012 12:43
Show Gist options
  • Save nshaw/3698146 to your computer and use it in GitHub Desktop.
Save nshaw/3698146 to your computer and use it in GitHub Desktop.
Make HTTP request available to JSON services
public String getJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String className = ParamUtil.getString(request, "serviceClassName");
boolean useThreadLocal = (className.indexOf("UmpServiceUtil") > 0) || (className.indexOf("MyStreetServiceUtil") > 0);
try {
if (useThreadLocal) {
JSONRequestThreadLocal.setRequest(request);
}
return super.getJSON(mapping, form, request, response);
}
finally {
JSONRequestThreadLocal.setRequest(null);
}
}
public class JSONRequestThreadLocal {
public static HttpServletRequest getRequest() {
return _threadLocal.get();
}
public static void setRequest(HttpServletRequest request) {
if (_log.isDebugEnabled()) {
_log.debug("setRequest " + request);
}
_threadLocal.set(request);
}
private static Log _log = LogFactoryUtil.getLog(JSONRequestThreadLocal.class);
private static ThreadLocal<HttpServletRequest> _threadLocal =
new ThreadLocal<HttpServletRequest>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment