List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:org.n52.web.common.RequestUtils.java
/** * Get the request {@link URL} without the query parameter * * @return Request {@link URL} without query parameter * @throws IOException//from ww w .ja v a 2 s. c om * @throws URISyntaxException */ public static String resolveQueryLessRequestUrl() throws IOException, URISyntaxException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest(); URL url = new URL(request.getRequestURL().toString()); String scheme = url.getProtocol(); String userInfo = url.getUserInfo(); String host = url.getHost(); int port = url.getPort(); String path = request.getRequestURI(); if (path != null && path.endsWith("/")) { path = path.substring(0, path.length() - 1); } URI uri = new URI(scheme, userInfo, host, port, path, null, null); return uri.toString(); }
From source file:org.n52.web.common.RequestUtils.java
/** * Get the full request {@link URL} including the query parameter * * @return Request {@link URL} with query parameter * @throws IOException//from ww w .j ava2 s . c o m * @throws URISyntaxException */ public static String resolveFullRequestUrl() throws IOException, URISyntaxException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest(); URL url = new URL(request.getRequestURL().toString()); String scheme = url.getProtocol(); String userInfo = url.getUserInfo(); String host = url.getHost(); int port = url.getPort(); String path = request.getRequestURI(); if (path != null && path.endsWith("/")) { path = path.substring(0, path.length() - 1); } String query = request.getQueryString(); URI uri = new URI(scheme, userInfo, host, port, path, query, null); return uri.toString(); }
From source file:com.safetys.framework.jmesa.util.ExportUtils.java
/** * @deprecated This method has not turned out to be very useful and will be returned in a future release. *//* w w w .java 2s.c om*/ @Deprecated private static void exportPdf(TableFacade tableFacade, String filePath) { View view = tableFacade.getView(); byte[] contents = view.getBytes(); System.setProperty("xr.load.xml-reader", "org.ccil.cowan.tagsoup.Parser"); System.setProperty("xr.util-logging.loggingEnabled", "false"); System.setProperty("xr.util-logging.java.util.logging.ConsoleHandler.level", "WARN"); System.setProperty("xr.util-logging..level", "WARN"); System.setProperty("xr.util-logging.plumbing.level", "WARN"); System.setProperty("xr.util-logging.plumbing.config.level", "WARN"); System.setProperty("xr.util-logging.plumbing.exception.level", "WARN"); System.setProperty("xr.util-logging.plumbing.general.level", "WARN"); System.setProperty("xr.util-logging.plumbing.init.level", "WARN"); System.setProperty("xr.util-logging.plumbing.load.level", "WARN"); System.setProperty("xr.util-logging.plumbing.load.xml-entities.level", "WARN"); System.setProperty("xr.util-logging.plumbing.match.level", "WARN"); System.setProperty("xr.util-logging.plumbing.cascade.level", "WARN"); System.setProperty("xr.util-logging.plumbing.css-parse.level", "WARN"); System.setProperty("xr.util-logging.plumbing.layout.level", "WARN"); System.setProperty("xr.util-logging.plumbing.render.level", "WARN"); XRLog.setLoggingEnabled(false); ITextRenderer renderer = new ITextRenderer(); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(contents)); HttpServletRequest request = (HttpServletRequest) tableFacade.getWebContext().getBackingObject(); renderer.setDocument(doc, request.getRequestURL().toString()); renderer.layout(); File file = new File(filePath); FileOutputStream output = new FileOutputStream(file); renderer.createPDF(output); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Not able to generate the PDF"); } }
From source file:com.app.framework.web.mvc.ActionMap.java
public static ActionMap Init(ServletRequest request, ServletResponse response) throws IOException { ActionMap actMap = null;/*from ww w. ja v a2 s . co m*/ HttpServletRequest req = ((HttpServletRequest) request); String s1 = req.getContextPath(); String s2 = req.getRequestURI(); String s3 = req.getRequestURL().toString(); String fullUrl = getFullURL(req).toLowerCase(); if (fullUrl.contains(".css") || fullUrl.contains(".js") || fullUrl.contains(".html") || fullUrl.contains(".jpg") || fullUrl.contains(".png") || fullUrl.contains(".gif") || fullUrl.contains(".icon")) { return null; } Gson g = new Gson(); String requestedResource = s2.replace(s1 + "/", ""); String[] urlParts = requestedResource.split("/"); if (urlParts != null && urlParts.length >= 2) { String controller = urlParts[0]; String action = urlParts[1]; String jsonFilePath = req.getServletContext().getRealPath("/WEB-INF/action-map.json"); String json = FileUtils.readFileToString(new File(jsonFilePath), "utf-8"); Type listType = new TypeToken<Map<String, ControllerInfo>>() { }.getType(); Map<String, ControllerInfo> map = g.fromJson(json, listType); String method = req.getMethod(); if (map.containsKey(controller)) { actMap = new ActionMap(); ControllerInfo cInfo = map.get(controller); ActionInfo mInfo = cInfo.getActions().get(action).get(method); actMap.setController(cInfo.getControllerClassName()); actMap.setAction(mInfo.getMethodName()); actMap.setModel(mInfo.getModelClassName()); } } return actMap; }
From source file:com.ineunet.knife.upload.WebPaths.java
/** * @param request HttpServletRequest/* www.j a v a 2 s . c o m*/ */ public static void init(HttpServletRequest request) { if (request == null) { return; } if (inited) return; // init rootUrl String reqUrl = request.getRequestURL().toString(); String reqUri = request.getRequestURI(); int index = reqUrl.length() - reqUri.length(); rootUrl = reqUrl.substring(0, index) + request.getContextPath(); // init rootPath rootPath = request.getSession().getServletContext().getRealPath("/"); // set flag inited = true; }
From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java
/** * Gen http request dump.//from w w w. j av a 2 s . c o m * * @param req the req * @return the string */ @SuppressWarnings("unchecked") public static String genHttpRequestDump(HttpServletRequest req) { StringBuilder sb = new StringBuilder(); sb.append("method: ").append(req.getMethod()).append('\n')// .append("requestURL: ").append(req.getRequestURL()).append('\n')// .append("servletPath: ").append(req.getServletPath()).append('\n')// .append("requestURI: ").append(req.getRequestURI()).append('\n') // .append("queryString: ").append(req.getQueryString()).append('\n') // .append("pathInfo: ").append(req.getPathInfo()).append('\n')// .append("contextPath: ").append(req.getContextPath()).append('\n') // .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') // .append("localName: ").append(req.getLocalName()).append('\n') // .append("contentLength: ").append(req.getContentLength()).append('\n') // ; sb.append("Header:\n"); for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) { String hn = en.nextElement(); sb.append(" ").append(hn).append(": ").append(req.getHeader(hn)).append("\n"); } sb.append("Attr: \n"); Enumeration en = req.getAttributeNames(); for (; en.hasMoreElements();) { String k = (String) en.nextElement(); Object v = req.getAttribute(k); sb.append(" ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n'); } return sb.toString(); }
From source file:org.apache.atlas.web.util.Servlets.java
/** * Returns the full URL of the given request. * * @param httpRequest an HTTP servlet request * @return the full URL, including the query string *//*from ww w . j a v a 2 s . com*/ public static String getRequestURL(HttpServletRequest httpRequest) { final StringBuilder url = new StringBuilder(100).append(httpRequest.getRequestURL()); if (httpRequest.getQueryString() != null) { url.append('?').append(httpRequest.getQueryString()); } return url.toString(); }
From source file:com.tremolosecurity.unison.u2f.util.U2fUtil.java
public static String getApplicationId(HttpServletRequest request) throws MalformedURLException { StringBuffer appID = new StringBuffer(); URL url = new URL(request.getRequestURL().toString()); appID.append(url.getProtocol()).append("://").append(url.getHost()); /*if (! (url.getProtocol().equalsIgnoreCase("http") && (url.getPort() == 80 || url.getPort() <= 0)) || ! ( url.getProtocol().equalsIgnoreCase("https") && (url.getPort() == 443 || url.getPort() <= 0)) ) { appID.append(':').append(url.getPort()); }*//*from ww w . ja v a 2 s . co m*/ if (url.getPort() > 0) { appID.append(':').append(url.getPort()); } return appID.toString(); }
From source file:br.com.webbudget.infraestructure.configuration.ApplicationUtils.java
/** * Constroi a URL base da aplicacao/*w w w. j av a 2 s . co m*/ * * @return a URL base da aplicaco + contexto */ public static String buildBaseURL() { final FacesContext facesContext = FacesContext.getCurrentInstance(); final HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest(); final StringBuilder builder = new StringBuilder(); String actualPath = request.getRequestURL().toString(); builder.append(actualPath.replace(request.getRequestURI(), "")); builder.append(request.getContextPath()); return builder.toString(); }
From source file:com.ai.smart.common.helper.util.RequestUtils.java
/** * /*from w w w . j a va2 s. c o m*/ * <p> * HttpServletRequest.getRequestURL+"?"+HttpServletRequest.getQueryString * * @param request * @return */ public static String getLocation(HttpServletRequest request) { UrlPathHelper helper = new UrlPathHelper(); StringBuffer buff = request.getRequestURL(); String uri = request.getRequestURI(); String origUri = helper.getOriginatingRequestUri(request); buff.replace(buff.length() - uri.length(), buff.length(), origUri); String queryString = helper.getOriginatingQueryString(request); if (queryString != null) { buff.append("?").append(queryString); } return buff.toString(); }