List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:cn.guoyukun.spring.web.interceptor.SetCommonDataInterceptor.java
private String getBasePath(HttpServletRequest req) { StringBuffer baseUrl = new StringBuffer(); String scheme = req.getScheme(); int port = req.getServerPort(); //String servletPath = req.getServletPath (); //String pathInfo = req.getPathInfo (); baseUrl.append(scheme); // http, https baseUrl.append("://"); baseUrl.append(req.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { baseUrl.append(':'); baseUrl.append(req.getServerPort()); }/*from w w w. j av a 2 s . c o m*/ return baseUrl.toString(); }
From source file:com.brokenmodel.swats.RouterServlet.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response, ControllerRequest.Type type) { try {/*from www . j a v a2 s . c om*/ URL rootURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + request.getServletPath()); String appRoot = rootURL.getFile(); String htmlRoot = request.getContextPath(); MatchedRoute matchedRoute = controllers.matchRoute(request.getPathInfo()); ControllerRequest controllerRequest = new ControllerRequest(request, response, appRoot, htmlRoot, matchedRoute.getUrlParams(), type, handleMultipart(request), getDataSource()); AbstractController controller = matchedRoute.getController(); controller.doRequest(controllerRequest); } catch (Throwable t) { log(t); try { // only will work if output stream has not been opened PrintWriter pw = new PrintWriter(response.getWriter()); pw.append("<pre>"); pw.append("We're sorry - an error has occurred:\n\n"); t.printStackTrace(pw); pw.append("</pre>"); } catch (Throwable t2) { } } }
From source file:org.ow2.chameleon.everest.servlet.EverestServlet.java
/** * Computes the HTTP url of the given path. * The url is computed thanks to the request. * @param request the HTTP Request//from www . jav a 2 s . c om * @param path the path * @return the URL pointing to the given path */ private String toURL(HttpServletRequest request, Path path) { return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + EVEREST_SERVLET_PATH + "/" + path.toString(); }
From source file:org.apache.wookie.controller.WidgetInstancesController.java
/** * Returns the absolute URL of the widget instance including id key, proxy * url and opensocial token/*from ww w . j av a 2 s . c o m*/ * * @param request * the current request * @param instance * the widget instance * @return the absolute URL * @throws IOException */ protected static String getUrl(HttpServletRequest request, IWidgetInstance instance) throws IOException { String url = ""; IStartFile[] startFiles = instance.getWidget().getStartFiles() .toArray(new IStartFile[instance.getWidget().getStartFiles().size()]); IStartFile sf = (IStartFile) LocalizationUtils.getLocalizedElement(startFiles, new String[] { instance.getLang() }); // Try default locale if no appropriate localization found if (sf == null) sf = (IStartFile) LocalizationUtils.getLocalizedElement(startFiles, null); // No start file found, so throw an exception if (sf == null) throw new IOException("No start file located for widget " + instance.getWidget().getGuid()); URL urlWidget = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), sf.getUrl()); if (urlWidget.getQuery() != null) { url += urlWidget + "&idkey=" + instance.getIdKey() //$NON-NLS-1$ + "&proxy=" + urlWidgetProxyServer.toExternalForm() //$NON-NLS-1$ + "&st=" + instance.getOpensocialToken(); //$NON-NLS-1$ } else { url += urlWidget + "?idkey=" + instance.getIdKey() //$NON-NLS-1$ + "&proxy=" + urlWidgetProxyServer.toExternalForm() //$NON-NLS-1$ + "&st=" + instance.getOpensocialToken(); //$NON-NLS-1$ } return url; }
From source file:org.apache.struts.webapp.tiles.rssChannel.Channels.java
private String toFullUrl(HttpServletRequest request, String url) { StringBuffer buff = new StringBuffer(); buff.append(request.getScheme()).append("://").append(request.getServerName()); if (request.getServerPort() != 80) { buff.append(":").append(request.getServerPort()); }//from w w w. j ava2 s.c o m buff.append(request.getContextPath()).append(url); return buff.toString(); }
From source file:org.openmrs.module.webservices.rest.web.controller.SwaggerSpecificationController.java
@RequestMapping(method = RequestMethod.GET) public @ResponseBody String getSwaggerSpecification(HttpServletRequest request) throws Exception { String swaggerSpecificationJSON = ""; StringBuilder baseUrl = new StringBuilder(); String scheme = request.getScheme(); int port = request.getServerPort(); baseUrl.append(scheme); // http, https baseUrl.append("://"); baseUrl.append(request.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { baseUrl.append(':'); baseUrl.append(request.getServerPort()); }//w ww . j av a2 s.c o m baseUrl.append(request.getContextPath()); String resourcesUrl = Context.getAdministrationService() .getGlobalProperty(RestConstants.URI_PREFIX_GLOBAL_PROPERTY_NAME, baseUrl.toString()); if (!resourcesUrl.endsWith("/")) { resourcesUrl += "/"; } resourcesUrl += "ws/rest"; String urlWithoutScheme = ""; /* Swagger appends scheme to urls, so we should remove it */ if (scheme.equals("http")) urlWithoutScheme = resourcesUrl.replace("http://", ""); else if (scheme.equals("https")) urlWithoutScheme = resourcesUrl.replace("https://", ""); SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(urlWithoutScheme); swaggerSpecificationJSON = creator.BuildJSON(); return swaggerSpecificationJSON; }
From source file:com.rbmhtechnology.apidocserver.controller.ApiDocController.java
private void addBasicAttributes(Model model, HttpServletRequest request) { String baseUrl = request.getScheme() + "://" + (request.getHeader("Host") != null ? request.getHeader("Host") : "localhost"); model.addAttribute("name", repositoryService.getName()); model.addAttribute("baseUrl", baseUrl); model.addAttribute("defaultClassifier", repositoryService.getDefaultClassifier()); model.addAttribute("applicationVersion", getApplicationVersion()); model.addAttribute("repositoryUrl", repositoryService.getRepositoryUrl()); model.addAttribute("groupIdWhitelist", groupIdWhitelistService.getGroupIdPrefixWhitelist()); }
From source file:org.lockss.util.UrlUtil.java
/** Reconstructs the URL the client used to make the request, using * information in the HttpServletRequest object. The returned URL * contains a protocol, server name, port number, and server path, but it * does not include query string parameters. This method duplicates the * deprecated method from javax.servlet.http.HttpUtils * @param req - a HttpServletRequest object containing the client's request * @return string containing the reconstructed URL */// w w w. j a va 2 s . co m // http://hostname.com:80/mywebapp/servlet/MyServlet/a/b;c=123?d=789 public static String getRequestURL(HttpServletRequest req) { String scheme = req.getScheme(); // http String serverName = req.getServerName(); // hostname.com int serverPort = req.getServerPort(); // 80 String contextPath = req.getContextPath(); // /mywebapp String servletPath = req.getServletPath(); // /servlet/MyServlet String pathInfo = req.getPathInfo(); // /a/b;c=123 // String queryString = req.getQueryString(); // d=789 // Reconstruct original requesting URL StringBuffer sb = new StringBuffer(40); sb.append(scheme); sb.append("://"); sb.append(serverName); sb.append(":"); sb.append(serverPort); sb.append(contextPath); sb.append(servletPath); if (pathInfo != null) { sb.append(pathInfo); } // if (queryString != null) { // sb.append("?"); // sb.append(queryString); // } return sb.toString(); }
From source file:ManageDatasetFiles.java
public String getServerUrl(HttpServletRequest request) { String uri = request.getScheme() + "://" + // "http" + ":// request.getServerName() + // "myhost" ":" + // ":" request.getServerPort() + // "8080" request.getRequestURI();//+ // "/people" int lastbackslash = uri.lastIndexOf("/"); return uri.substring(0, lastbackslash); }
From source file:org.apache.struts.webapp.tiles.rssChannel.RssChannelsAction.java
/** * Compute Full local url from an url starting with "/". *//*ww w .j ava 2 s . c o m*/ private String toFullUrl(HttpServletRequest request, String url) { StringBuffer buff = new StringBuffer(); buff.append(request.getScheme()).append("://").append(request.getServerName()); if (request.getServerPort() != 80) { buff.append(":").append(request.getServerPort()); } buff.append(request.getContextPath()).append(url); return buff.toString(); }