Exemplo n.º 1
0
  public String toRelativeUrl() {
    StringBuilder sb = StringUtils.stringBuilder();
    if (MiscUtils.isNonEmpty(path)) sb.append(path);
    else sb.append('/');
    if (query != null) sb.append('?').append(query);

    return sb.toString();
  }
Exemplo n.º 2
0
 private static String toHexString(byte[] data) {
   StringBuilder buffer = StringUtils.stringBuilder();
   for (int i = 0; i < data.length; i++) {
     buffer.append(Integer.toHexString((data[i] & 0xf0) >>> 4));
     buffer.append(Integer.toHexString(data[i] & 0x0f));
   }
   return buffer.toString();
 }
  private NettyBody body(Request request, boolean connect) throws IOException {
    NettyBody nettyBody = null;
    if (!connect) {

      Charset bodyCharset =
          request.getBodyCharset() == null ? DEFAULT_CHARSET : request.getBodyCharset();

      if (request.getByteData() != null) nettyBody = new NettyByteArrayBody(request.getByteData());
      else if (request.getCompositeByteData() != null)
        nettyBody = new NettyCompositeByteArrayBody(request.getCompositeByteData());
      else if (request.getStringData() != null)
        nettyBody =
            new NettyByteBufferBody(
                StringUtils.charSequence2ByteBuffer(request.getStringData(), bodyCharset));
      else if (request.getByteBufferData() != null)
        nettyBody = new NettyByteBufferBody(request.getByteBufferData());
      else if (request.getStreamData() != null)
        nettyBody = new NettyInputStreamBody(request.getStreamData(), config);
      else if (isNonEmpty(request.getFormParams())) {

        String contentType = null;
        if (!request.getHeaders().containsKey(CONTENT_TYPE))
          contentType = HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED;

        nettyBody =
            new NettyByteBufferBody(
                urlEncodeFormParams(request.getFormParams(), bodyCharset), contentType);

      } else if (isNonEmpty(request.getParts()))
        nettyBody = new NettyMultipartBody(request.getParts(), request.getHeaders(), config);
      else if (request.getFile() != null) nettyBody = new NettyFileBody(request.getFile(), config);
      else if (request.getBodyGenerator() instanceof FileBodyGenerator) {
        FileBodyGenerator fileBodyGenerator = (FileBodyGenerator) request.getBodyGenerator();
        nettyBody =
            new NettyFileBody(
                fileBodyGenerator.getFile(),
                fileBodyGenerator.getRegionSeek(),
                fileBodyGenerator.getRegionLength(),
                config);

      } else if (request.getBodyGenerator() instanceof InputStreamBodyGenerator)
        nettyBody =
            new NettyInputStreamBody(
                InputStreamBodyGenerator.class.cast(request.getBodyGenerator()).getInputStream(),
                config);
      else if (request.getBodyGenerator() != null)
        nettyBody = new NettyBodyBody(request.getBodyGenerator().createBody(), config);
    }

    return nettyBody;
  }
Exemplo n.º 4
0
 public String toUrl() {
   if (url == null) {
     StringBuilder sb = StringUtils.stringBuilder();
     sb.append(scheme).append("://");
     if (userInfo != null) sb.append(userInfo).append('@');
     sb.append(host);
     if (port != -1) sb.append(':').append(port);
     if (path != null) sb.append(path);
     if (query != null) sb.append('?').append(query);
     url = sb.toString();
     sb.setLength(0);
   }
   return url;
 }
Exemplo n.º 5
0
    private void newResponse(MessageDigest md) {
      // BEWARE: compute first as it used the cached StringBuilder
      String digestUri = AuthenticatorUtils.computeRealmURI(uri, useAbsoluteURI, omitQuery);

      StringBuilder sb = StringUtils.stringBuilder();

      // WARNING: DON'T MOVE, BUFFER IS RECYCLED!!!!
      byte[] secretDigest = secretDigest(sb, md);
      byte[] dataDigest = dataDigest(sb, digestUri, md);

      appendBase16(sb, secretDigest);
      appendDataBase(sb);
      appendBase16(sb, dataDigest);

      byte[] responseDigest = md5FromRecycledStringBuilder(sb, md);
      response = toHexString(responseDigest);
    }
Exemplo n.º 6
0
 private byte[] md5FromRecycledStringBuilder(StringBuilder sb, MessageDigest md) {
   md.update(StringUtils.charSequence2ByteBuffer(sb, ISO_8859_1));
   sb.setLength(0);
   return md.digest();
 }