Skip to content

Commit

Permalink
Refactored boundary variables to be static attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Apr 15, 2016
1 parent 3eebaa8 commit 0b168fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public class LocalDnsHelper {
private static final ScheduledExecutorService EXECUTORS =
Executors.newScheduledThreadPool(2, Executors.defaultThreadFactory());
private static final String PROJECT_ID = "dummyprojectid";
private static final String responseBoundary = "____THIS_IS_HELPERS_BOUNDARY____";
private static final String responseSeparator = new StringBuilder("--")
.append(responseBoundary)
.append("\r\n")
.toString();
private static final String responseEnd = new StringBuilder("--")
.append(responseBoundary)
.append("--\r\n\r\n")
.toString();

static {
try {
Expand Down Expand Up @@ -356,15 +365,6 @@ private Response handleBatch(final HttpExchange exchange) throws IOException {
String contentType = exchange.getRequestHeaders().getFirst("Content-type");
if (contentType != null) {
int port = server.getAddress().getPort();
String responseBoundary = "____THIS_IS_HELPERS_BOUNDARY____";
String responseSeparator = new StringBuilder("--")
.append(responseBoundary)
.append("\r\n")
.toString();
String responseEnd = new StringBuilder("--")
.append(responseBoundary)
.append("--\r\n\r\n")
.toString();
HttpMediaType httpMediaType = new HttpMediaType(contentType);
String boundary = httpMediaType.getParameter("boundary");
MultipartStream multipartStream =
Expand Down Expand Up @@ -412,7 +412,7 @@ private Response handleBatch(final HttpExchange exchange) throws IOException {
}
}
out.write(responseEnd.getBytes());
writeBatchResponse(exchange, out, responseBoundary);
writeBatchResponse(exchange, out);
}
return null;
}
Expand Down Expand Up @@ -520,11 +520,10 @@ private static void writeResponse(HttpExchange exchange, Response response) {
}
}

private static void writeBatchResponse(HttpExchange exchange, ByteArrayOutputStream out,
String boundary) {
exchange.getResponseHeaders().set("Content-type", "multipart/mixed; boundary=" + boundary);
private static void writeBatchResponse(HttpExchange exchange, ByteArrayOutputStream out) {
exchange.getResponseHeaders().set(
"Content-type", "multipart/mixed; boundary=" + responseBoundary);
try {
exchange.getResponseHeaders().add("Connection", "close");
exchange.getResponseHeaders().add("Connection", "close");
exchange.sendResponseHeaders(200, out.toByteArray().length);
OutputStream responseBody = exchange.getResponseBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ public void onFailure(GoogleJsonError googleJsonError) {
batch.addGetChangeRequest(created.getName(), "0", new RpcBatch.Callback<Change>() {
@Override
public void onSuccess(Change response) {
assertEquals(RPC.getChangeRequest(created.getName(), "0", EMPTY_RPC_OPTIONS),response);
assertEquals(RPC.getChangeRequest(created.getName(), "0", EMPTY_RPC_OPTIONS), response);
}

@Override
Expand Down

0 comments on commit 0b168fb

Please sign in to comment.