Java Code Examples for javax.servlet.http.HttpServletRequest#getRequestURL()
The following examples show how to use
javax.servlet.http.HttpServletRequest#getRequestURL() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainController.java From gerbil with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") @Deprecated private String getFullURL(HttpServletRequest request) { StringBuffer requestURL = request.getRequestURL(); String queryString = request.getQueryString(); if (queryString == null) { return requestURL.toString(); } else { return requestURL.append('?').append(queryString).toString(); } }
Example 2
Source File: KRADUtils.java From rice with Educational Community License v2.0 | 5 votes |
/** * Get the full url for a request (requestURL + queryString) * * @param request the request * @return the fullUrl */ public static String getFullURL(HttpServletRequest request) { if (request == null) { return null; } StringBuffer requestURL = request.getRequestURL(); String queryString = request.getQueryString(); if (queryString == null) { return requestURL.toString(); } else { return requestURL.append('?').append(queryString).toString(); } }
Example 3
Source File: CollectSourceValidationInterceptor.java From singleton with Eclipse Public License 2.0 | 5 votes |
/** * Collect new source and send to l10n server * * @param request * HttpServletRequest object * @param response * HttpServletResponse object * @param handler * Object * @return a boolean result * @exception Exception */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String logOfUrl = "The request url is: " + request.getRequestURL(); String logOfQueryStr = "The request query string is: " + request.getQueryString(); LOGGER.debug(logOfUrl); LOGGER.debug(logOfQueryStr); try { validate(request, this.sourceLocales); } catch (VIPAPIException e) { LOGGER.warn(e.getMessage()); Response r = new Response(); r.setCode(APIResponseStatus.BAD_REQUEST.getCode()); r.setMessage(e.getMessage()); try { response.getWriter().write( new ObjectMapper().writerWithDefaultPrettyPrinter() .writeValueAsString(r)); return false; } catch (IOException e1) { LOGGER.warn(e1.getMessage()); return false; } } String startHandle = "[thread-" + Thread.currentThread().getId() + "] Start to handle request..."; LOGGER.info(startHandle); LOGGER.info(logOfUrl); LOGGER.info(logOfQueryStr); return true; }
Example 4
Source File: WorkbenchGateway.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns the full URL to the default server on the same server as the given request. * * @param req the request to find the default server relative to * @return the full URL to the default server on the same server as the given request */ private String getDefaultServer(final HttpServletRequest req) { String server = getDefaultServerPath(); if ('/' == server.charAt(0)) { final StringBuffer url = req.getRequestURL(); final StringBuilder path = getServerPath(req); url.setLength(url.indexOf(path.toString())); server = url.append(server).toString(); } return server; }
Example 5
Source File: HttpManagementUtil.java From qpid-broker-j with Apache License 2.0 | 5 votes |
public static String getRequestURL(HttpServletRequest httpRequest) { String url; StringBuilder urlBuilder = new StringBuilder(httpRequest.getRequestURL()); String queryString = httpRequest.getQueryString(); if (queryString != null) { urlBuilder.append('?').append(queryString); } url = urlBuilder.toString(); return url; }
Example 6
Source File: Webs.java From howsun-javaee-framework with Apache License 2.0 | 5 votes |
/** * * @param request * @param isSyncBase64Encoder * @Deprecated * @see Webs#getUrl(HttpServletRequest, UrlCodeType) * @return */ public static String getUrl(HttpServletRequest request, boolean isSyncBase64Encoder){ StringBuffer url = new StringBuffer(request.getAttribute("javax.servlet.forward.servlet_path") == null ? request.getRequestURL() : (String)request.getAttribute("javax.servlet.forward.servlet_path")); String parm = param(request); if (Strings.hasLength(parm)) { url.append("?").append(parm); } return isSyncBase64Encoder ? Codings.base64Encode(url.toString().getBytes()) : url.toString(); //new String(new BASE64Encoder().encode(url.toString().getBytes())); }
Example 7
Source File: ServletServerHttpRequest.java From java-technology-stack with MIT License | 5 votes |
private static URI initUri(HttpServletRequest request) throws URISyntaxException { Assert.notNull(request, "'request' must not be null"); StringBuffer url = request.getRequestURL(); String query = request.getQueryString(); if (StringUtils.hasText(query)) { url.append('?').append(query); } return new URI(url.toString()); }
Example 8
Source File: UrlHelper.java From edison-microservice with Apache License 2.0 | 5 votes |
/** * Returns the baseUri of the request: http://www.example.com:8080/example * * @param request the current HttpServletRequest * @return base uri including protocol, host, port and context path */ public static String baseUriOf(final HttpServletRequest request) { final StringBuffer requestUrl = request.getRequestURL(); return requestUrl != null ? requestUrl.substring(0, requestUrl.indexOf(request.getServletPath())) : ""; }
Example 9
Source File: FHIRRestServletFilter.java From FHIR with Apache License 2.0 | 5 votes |
/** * Get the original request URL from either the HttpServletRequest or a configured Header (in case of re-writing proxies). * * @param request * @return String The complete request URI */ private String getOriginalRequestURI(HttpServletRequest request) { String requestUri = null; // First, check the configured header for the original request URI (in case any proxies have overwritten the user-facing URL) if (originalRequestUriHeaderName != null) { requestUri = request.getHeader(originalRequestUriHeaderName); if (requestUri != null && !requestUri.isEmpty()) { // Try to parse it as a URI to ensure its valid try { URI originalRequestUri = new URI(requestUri); // If its not absolute, then construct an absolute URI (or else JAX-RS will append the path to the current baseUri) if (!originalRequestUri.isAbsolute()) { requestUri = UriBuilder.fromUri(getRequestURL(request)) .replacePath(originalRequestUri.getPath()).build().toString(); } } catch (Exception e) { log.log(Level.WARNING, "Error while computing the original request URI", e); requestUri = null; } } } // If there was no configured header or the header wasn't present, construct it from the HttpServletRequest if (requestUri == null || requestUri.isEmpty()) { StringBuilder requestUriBuilder = new StringBuilder(request.getRequestURL()); String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { requestUriBuilder.append("?").append(queryString); } requestUri = requestUriBuilder.toString(); } return requestUri; }
Example 10
Source File: ProxyServlet.java From logbook-kai with MIT License | 5 votes |
protected URI rewriteURI(HttpServletRequest request) { StringBuffer uri = request.getRequestURL(); String query = request.getQueryString(); if (query != null) uri.append("?").append(query); return URI.create(uri.toString()); }
Example 11
Source File: URLHttpServlet.java From tlaplus with MIT License | 5 votes |
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { // read the URL under which this servlet got accessed, assuming this is // the best hostname under which // the callee can access this host/servlet/resource final StringBuffer requestURL = req.getRequestURL(); url = new URL(requestURL.toString()); addr = url.getProtocol() + "://" + url.getAuthority(); remoteAddr = req.getRemoteAddr(); }
Example 12
Source File: ControllerExceptionHandler.java From pinpoint with Apache License 2.0 | 5 votes |
private String getRequestUrl(HttpServletRequest request) { if (request.getRequestURL() == null) { return UNKNOWN; } return request.getRequestURL().toString(); }
Example 13
Source File: HelloWorldServlet.java From JVoiceXML with GNU Lesser General Public License v2.1 | 5 votes |
/** * Create a simple VoiceXML document containing the hello world phrase. * * @param request * HttpServletRequest object that contains the request the client has * made of the servlet * @param response * HttpServletResponse object that contains the response the servlet * sends to the client * @return Created VoiceXML document, <code>null</code> if an error * occurs. */ private VoiceXmlDocument createHelloWorld(final HttpServletRequest request, final HttpServletResponse response) { final VoiceXmlDocument document; try { document = new VoiceXmlDocument(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); return null; } final Vxml vxml = document.getVxml(); final Form form = vxml.appendChild(Form.class); final Var var = form.appendChild(Var.class); var.setName("message"); var.setExpr("'Goodbye!'"); final Block block = form.appendChild(Block.class); block.addText("Hello World!"); final StringBuffer url = request.getRequestURL(); final String path = request.getServletPath(); url.delete(url.length() - path.length() + 1, url.length()); url.append("Goodbye"); final Submit next = block.appendChild(Submit.class); next.setNext(response.encodeURL(url.toString())); next.setNamelist("message"); return document; }
Example 14
Source File: ConsumerServlet.java From openid4java with Apache License 2.0 | 4 votes |
public Identifier verifyResponse(HttpServletRequest httpReq) throws ServletException { try { // extract the parameters from the authentication response // (which comes in as a HTTP request from the OpenID provider) ParameterList response = new ParameterList(httpReq .getParameterMap()); // retrieve the previously stored discovery information DiscoveryInformation discovered = (DiscoveryInformation) httpReq .getSession().getAttribute("openid-disc"); // extract the receiving URL from the HTTP request StringBuffer receivingURL = httpReq.getRequestURL(); String queryString = httpReq.getQueryString(); if (queryString != null && queryString.length() > 0) receivingURL.append("?").append(httpReq.getQueryString()); // verify the response; ConsumerManager needs to be the same // (static) instance used to place the authentication request VerificationResult verification = manager.verify(receivingURL .toString(), response, discovered); // examine the verification result and extract the verified // identifier Identifier verified = verification.getVerifiedId(); if (verified != null) { AuthSuccess authSuccess = (AuthSuccess) verification .getAuthResponse(); receiveSimpleRegistration(httpReq, authSuccess); receiveAttributeExchange(httpReq, authSuccess); return verified; // success } } catch (OpenIDException e) { // present error to the user throw new ServletException(e); } return null; }
Example 15
Source File: DemoAnnoController.java From springMvc4.x-project with Apache License 2.0 | 4 votes |
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨ public @ResponseBody String remove(HttpServletRequest request) { return "url:" + request.getRequestURL() + " can access"; }
Example 16
Source File: SimpleServletExceptionHandler.java From hasting with MIT License | 4 votes |
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, Exception e) { StringBuffer url = request.getRequestURL(); logger.error(url.toString(),e); }
Example 17
Source File: DemoAnnoController.java From springMvc4.x-project with Apache License 2.0 | 4 votes |
@RequestMapping(produces = "text/plain;charset=UTF-8") // ③ public @ResponseBody String index(HttpServletRequest request) { // ④ return "url:" + request.getRequestURL() + " can access"; }
Example 18
Source File: DemoAnnoController.java From springMvc4.x-project with Apache License 2.0 | 4 votes |
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨ public @ResponseBody String remove(HttpServletRequest request) { return "url:" + request.getRequestURL() + " can access"; }
Example 19
Source File: SpringContextUtils.java From jeecg-boot with Apache License 2.0 | 4 votes |
public static String getDomain(){ HttpServletRequest request = getHttpServletRequest(); StringBuffer url = request.getRequestURL(); return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); }
Example 20
Source File: DemoAnnoController.java From springMvc4.x-project with Apache License 2.0 | 4 votes |
@RequestMapping(produces = "text/plain;charset=UTF-8") // ③ public @ResponseBody String index(HttpServletRequest request) { // ④ return "url:" + request.getRequestURL() + " can access"; }