sb.append(query);
}
URI uri = new URI(sb.toString());
RestRequestBuilder rb = new RestRequestBuilder(uri);
rb.setMethod(req.getMethod());
for (Enumeration<String> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();)
{
// TODO multi-valued headers
String headerName = headerNames.nextElement();
rb.setHeader(headerName, req.getHeader(headerName));
}
int length = req.getContentLength();
if (length >= 0)
{
InputStream in = req.getInputStream();
byte[] buf = new byte[length];
int offset = 0;
for (int r; offset < length && (r = in.read(buf, offset, length - offset)) != -1; offset += r)
{
}
rb.setEntity(buf);
}
return QueryTunnelUtil.decode(rb.build());
}