List of usage examples for javax.servlet.http HttpServletRequest getRemotePort
public int getRemotePort();
From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java
private Map<String, String> getRequestInfo(PortletRequest request) { Map<String, String> requestResult = new TreeMap<String, String>(); HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request); requestResult.put("RemoteUser", httpRequest.getRemoteUser()); requestResult.put("P3P.USER_LOGIN_ID", getRemoteUserId(request)); requestResult.put("RemoteAddr", httpRequest.getRemoteAddr()); requestResult.put("RemoteHost", httpRequest.getRemoteHost()); requestResult.put("RemotePort", String.valueOf(httpRequest.getRemotePort())); requestResult.put("AuthType", httpRequest.getAuthType()); requestResult.put("CharacterEncoding", httpRequest.getCharacterEncoding()); requestResult.put("ContentLength", String.valueOf(httpRequest.getContentLength())); requestResult.put("ContentType", httpRequest.getContentType()); requestResult.put("ContextPath", httpRequest.getContextPath()); requestResult.put("LocalAddr", httpRequest.getLocalAddr()); requestResult.put("Locale", httpRequest.getLocale().toString()); requestResult.put("LocalName", httpRequest.getLocalName()); requestResult.put("LocalPort", String.valueOf(httpRequest.getLocalPort())); requestResult.put("Method", httpRequest.getMethod()); requestResult.put("PathInfo", httpRequest.getPathInfo()); requestResult.put("PathTranslated", httpRequest.getPathTranslated()); requestResult.put("Protocol", httpRequest.getProtocol()); requestResult.put("QueryString", httpRequest.getQueryString()); requestResult.put("RequestedSessionId", httpRequest.getRequestedSessionId()); requestResult.put("RequestURI", httpRequest.getRequestURI()); requestResult.put("Scheme", httpRequest.getScheme()); requestResult.put("ServerName", httpRequest.getServerName()); requestResult.put("ServerPort", String.valueOf(httpRequest.getServerPort())); requestResult.put("ServletPath", httpRequest.getServletPath()); return requestResult; }
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 w ww .j av a2 s. co m }
From source file:com.iLabs.spice.handler.LoginHandler.java
public String loginAction() throws IOException, ClassNotFoundException, SQLException { String result = "failure"; try {/*from w w w .j a v a 2s. c o m*/ java.util.Date date = new java.util.Date(); System.out.println("The Start Time (1): " + new Timestamp(date.getTime())); ProfileBean ownerProfile = (ProfileBean) getSessionScope().get("ownerProfile"); ProfileBean currentProfile = (ProfileBean) getSessionScope().get("currentProfile"); if (ownerProfile == null) { ownerProfile = new ProfileBean(); } if (currentProfile == null) { currentProfile = new ProfileBean(); } IPerson person = (IPerson) ServiceLocator.getService("PersonSvc"); UserAuth authPerson = person.authenticateUser(currentProfile.getUserAuth().getUserName(), currentProfile.getUserAuth().getUserPassword()); //This condition checks if the authPerson returned from authentication service is null or not. //If the user who enters the site is an authenticated user, the user's info and his friends info is stored in //currentProfile as well as ownerProfile bean. if (authPerson != null && authPerson.getUserName() != null) { //Save the QoS Level of the user (Platinum, Gold or Silver) qoslevel = currentProfile.getUserAuth().getProfile().getProfileURL(); ClientResource clientResource = new ClientResource("http://192.168.1.41:8180/sessions"); Session session = new Session(); ConnectionParty owner = new ConnectionParty(); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance() .getExternalContext().getRequest(); owner.setIp(request.getHeader("X-Forwarded-For")); owner.setPort(request.getRemotePort()); System.out.println("Client address: " + request.getRemoteAddr()); System.out.println("Client port: " + request.getRemotePort()); if (qoslevel.equalsIgnoreCase("GOLD")) { owner.setSip_uri("sip:alice@openepc.test"); session.setApplicationId("surveillance"); } else { if (qoslevel.equalsIgnoreCase("Silver")) { owner.setSip_uri("sip:bob@openepc.test"); session.setApplicationId("IMS"); } else { owner.setSip_uri("sip:charlie@openepc.test"); session.setApplicationId("YouTube"); } } System.out.println("REQUEST " + request.getRemoteAddr() + request.getRemoteHost() + request.getLocalPort() + request.getRequestURI()); System.out.println(request.getHeader("X-Forwarded-For")); ConnectionParty otherParty = new ConnectionParty(); otherParty.setIp("192.168.1.41"); otherParty.setPort(8080); otherParty.setSip_uri(""); session.setSessionOwner(owner); session.setSessionOtherParty(otherParty); ServiceInfo serviceInfo = new ServiceInfo(); //serviceInfo.setServiceId("Webcamstream"); setBandwidthAndPriority(serviceInfo, qoslevel); serviceInfo.setMediaType(MediaType.DATA); serviceInfo.setLifeTime(6000); session.setServiceInfo(serviceInfo); Representation response = clientResource.post(session); String resp = response.getText(); SI.setSessionID(resp.substring(70, 125)); System.out.println("200 OK RESPONSE IS: " + resp); String s = SI.getSessionID(); System.out.println("SESSION ID IS: " + s); UserFriends userFriends = person.getFriends(authPerson.getUserId()); ownerProfile.setUserAuth(authPerson); ownerProfile.setUserFriends(userFriends); currentProfile.setUserAuth(authPerson); currentProfile.setUserFriends(userFriends); getSessionScope().put("ownerProfile", ownerProfile); getSessionScope().put("currentProfile", currentProfile); DatabaseConnector r = new DatabaseConnector(); r.Write(s, authPerson.getUserId()); //authPerson.getProfile().setProfileURL(s); System.out.println("User " + authPerson.getProfile().getFirstName() + " " + authPerson.getProfile().getProfileURL()); System.out.println("The Start Time (3): " + new Timestamp(date.getTime())); result = "success"; } else { // if user is not an authenticate user, then error message is generated. FacesMessage message = new FacesMessage("Please Check Username and password"); FacesContext.getCurrentInstance().addMessage("login:user_password", message); } } catch (SysException e) { e.printStackTrace(); } return result; }
From source file:simplestorage.controllers.HashtableController.java
@RequestMapping(value = "/hashtable/{key}", method = RequestMethod.POST) public ModelAndView put(HttpServletRequest request, HttpServletResponse response, @PathVariable String key) throws IOException { // If I can't read from input stream, there is nothing I can do about it. InputStream input = request.getInputStream(); int length = request.getContentLength(); if (length != -1) { byte[] value = new byte[length]; input.read(value, 0, request.getContentLength()); String userIP = request.getRemoteAddr(); int userPort = request.getRemotePort(); hashtableSvc.put(key, new String(value, "UTF-8"), String.format("%s:%s", userIP, userPort)); return constructModelAndView(gson.toJson(Boolean.TRUE)); } else {/*from w ww.j a v a2s . c o m*/ throw new IOException("Content-Length unknown."); } }
From source file:se.vgregion.portal.auditlog.AuditLogInfoContainerFactoryImpl.java
/** * {@inheritDoc}// ww w. j a va 2s . com */ public AuditLogInfoContainer getAuditLogInfoContainer(String patientId, PortletRequest portletRequest) { HttpServletRequest httpServletRequest = requestResponseConverter.getHttpServletRequest(portletRequest); AuditLogInfoContainer container = new AuditLogInfoContainer(); container.setPatientId(patientId); String searcherId = getUserId(portletRequest); container.setSearcherId(searcherId); container.setRemoteIpAddress(getRemoteIpAddress(httpServletRequest)); container.setRemoteHost(httpServletRequest.getRemoteHost()); container.setRemotePort(httpServletRequest.getRemotePort()); String remoteUser = getUserLoginId(portletRequest); container.setRemoteUser(remoteUser); return container; }
From source file:com.streamsets.pipeline.lib.http.HttpReceiverServlet.java
@VisibleForTesting protected boolean validateAppId(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { boolean valid = false; String ourAppId = null;/*from ww w . ja v a2 s . c om*/ try { ourAppId = getReceiver().getAppId().get(); } catch (StageException e) { throw new IOException("Cant resolve credential value", e); } String requestor = req.getRemoteAddr() + ":" + req.getRemotePort(); String reqAppId = req.getHeader(HttpConstants.X_SDC_APPLICATION_ID_HEADER); if (reqAppId == null && receiver.isAppIdViaQueryParamAllowed()) { reqAppId = getQueryParameters(req).get(HttpConstants.SDC_APPLICATION_ID_QUERY_PARAM)[0]; } if (reqAppId == null) { LOG.warn("Request from '{}' missing appId, rejected", requestor); res.sendError(HttpServletResponse.SC_FORBIDDEN, "Missing 'appId'"); } else if (!ourAppId.equals(reqAppId)) { LOG.warn("Request from '{}' invalid appId '{}', rejected", requestor, reqAppId); res.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid 'appId'"); } else { valid = true; } return valid; }
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++;//from w ww. java2 s . c om 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:com.sixt.service.framework.jetty.RpcReadException.java
public String toJson(HttpServletRequest req) { JsonObject obj = new JsonObject(); Enumeration<String> h = req.getHeaderNames(); while (h.hasMoreElements()) { String hKey = h.nextElement(); String hValue = req.getHeader(hKey); obj.addProperty("request_header_" + hKey, hValue); }/* w w w . jav a 2 s . c o m*/ obj.addProperty("exception_message", this.getMessage()); obj.addProperty("request_query_string", req.getQueryString()); obj.addProperty("request_url", req.getRequestURL().toString()); obj.addProperty("request_remote_addr", req.getRemoteAddr()); obj.addProperty("request_remote_port", req.getRemotePort()); obj.addProperty("request_remote_host", req.getRemoteHost()); obj.addProperty("request_remote_user", req.getRemoteUser()); String readBody = "success"; // read the whole remaining body and put the joined base64 encoded message into the json object try { byte[] ba = IOUtils.toByteArray(this.in); byte[] combined; if ((ba != null) && (this.incomplete != null)) { combined = new byte[ba.length + this.incomplete.length]; System.arraycopy(incomplete, 0, combined, 0, this.incomplete.length); System.arraycopy(ba, 0, combined, this.incomplete.length, ba.length); obj.addProperty("request_body", Base64.getEncoder().encodeToString(combined)); } else if (ba != null) { combined = ba; } else if (this.incomplete != null) { combined = this.incomplete; } else { readBody = "body is empty"; } } catch (Exception ex) { readBody = String.format("failed because: %s", ex.getCause()); } obj.addProperty("read_body", readBody); return obj.toString(); }
From source file:org.jasig.cas.support.pac4j.web.flow.ClientBackChannelAction.java
private void log(HttpServletRequest request) { logger.debug("========================================================="); logger.debug("ClientBackChannelAction.doExecute: "); logger.debug("request.method: " + request.getMethod()); logger.debug("request.requestURI: " + request.getRequestURI()); logger.debug("request.queryString: " + request.getQueryString()); logger.debug("request. host port remoteaddress: " + request.getRemoteHost() + " " + request.getRemotePort() + " " + request.getRemoteAddr()); logger.debug("request. parameter:"); Enumeration enParams = request.getParameterNames(); while (enParams.hasMoreElements()) { String paramName = (String) enParams.nextElement(); logger.debug(paramName + ": " + request.getParameter(paramName)); }/* www . j av a 2 s . c o m*/ logger.debug("request. attribute:"); Enumeration enParams2 = request.getAttributeNames(); while (enParams2.hasMoreElements()) { String paramName2 = (String) enParams2.nextElement(); logger.debug(paramName2 + ": " + request.getAttribute(paramName2)); } logger.debug("========================================================="); }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;// www .j av a 2 s .c o 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; }