Java 类com.amazonaws.DefaultRequest 实例源码

项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void static_queryparams_in_path_added_to_request(){
    final String uriResourcePath = "/foo/bar";
    final String uriResourcePathWithParams =
            uriResourcePath + "?param1=value1&param2=value2";
    final Request<Object> request = new DefaultRequest<Object>
            (null, null);

    Assert.assertEquals(uriResourcePath, UriResourcePathUtils
            .addStaticQueryParamtersToRequest(request,
                    uriResourcePathWithParams));
    Assert.assertTrue(request.getParameters().containsKey("param1"));
    Assert.assertTrue(request.getParameters().containsKey("param2"));
    Assert.assertEquals(Arrays.asList("value1"), request.getParameters().get("param1"));
    Assert.assertEquals(Arrays.asList("value2"), request.getParameters().get("param2"));

}
项目:ibm-cos-sdk-java    文件:RetryPolicyContextTest.java   
@Test
public void buildFully() {
    final EmptyAmazonWebServiceRequest origRequest = new EmptyAmazonWebServiceRequest();
    final DefaultRequest<EmptyAmazonWebServiceRequest> request =
            new DefaultRequest<EmptyAmazonWebServiceRequest>(origRequest, "foo");
    final SdkClientException exception = new SdkClientException("boom");
    final RetryPolicyContext context = RetryPolicyContext.builder()
            .retriesAttempted(3)
            .httpStatusCode(400)
            .request(request)
            .exception(exception)
            .originalRequest(origRequest)
            .build();


    assertEquals(3, context.retriesAttempted());
    assertEquals(Integer.valueOf(400), context.httpStatusCode());
    assertEquals(request, context.request());
    assertEquals(exception, context.exception());
    assertEquals(origRequest, context.originalRequest());
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
protected <X extends AmazonWebServiceRequest> Request<X> createRequest(String bucketName, String key, X originalRequest, HttpMethodName httpMethod, URI endpoint) {
    // If the underlying AmazonS3Client has enabled accelerate mode and the original
    // request operation is accelerate mode supported, then the request will use the
    // s3-accelerate endpoint to performe the operations.
    if (clientOptions.isAccelerateModeEnabled() && !(originalRequest instanceof S3AccelerateUnsupported)) {
        if (clientOptions.isDualstackEnabled()) {
            endpoint = RuntimeHttpUtils.toUri(Constants.S3_ACCELERATE_DUALSTACK_HOSTNAME, clientConfiguration);
        } else {
            endpoint = RuntimeHttpUtils.toUri(Constants.S3_ACCELERATE_HOSTNAME, clientConfiguration);
        }
    }

    Request<X> request = new DefaultRequest<X>(originalRequest, Constants.S3_SERVICE_DISPLAY_NAME);
    request.setHttpMethod(httpMethod);
    request.addHandlerContext(S3HandlerContextKeys.IS_CHUNKED_ENCODING_DISABLED,
            Boolean.valueOf(clientOptions.isChunkedEncodingDisabled()));
    request.addHandlerContext(S3HandlerContextKeys.IS_PAYLOAD_SIGNING_ENABLED,
            Boolean.valueOf(clientOptions.isPayloadSigningEnabled()));
    resolveRequestEndpoint(request, bucketName, key, endpoint);

    return request;
}
项目:charles-rest    文件:EsHttpRequest.java   
/**
 * Ctor.
 * @param esEdp ElasticSearch URL.
 * @param uri REST path to the desired ElasticSearch endpoint.
 * @param respHandler Response handler.
 * @param errHandle Error handler.
 */
public EsHttpRequest(
    EsEndPoint esEdp,
    String uri,
    HttpResponseHandler<T> respHandler,
    HttpResponseHandler<AmazonServiceException> errHandler
){
    this.request = new DefaultRequest<Void>("es");
    String esEndpoint = esEdp.read();
    if(esEndpoint == null || esEndpoint.isEmpty()) {
        throw new IllegalStateException("ElasticSearch endpoint needs to be specified!");
    }
    if(esEndpoint.endsWith("/")) {
        esEndpoint += uri;
    } else {
        esEndpoint += "/" + uri;
    }
    this.request.setEndpoint(URI.create(esEndpoint));


    this.respHandler = respHandler;
    this.errHandler = errHandler;
}
项目:spectator    文件:SpectatorRequestMetricCollectorTest.java   
private void execRequest(String endpoint, int status) {
  AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport();
  metrics.addProperty(AWSRequestMetrics.Field.ServiceName, "AmazonCloudWatch");
  metrics.addProperty(AWSRequestMetrics.Field.ServiceEndpoint, endpoint);
  metrics.addProperty(AWSRequestMetrics.Field.StatusCode, "" + status);
  if (status == 503) {
    metrics.addProperty(AWSRequestMetrics.Field.AWSErrorCode, "Throttled");
  }
  String counterName = "BytesProcessed";
  String timerName = "ClientExecuteTime";
  metrics.setCounter(counterName, 12345);
  metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L));

  Request<?> req = new DefaultRequest(new ListMetricsRequest(), "AmazonCloudWatch");
  req.setAWSRequestMetrics(metrics);
  req.setEndpoint(URI.create(endpoint));

  HttpResponse hr = new HttpResponse(req, new HttpPost(endpoint));
  hr.setStatusCode(status);
  Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost(endpoint)));

  collector.collectMetrics(req, resp);
}
项目:apigateway-generic-java-sdk    文件:GenericApiGatewayClient.java   
private GenericApiGatewayResponse execute(HttpMethodName method, String resourcePath, Map<String, String> headers, InputStream content) {
    final ExecutionContext executionContext = buildExecutionContext();

    DefaultRequest request = new DefaultRequest(API_GATEWAY_SERVICE_NAME);
    request.setHttpMethod(method);
    request.setContent(content);
    request.setEndpoint(this.endpoint);
    request.setResourcePath(resourcePath);
    request.setHeaders(buildRequestHeaders(headers, apiKey));

    return this.client.execute(request, responseHandler, errorResponseHandler, executionContext).getAwsResponse();
}
项目:ibm-cos-sdk-java    文件:JsonProtocolMarshaller.java   
private DefaultRequest<OrigRequest> createRequest(OperationInfo operationInfo, OrigRequest originalRequest) {
    if (originalRequest instanceof AmazonWebServiceRequest) {
        return new DefaultRequest<OrigRequest>((AmazonWebServiceRequest) originalRequest, operationInfo.serviceName());
    } else {
        return new DefaultRequest<OrigRequest>(operationInfo.serviceName());
    }
}
项目:ibm-cos-sdk-java    文件:SdkStructuredIonFactoryTest.java   
private static HttpResponse createResponse(IonStruct payload) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    IonWriter writer = system.newBinaryWriter(bytes);
    payload.writeTo(writer);
    writer.close();

    HttpResponse error = new HttpResponse(new DefaultRequest(NO_SERVICE_NAME), NO_HTTP_REQUEST);
    error.setContent(new ByteArrayInputStream(bytes.toByteArray()));
    return error;
}
项目:ibm-cos-sdk-java    文件:ApacheDefaultHttpRequestFactoryTest.java   
private DefaultRequest<Object> newDefaultRequest(HttpMethodName httpMethod) throws
        URISyntaxException {

    final DefaultRequest<Object> request = new DefaultRequest<Object>
            (null, SERVICE_NAME);
    request.setEndpoint(new URI(ENDPOINT));
    request.setHttpMethod(httpMethod);
    return request;
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testRetryIOExceptionFromExecute() throws IOException {
    IOException exception = new IOException("BOOM");

    EasyMock.reset(httpClient);

    EasyMock
        .expect(httpClient.getConnectionManager())
        .andReturn(null)
        .anyTimes();

    EasyMock
        .expect(httpClient.execute(EasyMock.<HttpUriRequest>anyObject(),
                                   EasyMock.<HttpContext>anyObject()))
        .andThrow(exception)
        .times(4);

    EasyMock.replay(httpClient);

    ExecutionContext context = new ExecutionContext();

    Request<?> request = new DefaultRequest<Object>("testsvc");
    request.setEndpoint(java.net.URI.create(
            "http://testsvc.region.amazonaws.com"));
    request.setContent(new ByteArrayInputStream(new byte[0]));

    try {

        client.requestExecutionBuilder().request(request).executionContext(context).execute();
        Assert.fail("No exception when request repeatedly fails!");

    } catch (AmazonClientException e) {
        Assert.assertSame(exception, e.getCause());
    }

    // Verify that we called execute 4 times.
    EasyMock.verify(httpClient);
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
private Request<?> mockRequest(String serverName, HttpMethodName methodName, String uri, boolean hasCL) {
    Request<?> request = new DefaultRequest<Object>(null, serverName);
    request.setHttpMethod(methodName);
    request.setContent(new ByteArrayInputStream(new byte[100]));
    request.setEndpoint(URI.create(uri));
    if (hasCL) request.addHeader("Content-Length", "100");

    return request;
}
项目:ibm-cos-sdk-java    文件:JsonErrorResponseHandlerTest.java   
@Before
public void setup() throws UnsupportedEncodingException {
    MockitoAnnotations.initMocks(this);
    when(errorCodeParser
                 .parseErrorCode((HttpResponse) anyObject(), (JsonContent) anyObject()))
            .thenReturn(ERROR_CODE);

    httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null);
    httpResponse.setContent(new StringInputStream("{}"));

    responseHandler = new JsonErrorResponseHandler(Arrays.asList(unmarshaller), errorCodeParser,
                                                   JsonErrorMessageParser.DEFAULT_ERROR_MESSAGE_PARSER,
                                                   new JsonFactory());
}
项目:ibm-cos-sdk-java    文件:RuntimeHttpUtilsTest.java   
@Test(expected = SdkClientException.class)
public void endpointWithoutProtocol_ThrowsSdkClientException() {
    Request<?> request = new DefaultRequest<Object>("foo");
    request.setEndpoint(URI.create("foo.amazon.com"));
    request.setResourcePath("foo/bar");
    RuntimeHttpUtils.convertRequestToUrl(request, false, false);
}
项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void uri_resource_path_ends_with_question_mark_returns_path_removed_with_question_mark(){

    final String expectedResourcePath = "/foo/bar";
    final String pathWithEmptyStaticQueryParams = expectedResourcePath + "?";

    Assert.assertEquals(expectedResourcePath, UriResourcePathUtils
            .addStaticQueryParamtersToRequest(new DefaultRequest<Object>
                    (null, null), pathWithEmptyStaticQueryParams));

}
项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void queryparam_value_empty_adds_parameter_with_empty_string_to_request() {
    final String uriResourcePath = "/foo/bar";
    final String uriResourcePathWithParams =
            uriResourcePath + "?param1=";

    final Request<Object> request = new DefaultRequest<Object>
            (null, null);

    Assert.assertEquals(uriResourcePath, UriResourcePathUtils
            .addStaticQueryParamtersToRequest(request,
                    uriResourcePathWithParams));
    Assert.assertTrue(request.getParameters().containsKey("param1"));
    Assert.assertEquals(Arrays.asList(""), request.getParameters().get("param1"));
}
项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void queryparam_without_value_returns_list_containing_null_value() {
    final String uriResourcePath = "/foo/bar";
    final String uriResourcePathWithParams =
            uriResourcePath + "?param";
    final Request<Object> request = new DefaultRequest<Object>(null, null);

    Assert.assertEquals(uriResourcePath, UriResourcePathUtils.addStaticQueryParamtersToRequest(request, uriResourcePathWithParams));

    Assert.assertTrue(request.getParameters().containsKey("param"));
    Assert.assertEquals(Arrays.asList((String)null), request.getParameters().get("param"));
}
项目:ibm-cos-sdk-java    文件:RetryPolicyTestBase.java   
@SuppressWarnings("rawtypes")
public static Request<?> getSampleRequestWithRepeatableContent(AmazonWebServiceRequest amazonWebServiceRequest) {
    DefaultRequest<?> request = new DefaultRequest(
            amazonWebServiceRequest, "non-existent-service");
    request.setEndpoint(URI.create("http://non-existent-service.amazonaws.com"));
    // StringInputStream#markSupported() returns true
    try {
        request.setContent(new StringInputStream("Some content that could be read for multiple times."));
    } catch (UnsupportedEncodingException e) {
        Assert.fail("Unable to set up the request content");
    }
    return request;
}
项目:ibm-cos-sdk-java    文件:RetryPolicyTestBase.java   
@SuppressWarnings("rawtypes")
public static Request<?> getSampleRequestWithNonRepeatableContent(AmazonWebServiceRequest amazonWebServiceRequest) {
    DefaultRequest<?> request = new DefaultRequest(
            amazonWebServiceRequest, "non-existent-service");
    request.setEndpoint(URI.create("http://non-existent-service.amazonaws.com"));
    // NonRepeatableInputStream#markSupported() returns false
    request.setContent(new NonRepeatableInputStream("Some content that could only be read once."));
    return request;
}
项目:ibm-cos-sdk-java    文件:AmazonS3ClientTest.java   
/**
 * Test Service Instance Id is added to the Request Object and
 * the runtime parameter takes precedence over any set by the
 * CredentialProvider
 * 
 */ 
@Test
public void testServiceInstanceRuntimeParamTakesPrecedence() {

    String serviceInstanceId = "12345";

    CreateBucketRequest request = new CreateBucketRequest("testbucket").withServiceInstanceId(serviceInstanceId);
    Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
    AmazonS3Client s3Client = new AmazonS3Client(new BasicIBMOAuthCredentials(new TokenMangerUtilTest(), "54321"));
    defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);

    assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), serviceInstanceId);
}
项目:ibm-cos-sdk-java    文件:AmazonS3ClientTest.java   
/**
 * Test Service Instance Id is added to the Request Object by 
 * the CredentialProvider
 * 
 */ 
@Test
public void testServiceInstanceHeaderIsAddedByCredentialProvdier() {

    String serviceInstanceId = "12345";

    CreateBucketRequest request = new CreateBucketRequest("testbucket");
    Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
    AmazonS3Client s3Client = new AmazonS3Client(new BasicIBMOAuthCredentials(new TokenMangerUtilTest(), serviceInstanceId));
    defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);

    assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), serviceInstanceId);
}
项目:ibm-cos-sdk-java    文件:AmazonS3ClientTest.java   
/**
 * Test No IAM Headers are added & no null pointers are thrown
 * 
 */ 
@Test
public void testNoIAMHeadersAreAdded() {

    CreateBucketRequest request = new CreateBucketRequest("testbucket");
    Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
    AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials("987654321", "123456789"));
    defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);

    assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), null);
}
项目:spring-vault    文件:AwsIamAuthentication.java   
private static String getSignedHeaders(AwsIamAuthenticationOptions options) {

        Map<String, String> headers = createIamRequestHeaders(options);

        AWS4Signer signer = new AWS4Signer();

        DefaultRequest<String> request = new DefaultRequest<>("sts");

        request.setContent(new ByteArrayInputStream(REQUEST_BODY.getBytes()));
        request.setHeaders(headers);
        request.setHttpMethod(HttpMethodName.POST);
        request.setEndpoint(options.getEndpointUri());

        signer.setServiceName(request.getServiceName());
        signer.sign(request, options.getCredentialsProvider().getCredentials());

        Map<String, Object> map = new LinkedHashMap<>();

        for (Entry<String, String> entry : request.getHeaders().entrySet()) {
            map.put(entry.getKey(), Collections.singletonList(entry.getValue()));
        }

        try {
            return OBJECT_MAPPER.writeValueAsString(map);
        }
        catch (JsonProcessingException e) {
            throw new IllegalStateException("Cannot serialize headers to JSON", e);
        }
    }
项目:para-client-android    文件:Signer.java   
private DefaultRequest<?> buildAWSRequest(int httpMethod, String endpoint, String resourcePath,
                   Map<String, String> headers, Map<String, String> params, InputStream entity) {

    DefaultRequest<AmazonWebServiceRequest> r = new DefaultRequest<AmazonWebServiceRequest>(PARA);
    String method = getMethodString(httpMethod);
    r.setHttpMethod(HttpMethodName.valueOf(method));
    if (!StringUtils.isBlank(endpoint)) {
        if (!endpoint.startsWith("http")) {
            endpoint = "https://" + endpoint;
        }
        r.setEndpoint(URI.create(endpoint));
    }
    if (!StringUtils.isBlank(resourcePath)) {
        r.setResourcePath(resourcePath);
    }
    if (headers != null) {
        if (headers.containsKey("x-amz-date")) {
            overriddenDate = parseAWSDate(headers.get("x-amz-date"));
        }
        // we don't need these here, added by default
        headers.remove("host");
        headers.remove("x-amz-date");
        r.setHeaders(headers);
    }
    if (params != null) {
        for (Map.Entry<String, String> param : params.entrySet()) {
            r.addParameter(param.getKey(), param.getValue());
        }
    }
    if (entity != null) {
        r.setContent(entity);
    }
    return r;
}
项目:aws-signing-request-interceptor    文件:SkdSignerUtil.java   
static public String getExpectedAuthorizationHeader(Request request) throws Exception {
    // create the signable request
    DefaultRequest signableRequest = new DefaultRequest(null, request.getServiceName());
    signableRequest.setEndpoint(new URI("http://" + request.getHost()));
    signableRequest.setResourcePath(request.getUri());
    signableRequest.setHttpMethod(HttpMethodName.valueOf(request.getHttpMethod()));
    signableRequest.setContent(new StringInputStream(request.getBody()));
    if (request.getHeaders() != null)
        signableRequest.setHeaders(request.getHeaders());
    if (request.getQueryParams() != null) {
        Map<String, List<String>> convertedQueryParams = new HashMap<>();
        for (String paramName : request.getQueryParams().keySet()) {
            convertedQueryParams.put(paramName, new ArrayList<>(request.getQueryParams().get(paramName)));
        }
        signableRequest.setParameters(convertedQueryParams);
    }

    /*
       Init the signer class

       Note: Double uri encoding is off simple before the signature does not match the expected signature of the test cases
       if it is enabled.  This was a bit unexpected because AWSElasticsearchClient (AWS SDK Class) enabled double URI encoding
       in the signer by default.  I can only assume that double encoding is needed when accessing the service but not when accessing
       elasticsearch.
     */
    AWS4Signer aws4Signer = new AWS4Signer(false);
    aws4Signer.setServiceName(request.getServiceName());
    aws4Signer.setRegionName(request.getRegion());
    Method method1 = AWS4Signer.class.getDeclaredMethod("setOverrideDate", Date.class);
    method1.setAccessible(true);
    method1.invoke(aws4Signer, request.getDate());
    aws4Signer.sign(signableRequest, request.getCredentialsProvider().getCredentials());

    return (String) signableRequest.getHeaders().get("Authorization");
}
项目:ivona-speechcloud-sdk-java    文件:GetLexiconPostRequestMarshaller.java   
public Request<GetLexiconRequest> marshall(GetLexiconRequest getLexiconRequest) {
    if (getLexiconRequest == null) {
        throw new AmazonClientException("null getLexiconRequest passed to marshall(...)");
    }

    Request<GetLexiconRequest> request = new DefaultRequest<GetLexiconRequest>(getLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, getLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
项目:ivona-speechcloud-sdk-java    文件:ListLexiconsPostRequestMarshaller.java   
public Request<ListLexiconsRequest> marshall(ListLexiconsRequest listLexiconsRequest) {
    if (listLexiconsRequest == null) {
        throw new AmazonClientException("null listLexiconsRequest passed to marshall(...)");
    }

    Request<ListLexiconsRequest> request = new DefaultRequest<ListLexiconsRequest>(listLexiconsRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, listLexiconsRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
项目:ivona-speechcloud-sdk-java    文件:PutLexiconPostRequestMarshaller.java   
public Request<PutLexiconRequest> marshall(PutLexiconRequest putLexiconRequest) {
    if (putLexiconRequest == null) {
        throw new AmazonClientException("null putLexiconRequest passed to marshall(...)");
    }

    Request<PutLexiconRequest> request = new DefaultRequest<PutLexiconRequest>(putLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, putLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
项目:ivona-speechcloud-sdk-java    文件:DeleteLexiconPostRequestMarshaller.java   
public Request<DeleteLexiconRequest> marshall(DeleteLexiconRequest deleteLexiconRequest) {
    if (deleteLexiconRequest == null) {
        throw new AmazonClientException("null deleteLexiconRequest passed to marshall(...)");
    }

    Request<DeleteLexiconRequest> request = new DefaultRequest<DeleteLexiconRequest>(deleteLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, deleteLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
项目:ivona-speechcloud-sdk-java    文件:ListVoicesGetRequestMarshaller.java   
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

        if (listVoicesRequest == null) {
            throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
        }

        Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
                IvonaSpeechCloudClient.SERVICE_NAME);
        request.setHttpMethod(HttpMethodName.GET);
        request.setResourcePath(RESOURCE_PATH);

        setRequestParameters(request, listVoicesRequest);

        return request;
    }
项目:ivona-speechcloud-sdk-java    文件:ListVoicesPostRequestMarshaller.java   
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

        if (listVoicesRequest == null) {
            throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
        }

        Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
                IvonaSpeechCloudClient.SERVICE_NAME);
        request.setHttpMethod(HttpMethodName.POST);
        request.setResourcePath(RESOURCE_PATH);
        setRequestPayload(request, listVoicesRequest);
        return request;
    }
项目:ivona-speechcloud-sdk-java    文件:CreateSpeechPostRequestMarshaller.java   
public Request<CreateSpeechRequest> marshall(CreateSpeechRequest createSpeechRequest) {

        if (createSpeechRequest == null) {
            throw new AmazonClientException("null createSpeechRequest passed to marshall(...)");
        }

        Request<CreateSpeechRequest> request = new DefaultRequest<CreateSpeechRequest>(createSpeechRequest,
                IvonaSpeechCloudClient.SERVICE_NAME);
        request.setHttpMethod(HttpMethodName.POST);
        setRequestPayload(request, createSpeechRequest);
        request.setResourcePath(RESOURCE_PATH);

        return request;
    }
项目:ivona-speechcloud-sdk-java    文件:CreateSpeechGetRequestMarshaller.java   
public Request<CreateSpeechRequest> marshall(CreateSpeechRequest createSpeechRequest) {
    if (createSpeechRequest == null) {
        throw new AmazonClientException("null createSpeechRequest passed to marshall(...)");
    }

    Request<CreateSpeechRequest> request = new DefaultRequest<CreateSpeechRequest>(createSpeechRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    setRequestParameters(request, createSpeechRequest);
    request.setHttpMethod(HttpMethodName.GET);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}
项目:para    文件:Signer.java   
private Request<?> buildAWSRequest(String httpMethod, String endpoint, String resourcePath,
        Map<String, String> headers, Map<String, String> params, InputStream entity) {
    Request<AmazonWebServiceRequest> r = new DefaultRequest<>(Config.PARA);

    if (!StringUtils.isBlank(httpMethod)) {
        r.setHttpMethod(HttpMethodName.valueOf(httpMethod));
    }
    if (!StringUtils.isBlank(endpoint)) {
        if (!endpoint.startsWith("http")) {
            endpoint = "https://" + endpoint;
        }
        r.setEndpoint(URI.create(endpoint));
    }
    if (!StringUtils.isBlank(resourcePath)) {
        r.setResourcePath(SdkHttpUtils.urlEncode(resourcePath, true));
    }
    if (headers != null) {
        if (headers.containsKey("x-amz-date")) {
            overriddenDate = parseAWSDate(headers.get("x-amz-date"));
        }
        // we don't need these here, added by default
        headers.remove("host");
        headers.remove("x-amz-date");
        r.setHeaders(headers);
    }
    if (params != null) {
        for (Map.Entry<String, String> param : params.entrySet()) {
            r.addParameter(param.getKey(), param.getValue());
        }
    }
    if (entity != null) {
        r.setContent(entity);
    }
    return r;
}
项目:aws-hal-client-java    文件:HalClient.java   
private Request buildRequest(HttpMethodName httpMethodName, String resourcePath, Object representation) {
    Request request = new DefaultRequest(null);

    request.setHttpMethod(httpMethodName);
    request.setEndpoint(endpoint);

    populateResourcePathAndParameters(request, resourcePath);

    if (representation != null) {
        assignContent(request, representation);
    }

    return request;
}
项目:ibm-cos-sdk-java    文件:WireMockTestBase.java   
protected Request<?> newRequest(String resourcePath) {
    Request<?> request = new DefaultRequest<String>("mock");
    request.setEndpoint(URI.create("http://localhost:" + mockServer.port() + resourcePath));
    return request;
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testRetryIOExceptionFromHandler() throws Exception {
    final IOException exception = new IOException("BOOM");

    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler =
            EasyMock.createMock(HttpResponseHandler.class);

    EasyMock
        .expect(handler.needsConnectionLeftOpen())
        .andReturn(false)
        .anyTimes();

    EasyMock
        .expect(handler.handle(EasyMock.<HttpResponse>anyObject()))
        .andThrow(exception)
        .times(4);

    EasyMock.replay(handler);

    BasicHttpResponse response = createBasicHttpResponse();

    EasyMock.reset(httpClient);

    EasyMock
        .expect(httpClient.getConnectionManager())
        .andReturn(null)
        .anyTimes();

    EasyMock
        .expect(httpClient.execute(EasyMock.<HttpUriRequest>anyObject(),
                                   EasyMock.<HttpContext>anyObject()))
        .andReturn(response)
        .times(4);

    EasyMock.replay(httpClient);

    ExecutionContext context = new ExecutionContext();

    Request<?> request = new DefaultRequest<Object>(null, "testsvc");
    request.setEndpoint(java.net.URI.create(
            "http://testsvc.region.amazonaws.com"));
    request.setContent(new java.io.ByteArrayInputStream(new byte[0]));

    try {

        client.requestExecutionBuilder().request(request).executionContext(context).execute(handler);
        Assert.fail("No exception when request repeatedly fails!");

    } catch (AmazonClientException e) {
        Assert.assertSame(exception, e.getCause());
    }

    // Verify that we called execute 4 times.
    EasyMock.verify(httpClient);
}
项目:ibm-cos-sdk-java    文件:RuntimeHttpUtilsTest.java   
private Request<?> newRequest() {
    Request<?> request = new DefaultRequest<Object>("foo");
    request.setEndpoint(ENDPOINT);
    return request;
}
项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void uri_resource_path_null_returns_null(){
    Assert.assertNull(UriResourcePathUtils
            .addStaticQueryParamtersToRequest(new DefaultRequest<Object>
                            (null , null), null));
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public URL getUrl(String bucketName, String key) {
    Request<?> request = new DefaultRequest<Object>(Constants.S3_SERVICE_DISPLAY_NAME);
    resolveRequestEndpoint(request, bucketName, key, endpoint);
    return ServiceUtils.convertRequestToUrl(request, false, false);
}
项目:charles-rest    文件:AwsHttpRequest.java   
public FakeAwsHttpRequest() {
    this.fakeRq = new DefaultRequest<>("fake");
    this.fakeRq.setEndpoint(
        URI.create("http://localhost:8080/test")
    );
}