1818package com .rabbitmq .client ;
1919
2020import java .io .IOException ;
21- import java .io .UnsupportedEncodingException ;
2221
2322/**
2423 * Subclass of RpcServer which accepts UTF-8 string requests.
@@ -30,6 +29,8 @@ public StringRpcServer(Channel channel) throws IOException
3029 public StringRpcServer (Channel channel , String queueName ) throws IOException
3130 { super (channel , queueName ); }
3231
32+ public static String STRING_ENCODING = "UTF-8" ;
33+
3334 /**
3435 * Overridden to do UTF-8 processing, and delegate to
3536 * handleStringCall. If UTF-8 is not understood by this JVM, falls
@@ -39,14 +40,14 @@ public byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyPropertie
3940 {
4041 String request ;
4142 try {
42- request = new String (requestBody , "UTF-8" );
43- } catch (UnsupportedEncodingException uee ) {
43+ request = new String (requestBody , STRING_ENCODING );
44+ } catch (IOException _ ) {
4445 request = new String (requestBody );
4546 }
4647 String reply = handleStringCall (request , replyProperties );
4748 try {
48- return reply .getBytes ("UTF-8" );
49- } catch (UnsupportedEncodingException uee ) {
49+ return reply .getBytes (STRING_ENCODING );
50+ } catch (IOException _ ) {
5051 return reply .getBytes ();
5152 }
5253 }
@@ -69,14 +70,14 @@ public String handleStringCall(String request)
6970
7071 /**
7172 * Overridden to do UTF-8 processing, and delegate to
72- * handleStringCast. If UTF-8 is not understood by this JVM, falls
73- * back to the platform default.
73+ * handleStringCast. If requestBody cannot be interpreted as UTF-8
74+ * tries the platform default.
7475 */
7576 public void handleCast (byte [] requestBody )
7677 {
7778 try {
78- handleStringCast (new String (requestBody , "UTF-8" ));
79- } catch (UnsupportedEncodingException uee ) {
79+ handleStringCast (new String (requestBody , STRING_ENCODING ));
80+ } catch (IOException _ ) {
8081 handleStringCast (new String (requestBody ));
8182 }
8283 }
0 commit comments