List of usage examples for javax.servlet.http HttpServletRequest getLocalPort
public int getLocalPort();
From source file:fr.scc.elo.controller.EloController.java
@GET @Produces({ MediaType.TEXT_HTML }) @Path("/welcome") public Response welcome(@Context HttpServletRequest http, @PathParam("taille") Integer taille) { Map<String, Object> map = new HashMap<>(); map.put("ip", http.getLocalAddr() + ":" + http.getLocalPort()); return Response.ok(new Viewable("/welcome", map)).build(); }
From source file:net.sourceforge.subsonic.controller.MultiController.java
private void updatePortAndContextPath(HttpServletRequest request) { int port = Integer.parseInt(System.getProperty("subsonic.port", String.valueOf(request.getLocalPort()))); int httpsPort = Integer.parseInt(System.getProperty("subsonic.httpsPort", "0")); String contextPath = request.getContextPath().replace("/", ""); if (settingsService.getPort() != port) { settingsService.setPort(port);/*from w ww .j a v a2s . co m*/ settingsService.save(); } if (settingsService.getHttpsPort() != httpsPort) { settingsService.setHttpsPort(httpsPort); settingsService.save(); } if (!ObjectUtils.equals(settingsService.getUrlRedirectContextPath(), contextPath)) { settingsService.setUrlRedirectContextPath(contextPath); settingsService.save(); } }
From source file:service.FileUploadSvc.java
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON)/* ww w .j a v a 2 s. com*/ @Path("/multipleFiles") public String uploadFile(@Context HttpServletRequest request) { String actualPath = servletContext.getRealPath(""); String serverPath = "http://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath(); String responseStatus = SUCCESS_RESPONSE; String candidateName = null; String fileLocation = ""; fileLocation = actualPath + File.separator + "uploads"; System.out.println(fileLocation); //checks whether there is a file upload request or not if (ServletFileUpload.isMultipartContent(request)) { final FileItemFactory factory = new DiskFileItemFactory(); final ServletFileUpload fileUpload = new ServletFileUpload(factory); try { /* * parseRequest returns a list of FileItem * but in old (pre-java5) style */ final List items = fileUpload.parseRequest(request); if (items != null) { final Iterator iter = items.iterator(); while (iter.hasNext()) { final FileItem item = (FileItem) iter.next(); String itemName = item.getName(); if (itemName != null) { itemName = FilenameUtils.getName(itemName); } final String fieldName = item.getFieldName(); final String fieldValue = item.getString(); System.out.println("File: " + itemName); if (item.isFormField()) { candidateName = fieldValue; System.out.println("Field Name: " + fieldName + ", Field Value: " + fieldValue); System.out.println("Candidate Name: " + candidateName); } else { final File savedFile = new File(fileLocation + File.separator + itemName); System.out.println("Saving the file: " + savedFile.getName()); item.write(savedFile); } } } } catch (Exception e) { responseStatus = Utils.constructFailed("upload", false, e.getLocalizedMessage()); } } return responseStatus; }
From source file:com.ecsteam.cloudlaunch.controller.RestServices.java
@RequestMapping("/statistics") public ApplicationStatistics statistics(HttpServletRequest request) throws IOException { ApplicationStatistics statistics = statisticsProvider.getCurrentStatistics(); statistics.setHost(request.getLocalAddr()); statistics.setPort(request.getLocalPort()); return statistics; }
From source file:org.onebusaway.presentation.impl.ProxyServlet.java
/**** * Private Method//from w w w . ja va 2s. c om ****/ private String proxyUrl(HttpServletRequest req) { String pathInfo = req.getRequestURI(); if (_source != null) pathInfo = pathInfo.replaceFirst(_source, ""); String url = _target + pathInfo; if (!_target.startsWith("http")) url = "http://" + req.getLocalName() + ":" + req.getLocalPort() + url; if (req.getQueryString() != null) url += "?" + req.getQueryString(); return url; }
From source file:com.flipkart.phantom.runtime.impl.jetty.filter.ServletTraceFilter.java
/** * Submits the service request endpoint data * @param request the service request// www.ja v a 2 s .c o m */ private void submitEndpoint(HttpServletRequest request) { if (!endPointSubmitter.endPointSubmitted()) { String contextPath = request.getContextPath(); String localAddr = request.getLocalAddr(); int localPort = request.getLocalPort(); endPointSubmitter.submit(localAddr, localPort, contextPath); LOGGER.debug("Setting endpoint: addr: {}, port: {}, contextpath: " + contextPath, localAddr, localPort); } }
From source file:org.easyrec.controller.aop.LoggedInCheckAspect.java
private void initPath(HttpServletRequest request) { localName = request.getLocalName();//w w w .ja va 2s . c om localName = localName.equals("0.0.0.0") ? "localhost" : localName; this.webappPath = request.getContextPath(); this.extendedWebAppPath = request.getScheme() + "://" + localName + ":" + request.getLocalPort() + webappPath; PUBLIC_SITES = Sets.newHashSet(Collections2.transform(PUBLIC_SITES, new Function<String, String>() { public String apply(@Nullable String input) { StringBuilder result = new StringBuilder(webappPath); result.append('/'); result.append(input); return result.toString(); } })); }
From source file:org.madsonic.controller.MultiController.java
private void updatePortAndContextPath(HttpServletRequest request) { int port = Integer.parseInt(System.getProperty("madsonic.port", String.valueOf(request.getLocalPort()))); int httpsPort = Integer.parseInt(System.getProperty("madsonic.httpsPort", "0")); String contextPath = request.getContextPath().replace("/", ""); if (settingsService.getPort() != port) { settingsService.setPort(port);//from w w w . ja v a2 s . c om settingsService.save(); } if (settingsService.getHttpsPort() != httpsPort) { settingsService.setHttpsPort(httpsPort); settingsService.save(); } if (!ObjectUtils.equals(settingsService.getUrlRedirectContextPath(), contextPath)) { settingsService.setUrlRedirectContextPath(contextPath); settingsService.save(); } }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponseTest.java
@Test public void testResolveGatewayParams() throws Exception { UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)) .andReturn(rewriter).anyTimes(); FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes(); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(request.getScheme()).andReturn("mock-scheme").anyTimes(); EasyMock.expect(request.getLocalName()).andReturn("mock-host").anyTimes(); EasyMock.expect(request.getLocalPort()).andReturn(42).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn("/mock-path").anyTimes(); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(rewriter, context, config, request, response); UrlRewriteResponse rewriteResponse = new UrlRewriteResponse(config, request, response); List<String> url = rewriteResponse.resolve("gateway.url"); assertThat(url, hasItems(new String[] { "mock-scheme://mock-host:42/mock-path" })); List<String> scheme = rewriteResponse.resolve("gateway.scheme"); assertThat(scheme, hasItems(new String[] { "mock-scheme" })); List<String> host = rewriteResponse.resolve("gateway.host"); assertThat(host, hasItems(new String[] { "mock-host" })); List<String> port = rewriteResponse.resolve("gateway.port"); assertThat(port, hasItems(new String[] { "42" })); List<String> addr = rewriteResponse.resolve("gateway.addr"); assertThat(addr, hasItems(new String[] { "mock-host:42" })); List<String> address = rewriteResponse.resolve("gateway.addr"); assertThat(address, hasItems(new String[] { "mock-host:42" })); List<String> path = rewriteResponse.resolve("gateway.path"); assertThat(path, hasItems(new String[] { "/mock-path" })); }
From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug(request.getPathInfo() + ":" + request.getQueryString()); Properties resultProperties = new Properties(); resultProperties.put("local.host.name", request.getLocalName()); resultProperties.put("local.host.port", Integer.toString(request.getLocalPort())); resultProperties.put("remote.host.name", request.getRemoteHost()); resultProperties.put("remote.host.port", Integer.toString(request.getRemotePort())); resultProperties.put("makeCall.count", Integer.toString(makeCallCount)); resultProperties.put("terminateCall.count", Integer.toString(terminateCallCount)); resultProperties.put("incomingCall.count", Integer.toString(((ServiceImpl) service).getIncomingCount())); String result = "something or rather"; String resultKey = "callid"; if (request.getPathInfo().equalsIgnoreCase("/makecall")) { makeCallCount++;/*w ww . j av a 2 s.c o m*/ String caller = request.getParameter("caller"); String callee = request.getParameter("callee"); result = this.service.makeCall(caller, callee); } else if (request.getPathInfo().equalsIgnoreCase("/terminatecall")) { terminateCallCount++; String callid = request.getParameter("callid"); service.terminateCall(callid); result = callid; } else if (request.getPathInfo().equalsIgnoreCase("/reset")) { makeCallCount = 0; terminateCallCount = 0; ((ServiceImpl) service).setIncomingCount(0); } else if (request.getPathInfo().equalsIgnoreCase("/status")) { result = "Sample SpringRing web application"; resultKey = "status"; } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } resultProperties.put(resultKey, result); resultProperties.store(response.getOutputStream(), "Response generated on:"); }