5353import javax .servlet .http .HttpServletResponse ;
5454import javax .servlet .http .HttpSession ;
5555
56+ import com .cloud .utils .HttpUtils ;
5657import org .apache .commons .codec .binary .Base64 ;
5758import org .apache .http .ConnectionClosedException ;
5859import org .apache .http .HttpException ;
174175
175176@ Component
176177public class ApiServer extends ManagerBase implements HttpRequestHandler , ApiServerService {
177- private static final String UTF_8 = "UTF-8" ;
178178 private static final Logger s_logger = Logger .getLogger (ApiServer .class .getName ());
179179 private static final Logger s_accessLogger = Logger .getLogger ("apiserver." + ApiServer .class .getName ());
180180
@@ -392,7 +392,7 @@ public void handle(final HttpRequest request, final HttpResponse response, final
392392 try {
393393 List <NameValuePair > paramList = null ;
394394 try {
395- paramList = URLEncodedUtils .parse (new URI (request .getRequestLine ().getUri ()), UTF_8 );
395+ paramList = URLEncodedUtils .parse (new URI (request .getRequestLine ().getUri ()), HttpUtils . UTF_8 );
396396 } catch (final URISyntaxException e ) {
397397 s_logger .error ("Error parsing url request" , e );
398398 }
@@ -403,7 +403,7 @@ public void handle(final HttpRequest request, final HttpResponse response, final
403403 // (Immutable)Multimap<String, String> paramMultiMap = HashMultimap.create();
404404 // Map<String, Collection<String>> parameterMap = paramMultiMap.asMap();
405405 final Map parameterMap = new HashMap <String , String []>();
406- String responseType = BaseCmd .RESPONSE_TYPE_XML ;
406+ String responseType = HttpUtils .RESPONSE_TYPE_XML ;
407407 for (final NameValuePair param : paramList ) {
408408 if (param .getName ().equalsIgnoreCase ("response" )) {
409409 responseType = param .getValue ();
@@ -416,8 +416,8 @@ public void handle(final HttpRequest request, final HttpResponse response, final
416416 parameterMap .put ("httpmethod" , new String [] {request .getRequestLine ().getMethod ()});
417417
418418 // Check responseType, if not among valid types, fallback to JSON
419- if (!(responseType .equals (BaseCmd .RESPONSE_TYPE_JSON ) || responseType .equals (BaseCmd .RESPONSE_TYPE_XML ))) {
420- responseType = BaseCmd .RESPONSE_TYPE_XML ;
419+ if (!(responseType .equals (HttpUtils .RESPONSE_TYPE_JSON ) || responseType .equals (HttpUtils .RESPONSE_TYPE_XML ))) {
420+ responseType = HttpUtils .RESPONSE_TYPE_XML ;
421421 }
422422
423423 try {
@@ -827,9 +827,9 @@ public boolean verifyRequest(final Map<String, Object[]> requestParameters, fina
827827 }
828828
829829 if (unsignedRequest == null ) {
830- unsignedRequest = paramName + "=" + URLEncoder .encode (paramValue , UTF_8 ).replaceAll ("\\ +" , "%20" );
830+ unsignedRequest = paramName + "=" + URLEncoder .encode (paramValue , HttpUtils . UTF_8 ).replaceAll ("\\ +" , "%20" );
831831 } else {
832- unsignedRequest = unsignedRequest + "&" + paramName + "=" + URLEncoder .encode (paramValue , UTF_8 ).replaceAll ("\\ +" , "%20" );
832+ unsignedRequest = unsignedRequest + "&" + paramName + "=" + URLEncoder .encode (paramValue , HttpUtils . UTF_8 ).replaceAll ("\\ +" , "%20" );
833833 }
834834 }
835835 }
@@ -1077,21 +1077,21 @@ private void writeResponse(final HttpResponse resp, final String responseText, f
10771077 resp .setReasonPhrase (reasonPhrase );
10781078
10791079 final BasicHttpEntity body = new BasicHttpEntity ();
1080- if (BaseCmd .RESPONSE_TYPE_JSON .equalsIgnoreCase (responseType )) {
1080+ if (HttpUtils .RESPONSE_TYPE_JSON .equalsIgnoreCase (responseType )) {
10811081 // JSON response
10821082 body .setContentType (jsonContentType );
10831083 if (responseText == null ) {
1084- body .setContent (new ByteArrayInputStream ("{ \" error\" : { \" description\" : \" Internal Server Error\" } }" .getBytes (UTF_8 )));
1084+ body .setContent (new ByteArrayInputStream ("{ \" error\" : { \" description\" : \" Internal Server Error\" } }" .getBytes (HttpUtils . UTF_8 )));
10851085 }
10861086 } else {
10871087 body .setContentType ("text/xml" );
10881088 if (responseText == null ) {
1089- body .setContent (new ByteArrayInputStream ("<error>Internal Server Error</error>" .getBytes (UTF_8 )));
1089+ body .setContent (new ByteArrayInputStream ("<error>Internal Server Error</error>" .getBytes (HttpUtils . UTF_8 )));
10901090 }
10911091 }
10921092
10931093 if (responseText != null ) {
1094- body .setContent (new ByteArrayInputStream (responseText .getBytes (UTF_8 )));
1094+ body .setContent (new ByteArrayInputStream (responseText .getBytes (HttpUtils . UTF_8 )));
10951095 }
10961096 resp .setEntity (body );
10971097 } catch (final Exception ex ) {
0 commit comments