Changeset 402 for tapas/web/src/com/ether/WebHelper.java
- Timestamp:
- 03/08/12 17:20:11 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
tapas/web/src/com/ether/WebHelper.java
r389 r402 1 1 package com.ether; 2 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.security.InvalidParameterException; 6 7 import javax.servlet.ServletOutputStream; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse; 10 3 import com.ether.WebException.WebCode; 11 4 import org.apache.commons.logging.Log; 12 5 import org.apache.commons.logging.LogFactory; … … 14 7 import org.jetbrains.annotations.Nullable; 15 8 16 import com.ether.WebException.WebCode; 9 import javax.servlet.ServletOutputStream; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 import java.io.IOException; 13 import java.io.PrintWriter; 14 import java.security.InvalidParameterException; 17 15 18 16 public final class WebHelper … … 23 21 24 22 @NotNull 25 public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull )26 23 public static String getRequestParameter( @NotNull final HttpServletRequest httpServletRequest, @Nullable final String parameterName, @Nullable final String defaultParameterValue, final boolean canBeNull ) 24 throws InvalidParameterException 27 25 { 28 29 if(null == parameterName)30 31 26 String parameterValue; 27 if( null == parameterName ) 28 parameterValue = defaultParameterValue; 29 32 30 parameterValue = httpServletRequest.getParameter( parameterName ); 33 31 … … 48 46 49 47 final PrintWriter writer = httpServletResponse.getWriter(); 50 51 writer.write( JSON_TAG_BEGIN );52 48 writer.write( data ); 53 writer.write( JSON_TAG_END );54 49 } 55 50 56 public static void displayAjaxError(@NotNull final HttpServletResponse response, @Nullable final String methodName) 57 throws WebException 58 { 59 try { 60 response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); 61 response.setCharacterEncoding(UTF8Charset.getEncoding()); 62 response.setContentType("text/plain;charset="+ UTF8Charset.getEncoding()); 63 final ServletOutputStream outputStream = response.getOutputStream(); 64 outputStream.print("error.method_not_implemented : " + methodName+ " is not implemented."); 65 outputStream.flush(); 66 outputStream.close(); 67 } catch (IOException e) { 68 throw new WebException(WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e); 69 } 51 public static void displayAjaxError( @NotNull final HttpServletResponse response, @Nullable final String methodName ) 52 throws WebException 53 { 54 try 55 { 56 response.setStatus( HttpServletResponse.SC_NOT_IMPLEMENTED ); 57 response.setCharacterEncoding( UTF8Charset.getEncoding() ); 58 response.setContentType( "text/plain;charset=" + UTF8Charset.getEncoding() ); 59 final ServletOutputStream outputStream = response.getOutputStream(); 60 outputStream.print( "error.method_not_implemented : " + methodName + " is not implemented." ); 61 outputStream.flush(); 62 outputStream.close(); 63 } 64 catch( IOException e ) 65 { 66 throw new WebException( WebCode.IO_EXCEPTION_ERROR_TO_GET_OUTPUTSTREAM, e ); 67 } 70 68 } 71 69 72 70 private static final Log LOGGER = LogFactory.getLog( WebHelper.class ); 73 71 72 public static final int STATUS_CODE_SERVICE_EXCEPTION = 500; 74 73 private static final String CONTENT_TYPE_TEXT_JSON = "text/javascript;charset=" + UTF8Charset.getEncoding(); 75 private static final char JSON_TAG_BEGIN = ' ' ; // '(';76 private static final char JSON_TAG_END = ' '; // ')';77 74 }
Note: See TracChangeset
for help on using the changeset viewer.