List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:com.provenance.cloudprovenance.traceabilitystore.ws.controler.TraceabilityStoreController.java
@Override @GET/*w ww. j a va 2 s. co m*/ @Path(value = "/{serviceId}/{traceabilityType}") public Response getTraceabilityDocumentId(@PathParam("serviceId") String serviceId, @PathParam("traceabilityType") String traceabilityType, @Context HttpServletRequest request) { if (currentTraceabilityRecordId == null) { logger.warn("Current file record Id does not exist, need to create a new record !!!"); ResponseBuilder rBuilder = Response.status(404); rBuilder.entity("<TraceabilityDocument></TraceabilityDocument>"); return rBuilder.build(); } else { String responseUri = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI() + "/" + currentTraceabilityRecordId; logger.info("Response URI: " + responseUri); logger.info("Returning the current record Id"); ResponseBuilder rBuilder = Response.status(200); String responseContent = trResponse.genTraceabilityRecordIdResponse(currentTraceabilityRecordId, serviceId, defaultFileExtensionOfrecord, responseUri); logger.info("Sending GET resource URI response: " + responseContent); rBuilder.entity(responseContent); return rBuilder.build(); } }
From source file:de.tuttas.servlets.ClientConfig.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j av a 2 s .c om * * @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()) { /* TODO output your page here. You may use following sample code. */ Config c = Config.getInstance(); Set set = c.clientConfig.keySet(); Iterator<?> keys = set.iterator(); while (keys.hasNext()) { String key = (String) keys.next(); out.println("var " + key + "=\"" + c.clientConfig.get(key) + "\";"); } out.println("var debug=" + c.debug + ";"); out.println("var servername=\"" + request.getServerName() + "\";"); out.println("var serverport=" + request.getServerPort() + ";"); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarLoginHtml.java
protected void sendConfirmationEMail(ICFAstSecDeviceObj defDev, HttpServletRequest request, ICFAstSecUserObj confirmUser, ICFAstClusterObj cluster) throws IOException, MessagingException, NamingException { String clusterDescription = cluster.getRequiredDescription(); String thisURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI().toString(); int lastSlash = thisURI.lastIndexOf('/'); String baseURI = thisURI.substring(0, lastSlash); UUID confirmationUUID = confirmUser.getOptionalEMailConfirmationUuid(); String msgBody = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" + "<HTML>\n" + "<BODY>\n" + "<p>\n" + "You requested a new account for " + confirmUser.getRequiredEMailAddress() + " with " + clusterDescription + ".\n" + "<p>" + "Please click on the following link to confirm your email address:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarConfirmEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "\">" + baseURI + "/CFAstSMWarConfirmEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "</A>\n" + "<p>" + "Or click on the following link to cancel the request for a new account:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarCancelEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "\">" + baseURI + "/CFAstSMWarCancelEMailAddressHtml?ConfirmationUUID=" + confirmationUUID.toString() + "</A>\n" + "</BODY>\n" + "</HTML>\n"; CFAstSMWarUtil warUtil = new CFAstSMWarUtil(); warUtil.sendEMailToUser(confirmUser, "You requested an account with " + clusterDescription + "?", msgBody); }
From source file:com.junly.service.helper.TicketHelper.java
/** <p class="detail"> * ???ticket// w w w . ja v a 2 s . c om * </p> * @author junly * @date 2017324 * @param request * @param httpChannelType * @return */ public String getTicket(HttpServletRequest request, HttpChannelType httpChannelType) { Cookie cookies[] = request.getCookies(); String ticket = null; if (null != cookies) { for (Cookie cookie : cookies) { if (StringUtils.equals(ViewContants.LOGIN_TICKET_KEY, cookie.getName())) { ticket = StringUtils.trim(cookie.getValue()); StringBuilder builder = new StringBuilder(httpChannelType.name()); builder.append("?cookieticket=").append(ticket); builder.append("?=").append(request.getServerName()).append("===="); builder.append(cookie.getDomain()); logger.info(builder.toString()); break; } } } // java??cookieheader???, // ???cookie? ?? if (StringUtils.isBlank(ticket)) { ticket = customHeadTicket(request, httpChannelType); } if (StringUtils.isBlank(ticket)) { ticket = StringUtils.trim(request.getParameter(ViewContants.LOGIN_TICKET_KEY)); } return ticket; }
From source file:dk.itst.oiosaml.sp.configuration.ConfigurationHandler.java
protected String getBaseUrl(HttpServletRequest request) { String url = request.getRequestURL().toString(); log.info("url (old method): " + url); // might only be necessary because of my crazy pagekite setup --pdurbin // url = request.getScheme() url = "https" + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI(); log.info("url (new method): " + url); int idx = url.lastIndexOf(request.getServletPath()); return url.substring(0, idx + request.getServletPath().length()); }
From source file:com.hphoto.server.ApiServlet.java
public void addPhoto(Document doc, Element channel, HttpServletRequest request) { assert (request.getParameter("user") != null); assert (request.getParameter("album") != null); String requestUrl = request.getRequestURL().toString(); String base = "http://" + request.getServerName() + (request.getLocalPort() == 80 ? "" : ":" + Integer.toString(request.getLocalPort())); Image[] images = null;/*from w ww . ja v a 2 s. com*/ UserProfile[] users = null; Category category = null; String owner = request.getParameter("user"); String album = request.getParameter("album"); String authKey = request.getParameter("authKey"); boolean api = request.getParameter("feed") != null && request.getParameter("feed").equals("api"); try { users = server.getUser(owner, 1); images = server.getImages(owner, album); category = server.getCategory(owner, album); } catch (IOException e) { return; } if (users == null || users.length == 0) { return; } if (category == null) { return; } if (!category.isOpened()) { if (!category.getAuthkey().equals(authKey)) { return; } } addNode(doc, channel, "atom", "id", base + "/feed/" + request.getParameter("feed") + "/user/" + owner + "/album/" + album); addNode(doc, channel, "lastBuildDate", (new Date()).toString()); addNode(doc, channel, "title", owner + " " + I18nUtil.getText(key, "title", I18nUtil.getLoacl(request))); addNode(doc, channel, "description", ""); //add base,not complete addNode(doc, channel, "link", base + "/" + owner + "/" + album + (category.getAuthkey() != null ? "?authKey=" + category.getAuthkey() : "")); addNode(doc, channel, "managingEditor", owner); addNode(doc, channel, "generator", "hphoto.com"); addNode(doc, channel, "opensearch", "totalResults", "" + (images != null ? images.length : 0)); addNode(doc, channel, "opensearch", "startIndex", "" + 1); addNode(doc, channel, "opensearch", "itemsPerPage", "" + 1000); String lablename = category.getLablename(); String imgurl = category.getImgurl(); String id = imgurl.substring(imgurl.lastIndexOf('/') + 1, imgurl.lastIndexOf('.')); String img = "/image/" + owner + "/" + lablename + "/s" + 160 + "-c/" + id + ".jpg"; Element timage = addNode(doc, channel, "image"); addNode(doc, timage, "url", base + img); addNode(doc, timage, "title", category.getName()); addNode(doc, timage, "link", base + "/" + owner + "/" + lablename + (category.getAuthkey() != null ? "?authKey=" + category.getAuthkey() : "")); if (api) { //api data here } if (images != null) { //channel for (Image image : images) { Element item = addNode(doc, channel, "item"); addNode(doc, item, "pubDate", image.getTimestamp().toString()); addNode(doc, item, "atom", "updated", image.getTimestamp().toString()); addNode(doc, item, "title", image.getFileName()); addNode(doc, item, "description", getDescription(api, base, owner, category, image, I18nUtil.getLoacl(request))); addNode(doc, item, "link", ""); addNode(doc, item, "author", owner); if (api) { //api data here } Element media = addNode(doc, item, "media:group"); Element title = addNode(doc, media, "media", "title", image.getFileName()); addAttribute(doc, title, "type", "plain"); Element descript = addNode(doc, media, "media", "descript", ""); addAttribute(doc, descript, "type", "plain"); addNode(doc, media, "media", "keywords", ""); String img1 = base + "/image/" + owner + "/" + lablename + "/" + id + ".jpg"; String thumbnailImg = base + "/image/" + owner + "/" + lablename + "/s" + 288 + "/" + image.getId() + ".jpg"; Element content = addNode(doc, media, "media", "content", ""); addAttribute(doc, content, "url", img1); addAttribute(doc, content, "type", "image/jpeg"); addAttribute(doc, content, "medium", "image"); int[] value = getWidthAndHeight(image.getWidth(), image.getHeight(), 288); Element thum = addNode(doc, media, "media", "thumbnail", ""); addAttribute(doc, thum, "url", thumbnailImg); addAttribute(doc, thum, "height", Integer.toString(value[1])); addAttribute(doc, thum, "width", Integer.toString(value[0])); addNode(doc, media, "media", "credit", owner); } } }
From source file:com.eviware.soapui.impl.wsdl.monitor.jettyproxy.ProxyServlet.java
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { monitor.fireOnRequest(request, response); if (response.isCommitted()) return;//from www . j av a2s . c om ExtendedHttpMethod method; HttpServletRequest httpRequest = (HttpServletRequest) request; if (httpRequest.getMethod().equals("GET")) method = new ExtendedGetMethod(); else method = new ExtendedPostMethod(); method.setDecompress(false); // for this create ui server and port, properties. JProxyServletWsdlMonitorMessageExchange capturedData = new JProxyServletWsdlMonitorMessageExchange(project); capturedData.setRequestHost(httpRequest.getServerName()); capturedData.setRequestMethod(httpRequest.getMethod()); capturedData.setRequestHeader(httpRequest); capturedData.setHttpRequestParameters(httpRequest); capturedData.setTargetURL(httpRequest.getRequestURL().toString()); CaptureInputStream capture = new CaptureInputStream(httpRequest.getInputStream()); // check connection header String connectionHeader = httpRequest.getHeader("Connection"); if (connectionHeader != null) { connectionHeader = connectionHeader.toLowerCase(); if (connectionHeader.indexOf("keep-alive") < 0 && connectionHeader.indexOf("close") < 0) connectionHeader = null; } // copy headers boolean xForwardedFor = false; @SuppressWarnings("unused") long contentLength = -1; Enumeration<?> headerNames = httpRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String hdr = (String) headerNames.nextElement(); String lhdr = hdr.toLowerCase(); if (dontProxyHeaders.contains(lhdr)) continue; if (connectionHeader != null && connectionHeader.indexOf(lhdr) >= 0) continue; if ("content-length".equals(lhdr)) contentLength = request.getContentLength(); Enumeration<?> vals = httpRequest.getHeaders(hdr); while (vals.hasMoreElements()) { String val = (String) vals.nextElement(); if (val != null) { method.setRequestHeader(lhdr, val); xForwardedFor |= "X-Forwarded-For".equalsIgnoreCase(hdr); } } } // Proxy headers method.setRequestHeader("Via", "SoapUI Monitor"); if (!xForwardedFor) method.addRequestHeader("X-Forwarded-For", request.getRemoteAddr()); if (method instanceof ExtendedPostMethod) ((ExtendedPostMethod) method) .setRequestEntity(new InputStreamRequestEntity(capture, request.getContentType())); HostConfiguration hostConfiguration = new HostConfiguration(); StringBuffer url = new StringBuffer("http://"); url.append(httpRequest.getServerName()); if (httpRequest.getServerPort() != 80) url.append(":" + httpRequest.getServerPort()); if (httpRequest.getServletPath() != null) { url.append(httpRequest.getServletPath()); method.setPath(httpRequest.getServletPath()); if (httpRequest.getQueryString() != null) { url.append("?" + httpRequest.getQueryString()); method.setPath(httpRequest.getServletPath() + "?" + httpRequest.getQueryString()); } } hostConfiguration.setHost(new URI(url.toString(), true)); // SoapUI.log("PROXY to:" + url); monitor.fireBeforeProxy(request, response, method, hostConfiguration); if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) { if (httpState == null) httpState = new HttpState(); HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, method, httpState); } else { HttpClientSupport.getHttpClient().executeMethod(hostConfiguration, method); } // wait for transaction to end and store it. capturedData.stopCapture(); capturedData.setRequest(capture.getCapturedData()); capturedData.setRawResponseBody(method.getResponseBody()); capturedData.setResponseHeader(method); capturedData.setRawRequestData(getRequestToBytes(request.toString(), method, capture)); capturedData.setRawResponseData( getResponseToBytes(response.toString(), method, capturedData.getRawResponseBody())); capturedData.setResponseContent(new String(method.getDecompressedResponseBody())); monitor.fireAfterProxy(request, response, method, capturedData); if (!response.isCommitted()) { StringToStringsMap responseHeaders = capturedData.getResponseHeaders(); // capturedData = null; // copy headers to response HttpServletResponse httpResponse = (HttpServletResponse) response; for (String name : responseHeaders.keySet()) { for (String header : responseHeaders.get(name)) httpResponse.addHeader(name, header); } IO.copy(new ByteArrayInputStream(capturedData.getRawResponseBody()), httpResponse.getOutputStream()); } synchronized (this) { if (checkContentType(method)) { monitor.addMessageExchange(capturedData); } } }
From source file:gsn.http.ac.MyDataSourceCandidateWaitingListServlet.java
/********************************************************************************************************************/ private void checkSessionScheme(HttpServletRequest req, HttpServletResponse res) throws IOException { if (req.getScheme().equals("https") == true) { if ((req.getSession().getAttribute("scheme") == null)) { req.getSession().setAttribute("scheme", "https"); }//w ww . j av a 2 s . c om } else if (req.getScheme().equals("http") == true) { if ((req.getSession().getAttribute("scheme") == null)) { req.getSession().setAttribute("scheme", "http"); } res.sendRedirect("https://" + req.getServerName() + ":" + Main.getContainerConfig().getSSLPort() + "/gsn/MyDataSourceCandidateWaitingListServlet"); } }