List of usage examples for javax.servlet.http HttpServletResponse getCharacterEncoding
public String getCharacterEncoding();
From source file:org.exist.http.urlrewrite.XQueryURLRewrite.java
private void applyViews(ModelAndView modelView, List<URLRewrite> views, HttpServletResponse response, RequestWrapper modifiedRequest, HttpServletResponse currentResponse) throws IOException, ServletException { int status;//from w ww. j a v a 2s . c om HttpServletResponse wrappedResponse = currentResponse; for (int i = 0; i < views.size(); i++) { final URLRewrite view = (URLRewrite) views.get(i); // get data returned from last action byte[] data = ((CachingResponseWrapper) wrappedResponse).getData(); // determine request method to use for calling view String method = view.getMethod(); if (method == null) { method = "POST"; // default is POST } final RequestWrapper wrappedReq = new RequestWrapper(modifiedRequest); wrappedReq.allowCaching(false); wrappedReq.setMethod(method); wrappedReq.setBasePath(modifiedRequest.getBasePath()); wrappedReq.setCharacterEncoding(wrappedResponse.getCharacterEncoding()); wrappedReq.setContentType(wrappedResponse.getContentType()); if (data != null) { wrappedReq.setData(data); } wrappedResponse = new CachingResponseWrapper(response, true); doRewrite(view, wrappedReq, wrappedResponse); // catch errors in the view status = ((CachingResponseWrapper) wrappedResponse).getStatus(); if (status >= 400) { if (modelView != null && modelView.hasErrorHandlers()) { data = ((CachingResponseWrapper) wrappedResponse).getData(); final String msg = data == null ? "" : new String(data, UTF_8); modifiedRequest.setAttribute(RQ_ATTR_ERROR, msg); applyViews(null, modelView.errorHandlers, response, modifiedRequest, wrappedResponse); break; } else { flushError(response, wrappedResponse); } break; } else if (i == views.size() - 1) { ((CachingResponseWrapper) wrappedResponse).flush(); } } }
From source file:org.codelabor.system.file.web.struts.action.FileDownloadAction.java
@Override protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug(paramMap.toString());//from w w w . j a v a2s . c o m String fileId = (String) paramMap.get("fileId"); StreamInfo streamInfo = null; WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(servlet.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); FileDTO fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); StringBuilder sb = new StringBuilder(); // FILE_SYSTEM if (StringUtils.isNotEmpty(repositoryPath)) { sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); streamInfo = new FileStreamInfo(org.codelabor.system.file.FileConstants.CONTENT_TYPE, file); // DATABASE } else { byte[] bytes = fileDTO.getBytes(); streamInfo = new ByteArrayStreamInfo(org.codelabor.system.file.FileConstants.CONTENT_TYPE, bytes); } // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); response.setContentType(org.codelabor.system.file.FileConstants.CONTENT_TYPE); sb.setLength(0); if (request.getHeader(HttpRequestHeaderConstants.USER_AGENT).indexOf("MSIE5.5") > -1) { sb.append("filename="); } else { sb.append("attachment; filename="); } // stringBuilder.append("\""); sb.append(encodedRealFilename); // stringBuilder.append("\""); response.setHeader(HttpResponseHeaderConstants.CONTENT_DISPOSITION, sb.toString()); logger.debug("header: {}", sb.toString()); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); return streamInfo; }
From source file:org.codelabor.system.file.web.controller.xplatform.FileController.java
@RequestMapping("/view") public String view(Model model, @RequestParam("fileId") String fileId, HttpServletResponse response) throws Exception { StringBuilder stringBuilder = null; FileDTO fileDTO;//from w w w. j ava2 s . c o m fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; BufferedInputStream bufferdInputStream = null; ServletOutputStream servletOutputStream = null; BufferedOutputStream bufferedOutputStream = null; DataSetList outputDataSetList = new DataSetList(); VariableList outputVariableList = new VariableList(); try { if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM stringBuilder = new StringBuilder(); stringBuilder.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { stringBuilder.append(File.separator); } stringBuilder.append(uniqueFilename); File file = new File(stringBuilder.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); bufferdInputStream = new BufferedInputStream(inputStream); servletOutputStream = response.getOutputStream(); bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); XplatformUtils.setSuccessMessage( messageSource.getMessage("info.success", new Object[] {}, forcedLocale), outputVariableList); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); throw new XplatformException(messageSource.getMessage("error.failure", new Object[] {}, forcedLocale), e); } finally { // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); } model.addAttribute(OUTPUT_DATA_SET_LIST, outputDataSetList); model.addAttribute(OUTPUT_VARIABLE_LIST, outputVariableList); return VIEW_NAME; }
From source file:org.apache.click.ClickServlet.java
/** * Retrieve a writer instance for the given context. * * @param response the servlet response//from w ww . ja v a 2s .c o m * @return a writer instance * @throws IOException if an input or output exception occurred */ Writer getWriter(HttpServletResponse response) throws IOException { try { return response.getWriter(); } catch (IllegalStateException ignore) { // If writer cannot be retrieved fallback to OutputStream. CLK-644 return new OutputStreamWriter(response.getOutputStream(), response.getCharacterEncoding()); } }
From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java
/** * ?? ??.//from ww w. j av a2 s .c o m * * @param request * * @param response * ? * @throws Exception * */ protected void view(HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO; fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); }
From source file:com.wordpress.metaphorm.authProxy.hook.AuthProxyServletFilter.java
private boolean processLocalLiferayResourceRequest(HttpServletRequest servletReq, HttpServletResponse servletResp) throws OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, MalformedURLException, UnsupportedEncodingException { OAuthState oAuthState = OAuthStateManager.getOAuthState(servletReq.getSession().getId()); String url = servletReq.getRequestURL().toString(); String queryString = servletReq.getQueryString(); if (oAuthState != null) { _log.debug("Requesting local Liferay resource using p_auth from OAuthState object!"); try {//from ww w. j av a2s . c o m if (queryString != null) queryString += "&p_auth=" + oAuthState.getPAuth(); else queryString = "p_auth=" + oAuthState.getPAuth(); } catch (ExpiredStateException e) { _log.debug("Could not provide p_auth parameter enrichment"); } } _log.debug("Requesting " + url + (queryString != null ? "?" + queryString : "")); HttpURLConnection uRLConn = (HttpURLConnection) new URL( url + (queryString != null ? "?" + queryString : "")).openConnection(); uRLConn.addRequestProperty("User-Agent", PROXY_USER_AGENT); uRLConn.addRequestProperty("Cookie", "JSESSIONID=" + servletReq.getSession().getId()); String transformHeader = servletReq.getHeader("transform-response-to"); if (transformHeader == null) transformHeader = servletReq.getParameter("transform-response-to"); uRLConn.connect(); int httpStatusCode = uRLConn.getResponseCode(); servletResp.setStatus(httpStatusCode); if (httpStatusCode < 200 || httpStatusCode >= 300) { // Return immediately for error codes return true; } InputStream in = uRLConn.getInputStream(); if (transformHeader != null) { _log.debug("Transforming JSON to XML"); servletResp.setContentType("application/xml"); String json = sinkInputStream(in, servletResp.getCharacterEncoding()); Utils.writeJSONAsXML(json, servletResp.getWriter()); } else { // Proxy content type hearder servletResp.setContentType(uRLConn.getContentType()); OutputStream out = servletResp.getOutputStream(); int i; while ((i = in.read()) != -1) { out.write((byte) i); } } return true; }
From source file:org.codelabor.system.file.web.controller.xplatform.FileController.java
@RequestMapping("/download") public String download(Model model, @RequestHeader("User-Agent") String userAgent, @RequestParam("fileId") String fileId, HttpServletResponse response) throws Exception { FileDTO fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; BufferedInputStream bufferdInputStream = null; ServletOutputStream servletOutputStream = null; BufferedOutputStream bufferedOutputStream = null; StringBuilder sb = new StringBuilder(); DataSetList outputDataSetList = new DataSetList(); VariableList outputVariableList = new VariableList(); try {// w w w .ja v a2 s. c o m if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); response.setContentType(org.codelabor.system.file.FileConstants.CONTENT_TYPE); sb.setLength(0); if (userAgent.indexOf("MSIE5.5") > -1) { sb.append("filename="); } else { sb.append("attachment; filename="); } sb.append(encodedRealFilename); response.setHeader(HttpResponseHeaderConstants.CONTENT_DISPOSITION, sb.toString()); logger.debug("header: {}", sb.toString()); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); bufferdInputStream = new BufferedInputStream(inputStream); servletOutputStream = response.getOutputStream(); bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); XplatformUtils.setSuccessMessage( messageSource.getMessage("info.success", new Object[] {}, forcedLocale), outputVariableList); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); throw new XplatformException(messageSource.getMessage("error.failure", new Object[] {}, forcedLocale), e); } finally { // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); } model.addAttribute(OUTPUT_DATA_SET_LIST, outputDataSetList); model.addAttribute(OUTPUT_VARIABLE_LIST, outputVariableList); return VIEW_NAME; }
From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java
/** * ?? ./*from w w w .j a v a2s. co m*/ * * @param request * * @param response * ? * @throws Exception * */ protected void download(HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO; fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); response.setContentType(org.codelabor.system.file.FileConstants.CONTENT_TYPE); sb.setLength(0); if (request.getHeader(HttpRequestHeaderConstants.USER_AGENT).indexOf("MSIE5.5") > -1) { sb.append("filename="); } else { sb.append("attachment; filename="); } sb.append(encodedRealFilename); response.setHeader(HttpResponseHeaderConstants.CONTENT_DISPOSITION, sb.toString()); logger.debug("header: {}", sb.toString()); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); }
From source file:de.innovationgate.wgpublisher.WGPDispatcher.java
private void writeWholeData(DataSource data, HttpServletRequest request, HttpServletResponse response, String characterEncoding, String dbHint) throws IOException, HttpErrorException, UnsupportedEncodingException { Reader reader = null;/* w ww. j a v a 2 s.com*/ InputStream in = data.getInputStream(); if (in == null) { throw new HttpErrorException(404, "File not found: " + data.getName(), dbHint); } try { if (!isBinary(request, response)) { // this is a textual reponse if (characterEncoding != null && !characterEncoding.equals(response.getCharacterEncoding())) { reader = new InputStreamReader(in, characterEncoding); WGUtils.inToOut(reader, response.getWriter(), 2048); } else { WGUtils.inToOut(in, response.getOutputStream(), 2048); } } else { WGUtils.inToOut(in, response.getOutputStream(), 2048); } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:com.wordpress.metaphorm.authProxy.hook.AuthProxyServletFilter.java
private boolean serveRequest(HttpServletRequest servletReq, HttpServletResponse servletResp) throws OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, MalformedURLException, UnsupportedEncodingException, ExpiredStateException, OAuthProviderConfigurationException, ProtocolNotSupportedException { _log.debug("Acting as forwarding proxy to " + servletReq.getServerName() + " !"); // Get the oAuthState linked to the userToken (by header) or HTTP session ID OAuthState oAuthState = getOAuthState(servletReq, servletResp); AuthProxyConnection uRLConn = new OAuthProxyConnectionImpl(servletReq, AuthProxyConnectionFactory.getFactory(servletReq, oAuthState)); //AuthProxyConnectionFactory.getFactory(servletReq, oAuthState).getAuthProxyConnection(); try {//from w w w. j a v a 2 s . c om String transformHeader = servletReq.getHeader("transform-response-to"); if (transformHeader == null) transformHeader = servletReq.getParameter("transform-response-to"); uRLConn.connect(); servletResp.setStatus(uRLConn.getResponseCode()); Map<String, List<String>> headerMap = uRLConn.getResponseHeaders(); String acceptEncodingHeaderValue = servletReq .getHeader(HttpConstants.STRING_ACCEPT_ENCODING_HEADER_NAME); boolean supportGzip = acceptEncodingHeaderValue != null && acceptEncodingHeaderValue.contains("gzip"); boolean gzipped = false; { List<String> contentEncoding = headerMap.get(HttpConstants.STRING_CONTENT_ENCODING_HEADER_NAME); if (contentEncoding != null && contentEncoding.size() == 1 && contentEncoding.get(0).contains("gzip")) gzipped = true; } boolean proxyContentUntouched = (transformHeader == null && (!gzipped || (gzipped && supportGzip))); _log.debug("Preserve content length & encoding headers? " + proxyContentUntouched); for (String headerName : headerMap.keySet()) { // Discard content compression / encoding headers if the proxied response will be manipulated later // If so, let the Servlet container add appropriate replacement headers if (!proxyContentUntouched) { if (headerName.equalsIgnoreCase(HttpConstants.STRING_CONTENT_LENGTH_HEADER_NAME)) continue; if (headerName.equalsIgnoreCase(HttpConstants.STRING_CONTENT_TYPE_HEADER_NAME)) continue; if (headerName.equalsIgnoreCase(HttpConstants.STRING_CONTENT_ENCODING_HEADER_NAME)) continue; } for (String headerValue : headerMap.get(headerName)) { servletResp.setHeader(headerName, headerValue); _log.debug(" Set header \"" + headerName + "\" = \"" + headerValue + "\""); } } InputStream in = uRLConn.getInputStream(); if (in != null) { if (transformHeader != null) { _log.debug("Transforming JSON to XML"); String jsonContentType = uRLConn.getContentType(); String jsonCharSet = (jsonContentType.indexOf("charset=") > -1 ? jsonContentType.substring(jsonContentType.indexOf("charset=") + "charset=".length()) : ""); _log.debug("JSON response character set was " + jsonCharSet); servletResp.setContentType( "application/xml" + (jsonCharSet.length() > 0 ? "; charset=" + jsonCharSet : "")); String json = sinkInputStream(in, servletResp.getCharacterEncoding()); Utils.writeJSONAsXML(json, servletResp.getWriter()); } else { _log.debug("Serving response.."); // Proxy content type hearder servletResp.setContentType(uRLConn.getContentType()); OutputStream out; // No transformation necessary, attempt to proxy on Content-Length header int byteCount = 0; int i; if (!proxyContentUntouched) { if (gzipped) { _log.debug("Proxy endpoint content is GZipped"); in = new GZIPInputStream(in); } if (supportGzip) { _log.debug("GZipping response..."); servletResp.setHeader(HttpConstants.STRING_CONTENT_ENCODING_HEADER_NAME, "gzip"); out = servletResp.getOutputStream(); GZIPOutputStream gzipOut = new GZIPOutputStream(out); streamBytes(in, gzipOut, byteCount); } else { _log.debug("Writing an uncompressed response..."); out = servletResp.getOutputStream(); streamBytes(in, out, byteCount); } } else { _log.debug("Tunnelling proxy endpoint content untouched..."); out = servletResp.getOutputStream(); streamBytes(in, out, byteCount); } out.flush(); } } return true; } catch (RedirectRequiredException e) { if (oAuthState instanceof HttpSessionOAuthStateImpl || (oAuthState instanceof OAuthStateManager.ManagedOAuthState && ((OAuthStateManager.ManagedOAuthState) oAuthState).getManagedOAuthState() .equals(HttpSessionOAuthStateImpl.class))) { _log.debug("About to issue HTTP redirect to: " + e.getURL().toString()); servletResp.sendRedirect(e.getURL().toString()); return true; } else { String xmlResp = "<?xml version=\"1.0\"?>" + "<oauth><authorisation_needed><url>" + e.getURL().toString().replaceAll("&", "&") .replaceAll("<", "<").replaceAll(">", ">") + "</url></authorisation_needed></oauth>"; _log.debug("About to write XML: " + xmlResp); servletResp.setStatus(200); servletResp.setContentType("application/xml"); servletResp.getWriter().write(xmlResp); return true; } } }