@Test(dataProvider = "objects") public void testObject(String key) throws InterruptedException { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: BindAsHostPrefixIfConfigured binder = injector.getInstance(BindAsHostPrefixIfConfigured.class); request = binder.bindToRequest(request, "bucket"); assertEquals(request.getRequestLine(), "GET http: }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { String payloadAsString = payload.toString(); if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) { request = bindAsHostPrefix.bindToRequest(request, payload); String host = request.getEndpoint().getHost(); if (request.getEndpoint().getPort() != -1) { host += ":" + request.getEndpoint().getPort(); } return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build(); } else { StringBuilder path = new StringBuilder(request.getEndpoint().getRawPath()); if (servicePath.equals("/")) { if (path.toString().equals("/")) path.append(payloadAsString); else path.insert(0, "/" + payloadAsString); } else { int indexToInsert = 0; indexToInsert = path.indexOf(servicePath); indexToInsert = indexToInsert == -1 ? 0 : indexToInsert; indexToInsert += servicePath.length(); path.insert(indexToInsert, "/" + payloadAsString); } return (R) request.toBuilder().replacePath(path.toString()).build(); } }
BindAsHostPrefixIfConfigured implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { String payloadAsString = payload.toString(); if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) { request = bindAsHostPrefix.bindToRequest(request, payload); String host = request.getEndpoint().getHost(); if (request.getEndpoint().getPort() != -1) { host += ":" + request.getEndpoint().getPort(); } return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build(); } else { StringBuilder path = new StringBuilder(request.getEndpoint().getRawPath()); if (servicePath.equals("/")) { if (path.toString().equals("/")) path.append(payloadAsString); else path.insert(0, "/" + payloadAsString); } else { int indexToInsert = 0; indexToInsert = path.indexOf(servicePath); indexToInsert = indexToInsert == -1 ? 0 : indexToInsert; indexToInsert += servicePath.length(); path.insert(indexToInsert, "/" + payloadAsString); } return (R) request.toBuilder().replacePath(path.toString()).build(); } } }
BindAsHostPrefixIfConfigured implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { String payloadAsString = payload.toString(); if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) { request = bindAsHostPrefix.bindToRequest(request, payload); String host = request.getEndpoint().getHost(); if (request.getEndpoint().getPort() != -1) { host += ":" + request.getEndpoint().getPort(); } return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build(); } else { StringBuilder path = new StringBuilder(request.getEndpoint().getRawPath()); if (servicePath.equals("/")) { if (path.toString().equals("/")) path.append(payloadAsString); else path.insert(0, "/" + payloadAsString); } else { int indexToInsert = 0; indexToInsert = path.indexOf(servicePath); indexToInsert = indexToInsert == -1 ? 0 : indexToInsert; indexToInsert += servicePath.length(); path.insert(indexToInsert, "/" + payloadAsString); } return (R) request.toBuilder().replacePath(path.toString()).build(); } } @Inject  BindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,
            @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
            @Named(PROPERTY_S3_SERVICE_PATH) String servicePath); }
BindAsHostPrefixIfConfigured implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { String payloadAsString = payload.toString(); if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) { request = bindAsHostPrefix.bindToRequest(request, payload); String host = request.getEndpoint().getHost(); if (request.getEndpoint().getPort() != -1) { host += ":" + request.getEndpoint().getPort(); } return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build(); } else { StringBuilder path = new StringBuilder(request.getEndpoint().getRawPath()); if (servicePath.equals("/")) { if (path.toString().equals("/")) path.append(payloadAsString); else path.insert(0, "/" + payloadAsString); } else { int indexToInsert = 0; indexToInsert = path.indexOf(servicePath); indexToInsert = indexToInsert == -1 ? 0 : indexToInsert; indexToInsert += servicePath.length(); path.insert(indexToInsert, "/" + payloadAsString); } return (R) request.toBuilder().replacePath(path.toString()).build(); } } @Inject  BindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,
            @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
            @Named(PROPERTY_S3_SERVICE_PATH) String servicePath); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object payload); }
BindAsHostPrefixIfConfigured implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { String payloadAsString = payload.toString(); if (isVhostStyle && payloadAsString.equals(payloadAsString.toLowerCase())) { request = bindAsHostPrefix.bindToRequest(request, payload); String host = request.getEndpoint().getHost(); if (request.getEndpoint().getPort() != -1) { host += ":" + request.getEndpoint().getPort(); } return (R) request.toBuilder().replaceHeader(HttpHeaders.HOST, host).build(); } else { StringBuilder path = new StringBuilder(request.getEndpoint().getRawPath()); if (servicePath.equals("/")) { if (path.toString().equals("/")) path.append(payloadAsString); else path.insert(0, "/" + payloadAsString); } else { int indexToInsert = 0; indexToInsert = path.indexOf(servicePath); indexToInsert = indexToInsert == -1 ? 0 : indexToInsert; indexToInsert += servicePath.length(); path.insert(indexToInsert, "/" + payloadAsString); } return (R) request.toBuilder().replacePath(path.toString()).build(); } } @Inject  BindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,
            @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
            @Named(PROPERTY_S3_SERVICE_PATH) String servicePath); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object payload);  }