Java Code Examples for javax.servlet.http.HttpServletRequest#getRequestURL()
The following examples show how to use
javax.servlet.http.HttpServletRequest#getRequestURL() .
These examples are extracted from open source projects.
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 Project: gerbil File: MainController.java License: 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 Project: JVoiceXML File: HelloWorldServlet.java License: 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 3
Source Project: pinpoint File: ControllerExceptionHandler.java License: Apache License 2.0 | 5 votes |
private String getRequestUrl(HttpServletRequest request) { if (request.getRequestURL() == null) { return UNKNOWN; } return request.getRequestURL().toString(); }
Example 4
Source Project: tlaplus File: URLHttpServlet.java License: 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 5
Source Project: logbook-kai File: ProxyServlet.java License: 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 6
Source Project: FHIR File: FHIRRestServletFilter.java License: 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 7
Source Project: edison-microservice File: UrlHelper.java License: 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 8
Source Project: java-technology-stack File: ServletServerHttpRequest.java License: 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 9
Source Project: howsun-javaee-framework File: Webs.java License: 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 10
Source Project: qpid-broker-j File: HttpManagementUtil.java License: 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 11
Source Project: rdf4j File: WorkbenchGateway.java License: 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 12
Source Project: singleton File: CollectSourceValidationInterceptor.java License: 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 13
Source Project: rice File: KRADUtils.java License: 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 14
Source Project: springMvc4.x-project File: DemoAnnoController.java License: 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 15
Source Project: springMvc4.x-project File: DemoAnnoController.java License: 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 Project: hasting File: SimpleServletExceptionHandler.java License: 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 Project: openid4java File: ConsumerServlet.java License: 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 18
Source Project: springMvc4.x-project File: DemoAnnoController.java License: 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 Project: springMvc4.x-project File: DemoAnnoController.java License: 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 20
Source Project: jeecg-boot File: SpringContextUtils.java License: 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(); }