List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:edu.stanford.epad.epadws.security.EPADSessionOperations.java
public static String getJSessionIDFromRequest(HttpServletRequest servletRequest) { String jSessionID = null;/* w ww. j av a2 s .co m*/ Cookie[] cookies = servletRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) { jSessionID = cookie.getValue(); break; } } } if (jSessionID == null) { log.warning("No JSESSIONID cookie present in request " + servletRequest.getRequestURL()); } else { int comma = jSessionID.indexOf(","); if (comma != -1) { log.warning("Multiple cookies:" + jSessionID); jSessionID = jSessionID.substring(0, comma); } } return jSessionID; }
From source file:com.hangum.tadpole.session.manager.SessionManager.java
/** * logout ./* w w w. j a va 2 s . c o m*/ */ public static void logout() { HttpServletRequest request = RWT.getRequest(); try { HttpSession sStore = request.getSession(); sStore.setAttribute(NAME.USER_SEQ.toString(), 0); sStore.invalidate(); } catch (Throwable e) { // ignore exception } // fixed https://github.com/hangum/TadpoleForDBTools/issues/708 // ps - ? session id ? ? ?. - hangum String[] arryRequestURL = StringUtils.split(request.getRequestURL().toString(), ";"); String browserText = MessageFormat.format("parent.window.location.href = \"{0}\";", arryRequestURL[0]); JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class); executor.execute("setTimeout('" + browserText + "', 100)"); }
From source file:org.impalaframework.extension.mvc.util.RequestModelHelper.java
/** * // w w w .jav a2 s . co m * @param logger * @param request */ public static void maybeDebugRequest(Log logger, HttpServletRequest request) { if (logger.isDebugEnabled()) { logger.debug("#####################################################################################"); logger.debug("---------------------------- Request details ---------------------------------------"); logger.debug("Request context path: " + request.getContextPath()); logger.debug("Request path info: " + request.getPathInfo()); logger.debug("Request path translated: " + request.getPathTranslated()); logger.debug("Request query string: " + request.getQueryString()); logger.debug("Request servlet path: " + request.getServletPath()); logger.debug("Request request URI: " + request.getRequestURI()); logger.debug("Request request URL: " + request.getRequestURL()); logger.debug("Request session ID: " + request.getRequestedSessionId()); logger.debug("------------------------------------------------ "); logger.debug("Parameters ------------------------------------- "); final Enumeration<String> parameterNames = request.getParameterNames(); Map<String, String> parameters = new TreeMap<String, String>(); while (parameterNames.hasMoreElements()) { String name = parameterNames.nextElement(); String value = request.getParameter(name); final String lowerCase = name.toLowerCase(); if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) { value = "HIDDEN"; } parameters.put(name, value); } //now output final Set<String> parameterKeys = parameters.keySet(); for (String key : parameterKeys) { logger.debug(key + ": " + parameters.get(key)); } logger.debug("------------------------------------------------ "); Map<String, Object> attributes = new TreeMap<String, Object>(); logger.debug("Attributes ------------------------------------- "); final Enumeration<String> attributeNames = request.getAttributeNames(); while (attributeNames.hasMoreElements()) { String name = attributeNames.nextElement(); Object value = request.getAttribute(name); final String lowerCase = name.toLowerCase(); if (lowerCase.contains("password") || lowerCase.contains("cardnumber")) { value = "HIDDEN"; } attributes.put(name, value); } //now output final Set<String> keys = attributes.keySet(); for (String name : keys) { Object value = attributes.get(name); logger.debug(name + ": " + (value != null ? value.toString() : value)); } logger.debug("------------------------------------------------ "); logger.debug("#####################################################################################"); } else { if (logger.isInfoEnabled()) { logger.info( "#####################################################################################"); logger.info("Request query string: " + request.getQueryString()); logger.info("Request request URI: " + request.getRequestURI()); logger.info( "#####################################################################################"); } } }
From source file:org.keycloak.example.oauth.ProductDatabaseClient.java
public static List<String> getProducts(HttpServletRequest request, String accessToken) throws Failure { KeycloakSecurityContext session = (KeycloakSecurityContext) request .getAttribute(KeycloakSecurityContext.class.getName()); // The ServletOAuthClient is obtained by getting a context attribute // that is set in the Bootstrap context listener in this project. // You really should come up with a better way to initialize // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code // and take a look how it works. You can also take a look at third-party-cdi example ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext() .getAttribute(ServletOAuthClient.class.getName()); HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(UriUtils.getOrigin(request.getRequestURL().toString()) + "/database/products"); get.addHeader("Authorization", "Bearer " + accessToken); try {//from ww w. ja v a2s .c o m HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { throw new Failure(response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); try { return JsonSerialization.readValue(is, TypedList.class); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.feilong.servlet.http.RequestUtil.java
/** * ????.//from w w w .j a v a 2 s.c o m * <p> * <span style="color:red"> request ? forword</span>,forword?,? {@link RequestAttributes#FORWARD_REQUEST_URI}?? * </p> * * <pre class="code"> * :http://localhost:8080/feilong/requestdemo.jsp?id=2 * <b>:</b>http://localhost:8080/feilong/requestdemo.jsp * </pre> * * : * * <blockquote> * <table border="1" cellspacing="0" cellpadding="4" summary=""> * <tr style="background-color:#ccccff"> * <th align="left"></th> * <th align="left"></th> * </tr> * <tr valign="top"> * <td><span style="color:red">request.getRequestURI()</span></td> * <td>/feilong/requestdemo.jsp</td> * </tr> * <tr valign="top" style="background-color:#eeeeff"> * <td><span style="color:red">request.getRequestURL()</span></td> * <td>http://localhost:8080/feilong/requestdemo.jsp</td> * </tr> * </table> * </blockquote> * * @param request * the request * @return ???? */ public static String getRequestURL(HttpServletRequest request) { String forwardRequestUri = getAttribute(request, RequestAttributes.FORWARD_REQUEST_URI); return isNotNullOrEmpty(forwardRequestUri) ? forwardRequestUri : request.getRequestURL().toString(); }
From source file:de.betterform.agent.web.WebUtil.java
/** * this method is responsible for passing all context information needed by the Adapter and Processor from * ServletRequest to Context. Will be called only once when the form-session is inited (GET). * <p/>/* w ww . j a v a2 s.c om*/ * <p/> * todo: better logging of context params * * @param request the Servlet request to fetch params from * @param httpSession the Http Session context * @param processor the XFormsProcessor which receives the context params * @param sessionkey the key to identify the XFormsSession */ public static void setContextParams(HttpServletRequest request, HttpSession httpSession, XFormsProcessor processor, String sessionkey) throws XFormsConfigException { Map servletMap = new HashMap(); servletMap.put(WebProcessor.SESSION_ID, sessionkey); processor.setContextParam(XFormsProcessor.SUBMISSION_RESPONSE, servletMap); //adding requestURI to context processor.setContextParam(WebProcessor.REQUEST_URI, WebUtil.getRequestURI(request)); //adding request URL to context String requestURL = request.getRequestURL().toString(); processor.setContextParam(WebProcessor.REQUEST_URL, requestURL); // the web app name with an '/' prepended e.g. '/betterform' by default String contextRoot = WebUtil.getContextRoot(request); processor.setContextParam(WebProcessor.CONTEXTROOT, contextRoot); if (LOGGER.isDebugEnabled()) { LOGGER.debug("context root of webapp: " + processor.getContextParam(WebProcessor.CONTEXTROOT)); } String requestPath = ""; URL url = null; String plainPath = ""; try { url = new URL(requestURL); requestPath = url.getPath(); } catch (MalformedURLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } if (requestPath.length() != 0) { //adding request path e.g. '/betterform/forms/demo/registration.xhtml' processor.setContextParam(WebProcessor.REQUEST_PATH, requestPath); //adding filename of requested doc to context String fileName = requestPath.substring(requestPath.lastIndexOf('/') + 1, requestPath.length());//FILENAME xforms processor.setContextParam(FILENAME, fileName); if (requestURL.contains(contextRoot)) { //case1: contextRoot is a part of the URL //adding plainPath which is the part between contextroot and filename e.g. '/forms' for a requestPath of '/betterform/forms/Status.xhtml' plainPath = requestPath.substring(contextRoot.length() + 1, requestPath.length() - fileName.length()); processor.setContextParam(PLAIN_PATH, plainPath); } else {//case2: contextRoot is not a part of the URL take the part previous the filename. String[] urlParts = requestURL.split("/"); plainPath = urlParts[urlParts.length - 2]; } //adding contextPath - requestPath without the filename processor.setContextParam(CONTEXT_PATH, contextRoot + "/" + plainPath); } //adding session id to context processor.setContextParam(HTTP_SESSION_ID, httpSession.getId()); //adding context absolute path to context //EXIST-WORKAROUND: TODO triple check ... //TODO: triple check where this is used. if (request.isRequestedSessionIdValid()) { processor.setContextParam(EXISTDB_USER, httpSession.getAttribute(EXISTDB_USER)); } //adding pathInfo to context - attention: this is only available when a servlet is requested String s1 = request.getPathInfo(); if (s1 != null) { processor.setContextParam(WebProcessor.PATH_INFO, s1); } processor.setContextParam(WebProcessor.QUERY_STRING, (request.getQueryString() != null ? request.getQueryString() : "")); //storing the realpath for webapp String realPath = WebFactory.getRealPath(".", httpSession.getServletContext()); File f = new File(realPath); URI fileURI = f.toURI(); processor.setContextParam(WebProcessor.REALPATH, fileURI.toString()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("real path of webapp: " + realPath); } //storing the TransformerService processor.setContextParam(TransformerService.TRANSFORMER_SERVICE, httpSession.getServletContext().getAttribute(TransformerService.TRANSFORMER_SERVICE)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("TransformerService: " + httpSession.getServletContext().getAttribute(TransformerService.TRANSFORMER_SERVICE)); } //[2] read any request params that are *not* betterForm params and pass them into the context map Enumeration params = request.getParameterNames(); String s; while (params.hasMoreElements()) { s = (String) params.nextElement(); //store all request-params we don't use in the context map of XFormsProcessorImpl String value = request.getParameter(s); processor.setContextParam(s, value); if (LOGGER.isDebugEnabled()) { LOGGER.debug("added request param '" + s + "' added to context"); LOGGER.debug("param value'" + value); } } }
From source file:com.example.ExampleController.java
@RequestMapping("/") public String work(HttpServletRequest request) { String meetUrl = request.getRequestURL().toString() + "/meet"; this.workService.visitMeetEndpoint(meetUrl); return "finished"; }
From source file:org.moserp.common.rest.ExceptionHandlingController.java
public ResponseEntity<Void> handleError(HttpServletRequest req, Exception exception) { logger.error("Request: " + req.getRequestURL() + " raised " + exception); ResponseEntity<Void> responseEntity = new ResponseEntity<Void>(HttpStatus.INTERNAL_SERVER_ERROR); return responseEntity; }
From source file:net.webpasswordsafe.server.controller.SsoController.java
private String getBaseUrl(HttpServletRequest request) { return request.getRequestURL().toString().replace(request.getRequestURI(), request.getContextPath()); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.BaseLoginServlet.java
/** * If we don't have a referrer, send them to the home page. *//*from ww w . ja va 2s .c om*/ protected String figureHomePageUrl(HttpServletRequest req) { StringBuffer url = req.getRequestURL(); String uri = req.getRequestURI(); int authLength = url.length() - uri.length(); String auth = url.substring(0, authLength); return auth + req.getContextPath(); }