List of usage examples for javax.servlet.http HttpServletResponse toString
public String toString()
From source file:com.baifendian.swordfish.webserver.interceptor.LoginInterceptor.java
@Override public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception { logger.info(httpServletResponse.toString()); }
From source file:com.thinkberg.webdav.servlet.MoxoWebDAVServlet.java
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // String auth = request.getHeader("Authorization"); // String login = "", password = ""; ////from w ww . ja v a 2 s. c om // if (auth != null) { // auth = new String(Base64.decodeBase64(auth.substring(auth.indexOf(' ') + 1).getBytes())); // login = auth.substring(0, auth.indexOf(':')); // password = auth.substring(auth.indexOf(':') + 1); // } // // AWSCredentials credentials = AWSCredentials.load(password, )) // if (user == null) { // response.setHeader("WWW-Authenticate", "Basic realm=\"Moxo\""); // response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // return; // } // show we are doing the litmus test String litmusTest = request.getHeader("X-Litmus"); if (null == litmusTest) { litmusTest = request.getHeader("X-Litmus-Second"); } if (litmusTest != null) { LOG.info(String.format("WebDAV Litmus Test: %s", litmusTest)); } String method = request.getMethod(); LOG.debug(String.format(">> %s %s", request.getMethod(), request.getPathInfo())); if (handlers.containsKey(method)) { handlers.get(method).service(request, response); } else { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); } LOG.debug( String.format("<< %s (%s)", request.getMethod(), response.toString().replaceAll("[\\r\\n]+", ""))); }
From source file:org.apache.wiki.ui.WikiJSPFilter.java
/** * Goes through all types and writes the appropriate response. * //from w w w .j a va 2 s .c om * @param wikiContext The usual processing context * @param response The source string * @return The modified string with all the insertions in place. */ private String filter(WikiContext wikiContext, HttpServletResponse response) { String string = response.toString(); if (wikiContext != null) { String[] resourceTypes = TemplateManager.getResourceTypes(wikiContext); for (int i = 0; i < resourceTypes.length; i++) { string = insertResources(wikiContext, string, resourceTypes[i]); } // // Add HTTP header Resource Requests // String[] headers = TemplateManager.getResourceRequests(wikiContext, TemplateManager.RESOURCE_HTTPHEADER); for (int i = 0; i < headers.length; i++) { String key = headers[i]; String value = ""; int split = headers[i].indexOf(':'); if (split > 0 && split < headers[i].length() - 1) { key = headers[i].substring(0, split); value = headers[i].substring(split + 1); } response.addHeader(key.trim(), value.trim()); } } return string; }
From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java
protected void buildResponseInfo(StringBuilder sb, HttpServletRequest request, HttpServletResponse response) { sb.append("Response class=" + response.getClass().getName()); sb.append(", ContentType=").append(response.getContentType()); sb.append(", Committed=").append(response.isCommitted()); String exp = response.toString().trim(); if (exp != null) { exp = replaceString(exp, "\r\n", "\n"); exp = replaceString(exp, "\n", " "); final int limitLength = 120; if (exp.length() >= limitLength) { // it is possible that Response toString() show all HTML strings // so cut it to suppress too big logging here exp = exp.substring(0, limitLength) + "..."; }/* w w w .j ava 2s .co m*/ sb.append(LF).append(IND); sb.append(", toString()=").append(exp); // e.g. Jetty // HTTP/1.1 200 Expires: Thu, 01-Jan-1970 00:00:00 GMT Set-Cookie: ... } }
From source file:org.dd4t.mvc.utils.RenderUtils.java
/** * Dispatch a url to a request dispatcher while buffering the output in a string * (and not directly to the response's writer). *//*w w w . j av a 2 s. c om*/ public static String dispatchBufferedRequest(final HttpServletRequest request, final HttpServletResponse response, final String url) throws ServletException, IOException { long time = System.currentTimeMillis(); final RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(url); final HttpServletResponse responseWrapper = new HttpServletResponseWrapper(response) { private CharArrayWriter output = new CharArrayWriter(); @Override public String toString() { return output.toString(); } @Override public PrintWriter getWriter() { return new PrintWriter(output); } }; dispatcher.include(request, responseWrapper); time = System.currentTimeMillis() - time; LOG.debug("dispatchBufferedRequest {}, takes: {} ms.", url, time); return responseWrapper.toString(); }
From source file:org.efaps.webdav4vfs.WebDAVServlet.java
@Override() public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // String auth = request.getHeader("Authorization"); // String login = "", password = ""; ////from w ww . j a va 2s .c o m // if (auth != null) { // auth = new String(Base64.decodeBase64(auth.substring(auth.indexOf(' ') + 1).getBytes())); // login = auth.substring(0, auth.indexOf(':')); // password = auth.substring(auth.indexOf(':') + 1); // } // // AWSCredentials credentials = AWSCredentials.load(password, )) // if (user == null) { // response.setHeader("WWW-Authenticate", "Basic realm=\"Moxo\""); // response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // return; // } // show we are doing the litmus test String litmusTest = request.getHeader("X-Litmus"); if (null == litmusTest) { litmusTest = request.getHeader("X-Litmus-Second"); } if (litmusTest != null) { LOG.info(String.format("WebDAV Litmus Test: %s", litmusTest)); } String method = request.getMethod(); LOG.debug(String.format(">> %s %s", request.getMethod(), request.getPathInfo())); if (handlers.containsKey(method)) { handlers.get(method).service(request, response); } else { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); } LOG.debug( String.format("<< %s (%s)", request.getMethod(), response.toString().replaceAll("[\\r\\n]+", ""))); }
From source file:org.encuestame.core.security.CustomAuthenticationEntryPoint.java
/** * *///from w ww . j av a2 s . c om @Override public void commence(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException, ServletException { if (authException != null) { // you can check for the spefic exception here and redirect like // this logger.debug("respnse" + response.toString()); logger.debug("respnse" + response.getContentType()); logger.debug("request" + request.toString()); logger.debug("request" + request.getContentType()); //response.sendRedirect("403.html"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String redirectUrl = null; if (useForward) { if (forceHttps && "http".equals(request.getScheme())) { // First redirect the current request to HTTPS. // When that request is received, the forward to the login page // will be used. redirectUrl = buildHttpsRedirectUrlForRequest(httpRequest); } if (redirectUrl == null) { String loginForm = determineUrlToUseForThisRequest(httpRequest, httpResponse, authException); if (logger.isDebugEnabled()) { logger.debug("Server side forward to: " + loginForm); } RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(loginForm); dispatcher.forward(request, response); return; } } else { // redirect to login page. Use https if forceHttps true redirectUrl = buildRedirectUrlToLoginPage(httpRequest, httpResponse, authException); } redirectStrategy.sendRedirect(httpRequest, httpResponse, redirectUrl); }
From source file:org.sakaiproject.nakamura.http.i18n.I18nFilter.java
/** * {@inheritDoc}/*from w ww . ja v a2s . co m*/ * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if ("true".equals(request.getParameter("raw"))) { chain.doFilter(request, response); return; } // get path info SlingHttpServletRequest srequest = (SlingHttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String path = srequest.getPathInfo(); // check that the path is something we should filter. boolean filter = false; if ((path.startsWith("/dev/") || path.startsWith("/devwidgets/")) && path.endsWith(".html")) { httpResponse = new CapturingHttpServletResponse(httpResponse); filter = true; } // allow the chain to process so we can capture the response chain.doFilter(request, httpResponse); // if the path was set to be filtered, get the output and filter it // otherwise the response isn't wrapped and doesn't require us to intervene if (filter) { String output = httpResponse.toString(); if (!StringUtils.isBlank(output)) { long start = System.currentTimeMillis(); writeFilteredResponse(srequest, response, output); long end = System.currentTimeMillis(); logger.debug("Filtered {} in {}ms", path, (end - start)); } } }
From source file:pa_SymposiumPlanner.BRF2011GeneralChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); //PrintWriter out = response.getWriter(); try {/* w w w .j a va 2 s .com*/ address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("General Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); //BackwardReasoner br = new BackwardReasoner(); //Iterator solit =null; //DefiniteClause dc = null; //SymbolTable.reset(); POSLParser pp = new POSLParser(); Date t1 = new GregorianCalendar().getTime(); //System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents //System.out.println("day: " + t1.getDay()); //System.out.println("day: " + t1.getYear()); //System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; //System.out.println(time); //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; //System.out.println(date); String url = poslAddress; String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); DefiniteClause dc = null; try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } int varSize = 0; Iterator solit = br.iterativeDepthFirstSolutionIterator(dc); while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); //messages = g.Messages2(); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } //out.close(); }
From source file:pa_SymposiumPlanner.BRF2011LiaisonChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from w w w . j av a2 s . c o m address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("Liaison Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }