Created
September 11, 2012 12:43
-
-
Save nshaw/3698146 to your computer and use it in GitHub Desktop.
Make HTTP request available to JSON services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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