List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:cn.itganhuo.app.web.controller.UserController.java
/** * ???/* w ww. ja va 2 s.c o m*/ * * @return ??? * @version 0.0.1-SNAPSHOT * @author ?-? */ @RequiresAuthentication @RequestMapping(value = "/upload", method = RequestMethod.GET) public String refurlUpload(Model model, HttpServletRequest request) { model.addAttribute("path", "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()); return "user/upload"; }
From source file:com.hphoto.server.ApiServlet.java
public void addCategory(Document doc, Element channel, HttpServletRequest request) { assert (request.getParameter("user") != null); String requestUrl = request.getRequestURL().toString(); String base = "http://" + request.getServerName() + (request.getLocalPort() == 80 ? "" : ":" + Integer.toString(request.getLocalPort())); Category[] categories = null;//from ww w .ja v a 2 s . c o m UserProfile[] users = null; String owner = request.getParameter("user"); String feed = request.getParameter("feed"); String language = request.getParameter("hl"); String kind = request.getParameter("kind"); String albumid = request.getParameter("albumid"); //Local local = language == null ? request.getLocale() : new Locale(language); boolean all = request.getParameter("acess") != null && request.getParameter("acess").equals("all"); boolean api = feed != null && feed.equals("api"); try { users = server.getUser(owner, 1); categories = server.getCategories(owner); } catch (IOException e) { e.printStackTrace(); return; } if (users == null || users.length == 0) { return; } addNode(doc, channel, "atom", "id", base + "/feed/" + feed + "/user/" + owner); addNode(doc, channel, "lastBuildDate", (new Date()).toString()); addNode(doc, channel, "title", owner + " " + I18nUtil.getText(key, "title", request.getLocale())); addNode(doc, channel, "description", ""); //add base,not complete addNode(doc, channel, "link", base + "/" + owner); addNode(doc, channel, "managingEditor", owner); addNode(doc, channel, "generator", "hphoto.com"); addNode(doc, channel, "opensearch", "totalResults", "" + (categories != null ? categories.length : 0)); //addNode(doc, channel, "opensearch", "startIndex", ""+1); //addNode(doc, channel, "opensearch", "itemsPerPage", ""+1000); Element image = addNode(doc, channel, "image"); addNode(doc, image, "url", base + "/image/" + owner + "/" + "AHHYILU" + "/s48-c/" + owner); addNode(doc, image, "title", owner + " " + I18nUtil.getText(key, "title", request.getLocale())); addNode(doc, image, "link", base + "/" + owner); //channel if (categories != null) { for (Category category : categories) { if (!all) { if (!category.isOpened() || category.getCount() < 1) { continue; } } Element item = addNode(doc, channel, "item"); addNode(doc, item, "pubDate", category.getCreatdate().toString()); addNode(doc, item, "atom", "updated", category.getLastupload().toString()); addNode(doc, item, "title", category.getName()); addNode(doc, item, "description", getDescription(api, base, owner, category, 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", category.getName()); addAttribute(doc, title, "type", "plain"); Element descript = addNode(doc, media, "media", "descript", ""); addAttribute(doc, descript, "type", "plain"); addNode(doc, media, "media", "keywords", ""); String lablename = category.getLablename(); String imgurl = category.getImgurl(); String id = imgurl.substring(imgurl.lastIndexOf('/') + 1, imgurl.lastIndexOf('.')); String img = "/image/" + owner + "/" + lablename + "/" + id + ".jpg"; String thumbnailImg = "/image/" + owner + "/" + lablename + "/s" + 160 + "-c/" + id + ".jpg"; Element content = addNode(doc, media, "media", "content", ""); addAttribute(doc, content, "url", base + img); addAttribute(doc, content, "type", "image/jpeg"); addAttribute(doc, content, "medium", "image"); Element thum = addNode(doc, media, "media", "thumbnail", ""); addAttribute(doc, thum, "url", base + thumbnailImg); addAttribute(doc, thum, "height", "160"); addAttribute(doc, thum, "width", "160"); addNode(doc, media, "media", "credit", owner); } } }
From source file:org.sample.link.TestServlet.java
/** * Processes requests for both HTTP/*w w w . j a v a 2 s . c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @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"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); // client.register(LoggingFilter.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruits"); String result = target.request().get(String.class); Response r = target.path("link").request().get(); out.println("Received response: " + result); out.println("</body>"); out.println("</html>"); }
From source file:org.sample.moxy.TestServlet.java
/** * Processes requests for both HTTP// www . j a va2s . c o m * <code>GET</code> and * <code>POST</code> methods. * * @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"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(MoxyJsonFeature.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/endpoint"); System.out.println("POST request"); MyObject mo = target.request().post(Entity.entity(new MyObject("Duke", 18), MediaType.APPLICATION_JSON), MyObject.class); out.println("Received response: " + mo.getName() + ", " + mo.getAge() + "<br><br>"); out.println("Check server.log for client/server interceptor output."); out.println("</body>"); out.println("</html>"); }
From source file:com.xpn.xwiki.user.impl.xwiki.MyPersistentLoginManager.java
/** * Compute the actual domain the cookie is supposed to be set for. Search through the list of generalized domains * for a partial match. If no match is found, then no specific domain is used, which means that the cookie will be * valid only for the requested domain./*w w w.j a v a 2 s . c om*/ * * @param request The servlet request. * @return The configured domain generalization that matches the request, or null if no match is found. */ private String getCookieDomain(HttpServletRequest request) { String cookieDomain = null; if (this.cookieDomains != null) { String servername = request.getServerName(); for (int i = 0; i < this.cookieDomains.length; i++) { if (servername.indexOf(this.cookieDomains[i]) != -1) { cookieDomain = this.cookieDomains[i]; break; } } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Cookie domain is:" + cookieDomain); } return cookieDomain; }
From source file:org.sample.filter.TestServlet.java
/** * Processes requests for both HTTP// ww w . j a va 2 s .c o m * <code>GET</code> and * <code>POST</code> methods. * * @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"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(ClientLoggingFilter.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruits"); out.println(target.getUri() + "<br><br>"); out.println("GET request" + "<br><br>"); String result = target.request().get(String.class); out.println("Received response (GET): " + result + "<br><br>"); System.out.println("**** POST request"); result = target.request().post(Entity.text("1"), String.class); out.println("Received response (POST): " + result + "<br><br>"); out.println("Received response: " + result + "<br><br>"); out.println("Check server.log for client/server filter output."); out.println("</body>"); out.println("</html>"); }
From source file:com.sun.socialsite.web.filters.CustomizedPageCachingFilter.java
@Override protected String calculateKey(final HttpServletRequest req) { StringBuffer sb;/*w ww . j av a2 s.c o m*/ String queryString = null; /* * We want our keys to be absolute URLs (with scheme, hostname, etc) so that * they'll line-up with what our URLStrategy uses (which makes it easier for * other code to invalidate cache entries when an entity is updated). */ if (req.getAttribute("javax.servlet.include.request_uri") != null) { sb = new StringBuffer(); sb.append(req.getMethod()); sb.append("|"); sb.append(req.getScheme()).append("://").append(req.getServerName()); switch (req.getServerPort()) { case 80: if (req.getScheme().equalsIgnoreCase("http")) { break; } case 443: if (req.getScheme().equalsIgnoreCase("https")) { break; } default: sb.append(":").append(req.getServerPort()); } sb.append((String) (req.getAttribute("javax.servlet.include.request_uri"))); queryString = (String) (req.getAttribute("javax.servlet.include.query_string")); } else { sb = req.getRequestURL(); queryString = req.getQueryString(); } if (queryString != null) { sb.append("?").append(queryString); } String key = sb.toString(); log.trace("key=" + key); return key; }
From source file:fr.xebia.cocktail.CocktailRssView.java
@Override protected List<Item> buildFeedItems(Map<String, Object> model, final HttpServletRequest request, HttpServletResponse response) throws Exception { Function<Cocktail, Item> cocktailToRssItem = new Function<Cocktail, Item>() { @Override//w w w .j a va 2s . co m public Item apply(@Nullable Cocktail cocktail) { if (cocktail == null) { return null; } Item item = new Item(); item.setTitle(cocktail.getName()); Content content = new Content(); content.setValue(cocktail.getInstructionsAsHtml()); content.setType(Content.HTML); item.setContent(content); item.setLink(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/cocktail/" + cocktail.getId()); return item; } }; return Lists.newArrayList(Iterables.transform(cocktails, cocktailToRssItem)); }
From source file:org.sample.readerwriter.TestServlet.java
/** * Processes requests for both HTTP//from ww w.j a va 2 s .co m * <code>GET</code> and * <code>POST</code> methods. * * @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"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(MyReader.class).register(MyWriter.class); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruits"); System.out.println("POST request"); String fruit = target.request().post(Entity.entity(new MyObject(1), MyObject.MIME_TYPE), String.class); out.println("Received response: " + fruit + "<br><br>"); fruit = target.path("fruitInt").request().post(Entity.text("1"), String.class); out.println("Received response: " + fruit + "<br><br>"); out.println("Check server.log for client/server interceptor output."); out.println("</body>"); out.println("</html>"); }
From source file:com.viewer.controller.ViewerController.java
@RequestMapping(value = "/GetApplicationHost", method = RequestMethod.GET, headers = { "Content-type=application/json" }) @ResponseBody/*from ww w.j a v a 2 s. c om*/ private String GetApplicationHost(@RequestBody HttpServletRequest request) { return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); }