List of usage examples for javax.servlet.http HttpServletRequest getServerPort
public int getServerPort();
From source file:fr.xebia.cocktail.CocktailRssView.java
@Override protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) { feed.setTitle("Cocktail App"); feed.setDescription("Java Tutorials and Examples"); feed.setLink(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()); super.buildFeedMetadata(model, feed, request); }
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 www . j a va2 s. c om return baseUrl.toString(); }
From source file:inet.util.FileStorage.java
public FileStorage(inet.common.jsf.request.MultipartRequest multipartRequest, String targe) { this.multipartRequest = multipartRequest; HttpServletRequest request = (HttpServletRequest) multipartRequest.getRequest(); realPath = request.getServletContext().getRealPath("/"); realUri = "http://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath(); this.targe = targe; }
From source file:cn.vlabs.umt.ui.servlet.LoginServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { addCrossDomainHeader(response);/*from w w w . ja v a 2 s . com*/ saveParams(request); request.setAttribute("basePath", request.getServerPort()); LocalLogin login = new LocalLogin(factory); login.doLogin(request, response); }
From source file:com.pontecultural.flashcards.DeckController.java
@RequestMapping(method = RequestMethod.GET) public String getUploadForm(HttpServletRequest req, Locale locale, Model model) { logger.info("List of decks"); // compute base URL to allow client to call us back. String baseURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath();/* w w w.j a v a 2 s .c o m*/ model.addAttribute("baseURL", baseURL); model.addAttribute("decks", jdbcFlashcardsDao.fetchAllDecks()); return "deckList"; }
From source file:org.stockwatcher.web.rss.BaseRssView.java
protected String getStockLink(HttpServletRequest request, String symbol) { StringBuilder link = new StringBuilder(request.getScheme()); link.append("://"); link.append(request.getServerName()); link.append(":"); link.append(request.getServerPort()); link.append(request.getContextPath()); link.append("/main/stocks/"); link.append(symbol);/*www .ja va 2 s. c o m*/ return link.toString(); }
From source file:com.brokenmodel.swats.RouterServlet.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response, ControllerRequest.Type type) { try {/* w ww. ja va2 s . c o m*/ 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.apache.jetspeed.security.mfa.util.ServerData.java
/** * A C'tor that takes a HTTP Request object and * builds the server data from its contents * * @param req The HTTP Request/*from w w w.jav a 2 s .c om*/ */ public ServerData(HttpServletRequest req) { setServerName(req.getServerName()); setServerPort(req.getServerPort()); setServerScheme(req.getScheme()); setScriptName(req.getServletPath()); setContextPath(req.getContextPath()); }
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/*w w w . jav a 2 s .co 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.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()); }/*from ww w . j a va2 s . com*/ 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; }