List of usage examples for javax.servlet.http HttpServletRequest getProtocol
public String getProtocol();
From source file:com.ebay.pulsar.collector.servlet.IngestServlet.java
private String readRequestHead(HttpServletRequest request) { try {/*ww w . ja v a 2s . c om*/ StringBuffer sb = new StringBuffer(); sb.append(request.getMethod()).append(" "); sb.append(request.getProtocol()).append(" "); sb.append(request.getPathInfo()).append("\n"); // Jetstream getHeaderNames has issues. Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); sb.append(name).append(": "); sb.append(request.getHeader(name)).append("\n"); } return sb.toString(); } catch (Throwable ex) { return null; } }
From source file:com.hypersocket.session.json.SessionUtils.java
public void addAPISession(HttpServletRequest request, HttpServletResponse response, Session session) { Cookie cookie = new Cookie(HYPERSOCKET_API_SESSION, session.getId()); cookie.setMaxAge(60 * session.getTimeout()); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setPath("/"); //cookie.setDomain(request.getServerName()); response.addCookie(cookie);/*from w w w .j a v a 2s . c o m*/ }
From source file:com.hypersocket.session.json.SessionUtils.java
public void setLocale(HttpServletRequest request, HttpServletResponse response, String locale) { request.getSession().setAttribute(USER_LOCALE, locale); Cookie cookie = new Cookie(HYPERSOCKET_LOCALE, locale); cookie.setMaxAge(Integer.MAX_VALUE); cookie.setPath("/"); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setDomain(request.getServerName()); response.addCookie(cookie);/*from w w w . j av a 2s. co m*/ }
From source file:com.mtgi.analytics.servlet.ServletRequestBehaviorTrackingAdapter.java
public BehaviorEvent start(ServletRequest request) { HttpServletRequest req = (HttpServletRequest) request; if (!match(req)) return null; String eventName = getEventName(req); BehaviorEvent event = manager.createEvent(eventType, eventName); //log relevant request data and parameters to the event. EventDataElement data = event.addData(); data.add("uri", req.getRequestURI()); data.add("protocol", req.getProtocol()); data.add("method", req.getMethod()); data.add("remote-address", req.getRemoteAddr()); data.add("remote-host", req.getRemoteHost()); if (this.parameters != null) { EventDataElement parameters = data.addElement(PARAMETERS_ELEMENT); //include only configured parameters for (String name : this.parameters) { String[] values = request.getParameterValues(name); if (values != null) addParameter(parameters, name, values); }//from w w w . j a v a 2 s. com } else { EventDataElement parameters = data.addElement(PARAMETERS_ELEMENT); //include all parameters for (Enumeration<?> params = request.getParameterNames(); params.hasMoreElements();) { String name = (String) params.nextElement(); String[] values = request.getParameterValues(name); addParameter(parameters, name, values); } } manager.start(event); return event; }
From source file:eionet.util.Util.java
/** * * @param request/*from w w w . j a va 2s.c o m*/ * @return */ public static String getBaseHref(HttpServletRequest request) { String protocol = request.getProtocol().toLowerCase(); int i = protocol.indexOf('/'); if (i >= 0) { protocol = protocol.substring(0, i); } StringBuffer buf = new StringBuffer(protocol); buf.append("://").append(request.getServerName()); if (request.getServerPort() > 0) { buf.append(":").append(request.getServerPort()); } if (request.getContextPath() != null) { buf.append(request.getContextPath()); } if (buf.toString().endsWith("/") == false) { buf.append("/"); } return buf.toString(); }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;//from w w w . ja v a2s . co m String name; StringBuffer html = new StringBuffer(); //session HttpSession session = request.getSession(); html.append("<div><b>session:</b></div><ul>"); html.append(createLI("Id", session.getId())); html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString())); html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString())); //session:attributes e = session.getAttributeNames(); html.append("<li>attributes:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, String.valueOf(session.getAttribute(name)))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //request html.append("<div><b>request:</b></div><ul>"); html.append(createLI("URL", request.getRequestURL().toString())); html.append(createLI("QueryString", request.getQueryString())); html.append(createLI("Method", request.getMethod())); html.append(createLI("CharacterEncoding", request.getCharacterEncoding())); html.append(createLI("ContentType", request.getContentType())); html.append(createLI("Protocol", request.getProtocol())); html.append(createLI("RemoteAddr", request.getRemoteAddr())); html.append(createLI("RemoteHost", request.getRemoteHost())); html.append(createLI("RemotePort", request.getRemotePort() + "")); html.append(createLI("RemoteUser", request.getRemoteUser())); html.append(createLI("ServerName", request.getServerName())); html.append(createLI("ServletPath", request.getServletPath())); html.append(createLI("ServerPort", request.getServerPort() + "")); html.append(createLI("Scheme", request.getScheme())); html.append(createLI("LocalAddr", request.getLocalAddr())); html.append(createLI("LocalName", request.getLocalName())); html.append(createLI("LocalPort", request.getLocalPort() + "")); html.append(createLI("Locale", request.getLocale().toString())); //request:headers e = request.getHeaderNames(); html.append("<li>Headers:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getHeader(name))); } html.append("</ul></li>\r\n"); //request:parameters e = request.getParameterNames(); html.append("<li>Parameters:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getParameter(name))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //response html.append("<div><b>response:</b></div><ul>"); html.append(createLI("CharacterEncoding", response.getCharacterEncoding())); html.append(createLI("ContentType", response.getContentType())); html.append(createLI("BufferSize", response.getBufferSize() + "")); html.append(createLI("Locale", response.getLocale().toString())); html.append("<ul>\r\n"); return html; }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * Dump out things from HttpServletRequest object * // w ww.j a v a 2 s.c o m * @param req * @return */ public static String dumpRequest(HttpServletRequest req) { if (req == null) return null; char column = ':', rtn = '\n', space = ' '; StringBuilder builder = new StringBuilder(req.getMethod()); builder.append(space).append(req.getRequestURL().toString()).append(space).append(req.getProtocol()) .append(rtn); Enumeration<String> headers = req.getHeaderNames(); builder.append("HEADERS:\n"); String header; for (; headers.hasMoreElements();) { header = headers.nextElement(); builder.append(header).append(column).append(req.getHeader(header)).append(rtn); } builder.append("COOKIES:\n"); Cookie cookie; Cookie[] cookies = req.getCookies(); if (!ValidationUtils.isEmpty(cookies)) { for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; builder.append(cookie.getName()).append(column).append(GsonUtils.format(cookie)).append(rtn); } } builder.append("BODY:\n"); Map<String, String[]> params = req.getParameterMap(); for (String name : params.keySet()) { builder.append(name).append(ShenStrings.DELIMITER_DOT); builder.append(name.matches(PASS_PATTERN) ? params.get(SECRET_STRING) : params.get(name)); } return builder.toString(); }
From source file:gov.redhawk.rap.internal.PluginProviderServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Path path = new Path(req.getRequestURI()); String pluginId = path.lastSegment(); if (pluginId.endsWith(".jar")) { pluginId = pluginId.substring(0, pluginId.length() - 4); }// w ww .j a va 2 s . c om final Bundle b = Platform.getBundle(pluginId); if (b == null) { final String protocol = req.getProtocol(); final String msg = "Plugin does not exist: " + pluginId; if (protocol.endsWith("1.1")) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } return; } final File file = FileLocator.getBundleFile(b); resp.setContentType("application/octet-stream"); if (file.isFile()) { final String contentDisposition = "attachment; filename=\"" + file.getName() + "\""; resp.setHeader("Content-Disposition", contentDisposition); resp.setContentLength((int) file.length()); final FileInputStream istream = new FileInputStream(file); try { IOUtils.copy(istream, resp.getOutputStream()); } finally { istream.close(); } resp.flushBuffer(); } else { final String contentDisposition = "attachment; filename=\"" + file.getName() + ".jar\""; resp.setHeader("Content-Disposition", contentDisposition); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Manifest man = new Manifest(new FileInputStream(new File(file, "META-INF/MANIFEST.MF"))); final JarOutputStream out = new JarOutputStream(outputStream, man); final File binDir = new File(file, "bin"); if (binDir.exists()) { addFiles(out, Path.ROOT, binDir.listFiles()); for (final File f : file.listFiles()) { if (!f.getName().equals("bin")) { addFiles(out, Path.ROOT, f); } } } else { addFiles(out, Path.ROOT, file.listFiles()); } out.close(); outputStream.close(); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); resp.setContentLength(outputStream.size()); try { IOUtils.copy(inputStream, resp.getOutputStream()); } finally { inputStream.close(); } resp.flushBuffer(); } }
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);//w w w . j ava 2 s . c o m // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:it.greenvulcano.gvesb.debug.DebuggerServlet.java
private void dump(HttpServletRequest request, StringBuffer log) throws IOException { String hN;/*from w w w .j ava 2s . c om*/ log.append("-- DUMP HttpServletRequest START").append("\n"); log.append("Method : ").append(request.getMethod()).append("\n"); log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n"); log.append("Scheme : ").append(request.getScheme()).append("\n"); log.append("IsSecure : ").append(request.isSecure()).append("\n"); log.append("Protocol : ").append(request.getProtocol()).append("\n"); log.append("ContextPath : ").append(request.getContextPath()).append("\n"); log.append("PathInfo : ").append(request.getPathInfo()).append("\n"); log.append("QueryString : ").append(request.getQueryString()).append("\n"); log.append("RequestURI : ").append(request.getRequestURI()).append("\n"); log.append("RequestURL : ").append(request.getRequestURL()).append("\n"); log.append("ContentType : ").append(request.getContentType()).append("\n"); log.append("ContentLength : ").append(request.getContentLength()).append("\n"); log.append("CharacterEncoding : ").append(request.getCharacterEncoding()).append("\n"); log.append("---- Headers START\n"); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { hN = headerNames.nextElement(); log.append("[" + hN + "]="); Enumeration<String> headers = request.getHeaders(hN); while (headers.hasMoreElements()) { log.append("[" + headers.nextElement() + "]"); } log.append("\n"); } log.append("---- Headers END\n"); log.append("---- Body START\n"); log.append(IOUtils.toString(request.getInputStream(), "UTF-8")).append("\n"); log.append("---- Body END\n"); log.append("-- DUMP HttpServletRequest END \n"); }