List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
protected String getDomainURL(HttpServletRequest request) { // reconstruct the start of the URL StringBuffer domainURL = new StringBuffer(); String scheme = request.getScheme(); int port = request.getServerPort(); domainURL.append(scheme);//from w w w . j av a2 s .c o m domainURL.append("://"); domainURL.append(request.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { domainURL.append(':'); domainURL.append(request.getServerPort()); } domainURL.append('/'); return domainURL.toString(); }
From source file:com.appeligo.showfiles.ShowFlv.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); PrintWriter out = response.getWriter(); /*/*from w ww.j av a 2s .c o m*/ try { Velocity.init(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ init(getServletConfig()); VelocityContext context = new VelocityContext(); context.put("title", "Flip.TV Video Recall"); context.put("server", request.getServerName()); context.put("contextPath", request.getContextPath()); context.put("flvUrl", request.getPathInfo()); int start = 0; try { start = Integer.parseInt(request.getParameter("start")); } catch (NumberFormatException e) { } int duration = 0; try { duration = Integer.parseInt(request.getParameter("duration")); } catch (NumberFormatException e) { } context.put("start", new Integer(start)); // Note, there is a bug in FlowPlayer where you have to add the // start time TWICE to the duration to get the "workable" value // for the "end" parameter. if (duration > 0) { context.put("end", new Integer((start * 2) + duration)); } Template template = null; try { template = getTemplate("/FlowPlayer.vm"); } catch (ResourceNotFoundException rnfe) { // couldn't find the template rnfe.printStackTrace(); } catch (ParseErrorException pee) { // syntax error : problem parsing the template pee.printStackTrace(); } catch (MethodInvocationException mie) { // something invoked in the template // threw an exception mie.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } try { template.merge(context, out); // sw ); } catch (ResourceNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseErrorException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MethodInvocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) { final String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }// w w w. j a va 2 s .c o m final int serverPort = this.portResolver.getServerPort(request); final String scheme = request.getScheme(); final RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); if (this.forceHttps && "http".equals(scheme)) { final Integer httpsPort = this.portMapper.lookupHttpsPort(Integer.valueOf(serverPort)); if (httpsPort != null) { // Overwrite scheme and port in the redirect URL urlBuilder.setScheme("https"); urlBuilder.setPort(httpsPort.intValue()); } else { logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); } } return urlBuilder.getUrl(); }
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
protected String getContextURL(HttpServletRequest request) { // reconstruct the start of the URL StringBuffer contextURL = new StringBuffer(); String scheme = request.getScheme(); int port = request.getServerPort(); contextURL.append(scheme);/* w w w .j a va 2 s . co m*/ contextURL.append("://"); contextURL.append(request.getServerName()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { contextURL.append(':'); contextURL.append(request.getServerPort()); } contextURL.append(request.getContextPath()); return contextURL.toString(); }
From source file:com.yoshio3.modules.AzureADServerAuthModule.java
private String getCurrentUri(HttpServletRequest request) { String scheme = request.getScheme(); int serverPort = request.getServerPort(); String portNumberString = ""; if (!((scheme.equals("http") && serverPort == 80) || (scheme.equals("https") && serverPort == 443))) { portNumberString = ":" + String.valueOf(serverPort); }/*from w ww . ja va 2s . c om*/ String uri = scheme + "://" + request.getServerName() + portNumberString + request.getRequestURI(); return uri; }
From source file:com.wabacus.system.assistant.WabacusAssistant.java
public String replaceAllImgPathInExportDataFile(HttpServletRequest request, String displayvalue) { String serverName = request.getServerName(); String serverPort = String.valueOf(request.getServerPort()); return replaceAllImgPathInExportDataFile("http://" + serverName + ":" + serverPort, displayvalue); }
From source file:org.sample.jsonp.TestServlet.java
/** * Processes requests for both HTTP/*from ww w .j a v a 2 s .c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(MoxyJsonFeature.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/endpoint"); JsonObject jsonObject = Json.createObjectBuilder().add("apple", "red").add("banana", "yellow").build(); JsonObject jo = target.request().post(Entity.entity(jsonObject, MediaType.APPLICATION_JSON), JsonObject.class); out.println(jo); out.println("</body>"); out.println("</html>"); } }
From source file:com.meltmedia.cadmium.servlets.ErrorPageFilter.java
/** * <p>Traps calls to sendError and catches all throwables from the chain. Error pages from the content * service are rendered in these situations if:</p> * <ul>//from w w w . j ava2s. co m * <li>The status code is a 400 or 500.</li> * <li>The response has not been committed.</li> * </ul> * <p>Any thrown Throwable is treated like a 500 error.</p> * * @param req the servlet request being handled. * @param res the servlet response being written to. * @param chain the filter chain to execute inside this filter. * @throws IOException if there is a problem rendering the error page. * @throws ServletException never. */ @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { try { final HttpServletRequest httpReq = (HttpServletRequest) req; final HttpServletResponse httpRes = (HttpServletResponse) res; if (ignorePath != null) { String contextPath = httpReq.getContextPath(); String uri = httpReq.getRequestURI(); if (contextPath != null && contextPath.trim().length() > 0 && uri.startsWith(contextPath)) { uri = uri.substring(contextPath.length()); } if (uri.startsWith(ignorePath)) { log.trace("Not handling errors for request server:{}, uri:{}", httpReq.getServerName(), uri); chain.doFilter(req, res); return; } } HttpServletResponse wrappedRes = new HttpServletResponseWrapper(httpRes) { @Override public void sendError(int sc) throws IOException { ErrorPageFilter.this.sendError(sc, null, httpReq, httpRes); } @Override public void sendError(int sc, String msg) throws IOException { ErrorPageFilter.this.sendError(sc, msg, httpReq, httpRes); } }; try { chain.doFilter(httpReq, wrappedRes); } catch (Throwable e) { log.trace("Handling thrown Exception", e); sendError(500, null, httpReq, httpRes); } } catch (IOException ioe) { log.trace("Failed in error filter.", ioe); throw ioe; } catch (ServletException se) { log.trace("Failed in error filter.", se); throw se; } catch (Throwable t) { log.trace("Failed in error filter.", t); throw new ServletException(t); } }
From source file:org.kew.rmf.reconciliation.ws.ReconciliationServiceController.java
/** * Retrieve reconciliation service metadata. *///from ww w . j a v a2s .com @RequestMapping(value = "/reconcile/{configName}", method = { RequestMethod.GET, RequestMethod.POST }, produces = "application/json; charset=UTF-8") public ResponseEntity<String> getMetadata(HttpServletRequest request, @PathVariable String configName, @RequestParam(value = "callback", required = false) String callback, Model model) throws JsonGenerationException, JsonMappingException, IOException { logger.info("{}: Get Metadata request", configName); String myUrl = request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : (":" + request.getServerPort())); String basePath = servletContext.getContextPath() + "/reconcile/" + configName; Metadata metadata; try { metadata = reconciliationService.getMetadata(configName); } catch (MatchExecutionException e) { return new ResponseEntity<String>(e.toString(), HttpStatus.NOT_FOUND); } if (metadata != null) { String metadataJson = jsonMapper.writeValueAsString(metadata).replace("LOCAL", myUrl).replace("BASE", basePath); return new ResponseEntity<String>(wrapResponse(callback, metadataJson), HttpStatus.OK); } return null; }