Skip to content

Commit e553452

Browse files
author
Emile Joubert
committed
String RPC uses UTF-8 consistently
1 parent 828fac3 commit e553452

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/com/rabbitmq/client/RpcClient.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717

1818
package com.rabbitmq.client;
1919

20-
import java.io.ByteArrayInputStream;
21-
import java.io.ByteArrayOutputStream;
22-
import java.io.DataInputStream;
23-
import java.io.DataOutputStream;
24-
import java.io.EOFException;
25-
import java.io.IOException;
20+
import java.io.*;
2621
import java.util.Date;
2722
import java.util.HashMap;
2823
import java.util.Map;
@@ -229,7 +224,18 @@ public byte[] primitiveCall(byte[] message)
229224
public String stringCall(String message)
230225
throws IOException, ShutdownSignalException, TimeoutException
231226
{
232-
return new String(primitiveCall(message.getBytes()));
227+
byte[] request;
228+
try {
229+
request = message.getBytes(StringRpcServer.STRING_ENCODING);
230+
} catch (UnsupportedEncodingException uee) {
231+
request = message.getBytes();
232+
}
233+
byte[] reply = primitiveCall(request);
234+
try {
235+
return new String(reply, StringRpcServer.STRING_ENCODING);
236+
} catch (UnsupportedEncodingException uee) {
237+
return new String(reply);
238+
}
233239
}
234240

235241
/**

src/com/rabbitmq/client/StringRpcServer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public StringRpcServer(Channel channel) throws IOException
3030
public StringRpcServer(Channel channel, String queueName) throws IOException
3131
{ super(channel, queueName); }
3232

33+
public static String STRING_ENCODING = "UTF-8";
34+
3335
/**
3436
* Overridden to do UTF-8 processing, and delegate to
3537
* handleStringCall. If UTF-8 is not understood by this JVM, falls
@@ -39,13 +41,13 @@ public byte[] handleCall(byte[] requestBody, AMQP.BasicProperties replyPropertie
3941
{
4042
String request;
4143
try {
42-
request = new String(requestBody, "UTF-8");
44+
request = new String(requestBody, STRING_ENCODING);
4345
} catch (UnsupportedEncodingException uee) {
4446
request = new String(requestBody);
4547
}
4648
String reply = handleStringCall(request, replyProperties);
4749
try {
48-
return reply.getBytes("UTF-8");
50+
return reply.getBytes(STRING_ENCODING);
4951
} catch (UnsupportedEncodingException uee) {
5052
return reply.getBytes();
5153
}
@@ -75,7 +77,7 @@ public String handleStringCall(String request)
7577
public void handleCast(byte[] requestBody)
7678
{
7779
try {
78-
handleStringCast(new String(requestBody, "UTF-8"));
80+
handleStringCast(new String(requestBody, STRING_ENCODING));
7981
} catch (UnsupportedEncodingException uee) {
8082
handleStringCast(new String(requestBody));
8183
}

0 commit comments

Comments
 (0)