List of usage examples for javax.servlet.http HttpServletRequest getLocalName
public String getLocalName();
From source file:architecture.user.security.authentication.impl.DefaultAuthenticationProvider.java
protected String getLocalName() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest();//www. j ava2 s . c o m return request.getLocalName(); }
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 w w. j ava 2s .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:"); }
From source file:net.duckling.ddl.service.oauth.impl.OAuthServiceImpl.java
@Override public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response, boolean sendBody) throws IOException, ServletException { String realm = (request.isSecure()) ? "https://" : "http://"; realm += request.getLocalName(); OAuthServlet.handleException(response, e, realm, sendBody); }
From source file:org.reallysqs.server.views.QueueListView.java
@SuppressWarnings("unchecked") @Override/*from ww w.j a va 2 s . c om*/ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); Map<String, Queue> queues = (Map<String, Queue>) model.get("queues"); Collection<Queue> queueList = queues.values(); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); for (Queue queue : queueList) { outputStream.print("<QueueUrl>"); outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName()); outputStream.print("</QueueUrl>"); } outputStream.print(epilogue); }
From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java
private void initializeServlet2point4Properties(HttpServletRequest servletRequest) { ServletContext context = servletRequest.getSession().getServletContext(); if (context.getMajorVersion() > 1 && context.getMinorVersion() > 3) { remotePort = servletRequest.getRemotePort(); localName = servletRequest.getLocalName(); localAddr = servletRequest.getLocalAddr(); localPort = servletRequest.getLocalPort(); }//from www .ja v a2 s . c om }
From source file:de.highbyte_le.weberknecht.request.taglibs.SiteBaseLinkTag.java
protected String getBaseUrl() throws JspException { if (!(pageContext.getRequest() instanceof HttpServletRequest)) throw new JspException("unable to get a HttpServletRequest"); StringBuilder baseUrl = new StringBuilder(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); try {/*from ww w. j av a2 s .c om*/ ContextConfig conf = new ContextConfig(); baseUrl.append(conf.getValue("webapp_base_url")); if (baseUrl.charAt(baseUrl.length() - 1) != '/') baseUrl.append("/"); } catch (NamingException e) { logger.error("getTokenUrl() - naming exception while fetching webapp_base_url: " + e.getMessage()); //$NON-NLS-1$ logger.warn("automatically generating base URL"); String contextPath = request.getContextPath(); String localHost = request.getLocalName(); int localPort = request.getLocalPort(); if (baseUrl.length() > 0) //just to be sure baseUrl = new StringBuilder(); baseUrl.append("http://").append(localHost).append(":").append(localPort + contextPath).append("/"); } return baseUrl.toString(); }
From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { // debug informations log.debug("doGet"); log.debug("context path: " + request.getContextPath()); log.debug("character encoding: " + request.getCharacterEncoding()); log.debug("content length: " + request.getContentLength()); log.debug("content type: " + request.getContentType()); log.debug("local addr: " + request.getLocalAddr()); log.debug("local name: " + request.getLocalName()); log.debug("local port: " + request.getLocalPort()); log.debug("method: " + request.getMethod()); log.debug("path info: " + request.getPathInfo()); log.debug("path translated: " + request.getPathTranslated()); log.debug("protocol: " + request.getProtocol()); log.debug("query string: " + request.getQueryString()); log.debug("requested session id: " + request.getRequestedSessionId()); log.debug("Host header: " + request.getServerName()); log.debug("servlet path: " + request.getServletPath()); log.debug("request URI: " + request.getRequestURI()); @SuppressWarnings("unchecked") final Enumeration<String> header_names = request.getHeaderNames(); while (header_names.hasMoreElements()) { final String header_name = header_names.nextElement(); log.debug("header name: " + header_name); @SuppressWarnings("unchecked") final Enumeration<String> header_values = request.getHeaders(header_name); while (header_values.hasMoreElements()) log.debug(" " + header_name + " => " + header_values.nextElement()); }// w w w .java 2 s . c om if (request.getCookies() != null) for (Cookie cookie : request.getCookies()) { log.debug("cookie:"); log.debug("cookie comment: " + cookie.getComment()); log.debug("cookie domain: " + cookie.getDomain()); log.debug("cookie max age: " + cookie.getMaxAge()); log.debug("cookie name: " + cookie.getName()); log.debug("cookie path: " + cookie.getPath()); log.debug("cookie value: " + cookie.getValue()); log.debug("cookie version: " + cookie.getVersion()); log.debug("cookie secure: " + cookie.getSecure()); } @SuppressWarnings("unchecked") final Enumeration<String> parameter_names = request.getParameterNames(); while (parameter_names.hasMoreElements()) { final String parameter_name = parameter_names.nextElement(); log.debug("parameter name: " + parameter_name); final String[] parameter_values = request.getParameterValues(parameter_name); for (final String parameter_value : parameter_values) log.debug(" " + parameter_name + " => " + parameter_value); } // parse request String target_scheme = null; String target_host; int target_port; // request.getPathInfo() is url decoded final String[] path_info_parts = request.getPathInfo().split("/"); if (path_info_parts.length >= 2) target_scheme = path_info_parts[1]; if (path_info_parts.length >= 3) { target_host = path_info_parts[2]; try { if (path_info_parts.length >= 4) target_port = new Integer(path_info_parts[3]); else target_port = 80; } catch (final NumberFormatException ex) { log.warn(ex); target_port = 80; } } else { target_scheme = "http"; target_host = "www.google.com"; target_port = 80; } log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port); // create forwarding request final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port); final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection(); // be transparent for accept-language headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_languages = request.getHeaders("accept-language"); while (accepted_languages.hasMoreElements()) target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement()); // be transparent for accepted headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_content = request.getHeaders("accept"); while (accepted_content.hasMoreElements()) target_connection.setRequestProperty("Accept", accepted_content.nextElement()); }
From source file:eu.comvantage.dataintegration.SparulSimulationServlet.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// w w w. java2s.c o m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String eventID = ""; if (request.getParameterMap().containsKey("eventID")) eventID = request.getParameter("eventID"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String uri = request.getRequestURI(); ServletContext context = getServletContext(); String serverName = ""; if (request.getLocalName().startsWith("0")) { serverName = "localhost"; } else { serverName = request.getLocalName(); } simulateEvent(eventID, new String("http://" + serverName + ":" + request.getLocalPort() + request.getContextPath() + "/QueryDistributionServiceImpl/SPARUL")); out.write("'" + eventID + "' simulated. "); }
From source file:org.archive.wayback.webapp.AccessPoint.java
/** * Construct an absolute URL that points to the root of the context that * recieved the request, including a trailing "/". * /*ww w.j av a2 s . com*/ * @return String absolute URL pointing to the Context root where the * request was revieved. */ private String getAbsoluteContextPrefix(HttpServletRequest httpRequest, boolean useRequestServer) { StringBuilder prefix = new StringBuilder(); prefix.append(WaybackConstants.HTTP_URL_PREFIX); String waybackPort = null; if (useRequestServer) { prefix.append(httpRequest.getLocalName()); waybackPort = String.valueOf(httpRequest.getLocalPort()); } else { prefix.append(httpRequest.getServerName()); waybackPort = String.valueOf(httpRequest.getServerPort()); } if (!waybackPort.equals(WaybackConstants.HTTP_DEFAULT_PORT)) { prefix.append(":").append(waybackPort); } String contextPath = getContextPath(httpRequest); prefix.append(contextPath); return prefix.toString(); }