com.google.api.client.http.HttpMethods Java Examples

The following examples show how to use com.google.api.client.http.HttpMethods. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractGoogleClientRequestTest.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
public void testExecuteUsingHead() throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(final String method, final String url) {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() {
          assertEquals("HEAD", method);
          assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url);
          return new MockLowLevelHttpResponse();
        }
      };
    }
  };
  MockGoogleClient client = new MockGoogleClient.Builder(
      transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(
      "Test Application").build();
  MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>(
      client, HttpMethods.GET, URI_TEMPLATE, null, String.class);
  request.put("testId", "foo");
  request.executeUsingHead();
}
 
Example #2
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse deleteOrderForHttpResponse(String orderId) throws IOException {
    // verify the required parameter 'orderId' is set
    if (orderId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'orderId' when calling deleteOrder");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("order_id", orderId);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/store/order/{order_id}");

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute();
}
 
Example #3
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse getOrderByIdForHttpResponse(Long orderId) throws IOException {
    // verify the required parameter 'orderId' is set
    if (orderId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'orderId' when calling getOrderById");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("order_id", orderId);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/store/order/{order_id}");

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute();
}
 
Example #4
Source File: UserApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse deleteUserForHttpResponse(String username) throws IOException {
    // verify the required parameter 'username' is set
    if (username == null) {
        throw new IllegalArgumentException("Missing the required parameter 'username' when calling deleteUser");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("username", username);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/{username}");

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute();
}
 
Example #5
Source File: AbstractGoogleClientRequestTest.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
public void testExecute_void() throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(final String method, final String url) {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() {
          return new MockLowLevelHttpResponse().setContent("{\"a\":\"ignored\"}")
              .setContentType(Json.MEDIA_TYPE);
        }
      };
    }
  };
  MockGoogleClient client = new MockGoogleClient.Builder(
      transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(
      "Test Application").build();
  MockGoogleClientRequest<Void> request =
      new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class);
  Void v = request.execute();
  assertNull(v);
}
 
Example #6
Source File: UserApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse updateUserForHttpResponse(String username, User body) throws IOException {
    // verify the required parameter 'username' is set
    if (username == null) {
        throw new IllegalArgumentException("Missing the required parameter 'username' when calling updateUser");
    }// verify the required parameter 'body' is set
    if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling updateUser");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("username", username);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/{username}");

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = apiClient.new JacksonJsonHttpContent(body);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #7
Source File: UserApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse updateUserForHttpResponse(String username, java.io.InputStream body, String mediaType) throws IOException {
    // verify the required parameter 'username' is set
        if (username == null) {
        throw new IllegalArgumentException("Missing the required parameter 'username' when calling updateUser");
        }// verify the required parameter 'body' is set
        if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling updateUser");
        }
            // create a map of path variables
            final Map<String, Object> uriVariables = new HashMap<String, Object>();
                uriVariables.put("username", username);
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/user/{username}");

        String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
        GenericUrl genericUrl = new GenericUrl(localVarUrl);

        HttpContent content = body == null ?
          apiClient.new JacksonJsonHttpContent(null) :
          new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body);
        return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #8
Source File: MethodOverride.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
public void intercept(HttpRequest request) throws IOException {
  if (overrideThisMethod(request)) {
    String requestMethod = request.getRequestMethod();
    request.setRequestMethod(HttpMethods.POST);
    request.getHeaders().set(HEADER, requestMethod);
    if (requestMethod.equals(HttpMethods.GET)) {
      // take the URI query part and put it into the HTTP body
      request.setContent(new UrlEncodedContent(request.getUrl().clone()));
      // remove query parameters from URI
      request.getUrl().clear();
    } else if (request.getContent() == null) {
      // Google servers will fail to process a POST unless the Content-Length header is specified
      request.setContent(new EmptyContent());
    }
  }
}
 
Example #9
Source File: PetApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse deletePetForHttpResponse(Long petId, String apiKey) throws IOException {
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'petId' when calling deletePet");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/{petId}");

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.DELETE, genericUrl, content).execute();
}
 
Example #10
Source File: AbstractGoogleClientRequestTest.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
public void testReturnRawInputStream_defaultFalse() throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(final String method, final String url) {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() {
          return new MockLowLevelHttpResponse().setContentEncoding("gzip").setContent(new ByteArrayInputStream(
              BaseEncoding.base64()
                  .decode("H4sIAAAAAAAAAPNIzcnJV3DPz0/PSVVwzskvTVEILskvSkxPVQQA/LySchsAAAA=")));
        }
      };
    }
  };
  MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH,
      JSON_OBJECT_PARSER, null).setApplicationName(
      "Test Application").build();
  MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>(
      client, HttpMethods.GET, URI_TEMPLATE, null, String.class);
  InputStream inputStream = request.executeAsInputStream();
  // The response will be wrapped because of gzip encoding
  assertFalse(inputStream instanceof ByteArrayInputStream);
}
 
Example #11
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testBodyWithFileSchemaForHttpResponse(FileSchemaTestClass body, Map<String, Object> params) throws IOException {
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling testBodyWithFileSchema");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/body-with-file-schema");

    // Copy the params argument if present, to allow passing in immutable maps
    Map<String, Object> allParams = params == null ? new HashMap<String, Object>() : new HashMap<String, Object>(params);

    for (Map.Entry<String, Object> entry: allParams.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (key != null && value != null) {
            if (value instanceof Collection) {
                uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
            } else if (value instanceof Object[]) {
                uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
            } else {
                uriBuilder = uriBuilder.queryParam(key, value);
            }
        }
    }

    String localVarUrl = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = apiClient.new JacksonJsonHttpContent(body);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #12
Source File: PayrollAuApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse createEmployeeForHttpResponse(String accessToken,  String xeroTenantId,  List<Employee> employee) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createEmployee");
    }// verify the required parameter 'employee' is set
    if (employee == null) {
        throw new IllegalArgumentException("Missing the required parameter 'employee' when calling createEmployee");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createEmployee");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent());
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Employees");
    String url = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("POST " + genericUrl.toString());
    }
    
    HttpContent content = null;
    content = apiClient.new JacksonJsonHttpContent(employee);
    
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #13
Source File: BankFeedsApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse getStatementForHttpResponse(String accessToken,  String xeroTenantId,  UUID statementId) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getStatement");
    }// verify the required parameter 'statementId' is set
    if (statementId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'statementId' when calling getStatement");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getStatement");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent()); 
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("statementId", statementId);

    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Statements/{statementId}");
    String url = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("GET " + genericUrl.toString());
    }
    
    HttpContent content = null;
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #14
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testBodyWithFileSchemaForHttpResponse(java.io.InputStream body, String mediaType) throws IOException {
    // verify the required parameter 'body' is set
        if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling testBodyWithFileSchema");
        }
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/body-with-file-schema");

        String localVarUrl = uriBuilder.build().toString();
        GenericUrl genericUrl = new GenericUrl(localVarUrl);

        HttpContent content = body == null ?
          apiClient.new JacksonJsonHttpContent(null) :
          new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body);
        return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #15
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testEndpointParametersForHttpResponse(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Map<String, Object> params) throws IOException {
    // verify the required parameter 'number' is set
    if (number == null) {
        throw new IllegalArgumentException("Missing the required parameter 'number' when calling testEndpointParameters");
    }// verify the required parameter '_double' is set
    if (_double == null) {
        throw new IllegalArgumentException("Missing the required parameter '_double' when calling testEndpointParameters");
    }// verify the required parameter 'patternWithoutDelimiter' is set
    if (patternWithoutDelimiter == null) {
        throw new IllegalArgumentException("Missing the required parameter 'patternWithoutDelimiter' when calling testEndpointParameters");
    }// verify the required parameter '_byte' is set
    if (_byte == null) {
        throw new IllegalArgumentException("Missing the required parameter '_byte' when calling testEndpointParameters");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake");

    // Copy the params argument if present, to allow passing in immutable maps
    Map<String, Object> allParams = params == null ? new HashMap<String, Object>() : new HashMap<String, Object>(params);

    for (Map.Entry<String, Object> entry: allParams.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (key != null && value != null) {
            if (value instanceof Collection) {
                uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
            } else if (value instanceof Object[]) {
                uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
            } else {
                uriBuilder = uriBuilder.queryParam(key, value);
            }
        }
    }

    String localVarUrl = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = new EmptyContent();
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #16
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testBodyWithQueryParamsForHttpResponse(String query, User body) throws IOException {
    // verify the required parameter 'query' is set
    if (query == null) {
        throw new IllegalArgumentException("Missing the required parameter 'query' when calling testBodyWithQueryParams");
    }// verify the required parameter 'body' is set
    if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling testBodyWithQueryParams");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/body-with-query-params");
    if (query != null) {
        String key = "query";
        Object value = query;
        if (value instanceof Collection) {
            uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
        } else if (value instanceof Object[]) {
            uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
        } else {
            uriBuilder = uriBuilder.queryParam(key, value);
        }
    }

    String localVarUrl = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = apiClient.new JacksonJsonHttpContent(body);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #17
Source File: MediaHttpUploaderTest.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
public void testUploadMultipleCalls_WithPatch() throws Exception {
  int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 5;
  MediaTransport fakeTransport = new MediaTransport(contentLength);
  fakeTransport.testMethodOverride = true;
  InputStream is = new ByteArrayInputStream(new byte[contentLength]);
  InputStreamContent mediaContent = new InputStreamContent(TEST_CONTENT_TYPE, is);
  mediaContent.setLength(contentLength);
  MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
  uploader.setInitiationRequestMethod(HttpMethods.PATCH);
  uploader.upload(new GenericUrl(TEST_RESUMABLE_REQUEST_URL));

  // There should be 6 calls made. 1 initiation request and 5 upload requests.
  assertEquals(6, fakeTransport.lowLevelExecCalls);
}
 
Example #18
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testClientModelForHttpResponse(java.io.InputStream body, String mediaType) throws IOException {
    // verify the required parameter 'body' is set
        if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClientModel");
        }
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake");

        String localVarUrl = uriBuilder.build().toString();
        GenericUrl genericUrl = new GenericUrl(localVarUrl);

        HttpContent content = body == null ?
          apiClient.new JacksonJsonHttpContent(null) :
          new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body);
        return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute();
}
 
Example #19
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse updatePetForHttpResponse(java.io.InputStream body, String mediaType) throws IOException {
    // verify the required parameter 'body' is set
        if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling updatePet");
        }
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet");

        String localVarUrl = uriBuilder.build().toString();
        GenericUrl genericUrl = new GenericUrl(localVarUrl);

        HttpContent content = body == null ?
          apiClient.new JacksonJsonHttpContent(null) :
          new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body);
        return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #20
Source File: ProjectApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse deleteTimeEntryForHttpResponse(String accessToken,  String xeroTenantId,  UUID projectId,  UUID timeEntryId) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling deleteTimeEntry");
    }// verify the required parameter 'projectId' is set
    if (projectId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'projectId' when calling deleteTimeEntry");
    }// verify the required parameter 'timeEntryId' is set
    if (timeEntryId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'timeEntryId' when calling deleteTimeEntry");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling deleteTimeEntry");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept(""); 
    headers.setUserAgent(this.getUserAgent()); 
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("projectId", projectId);
    uriVariables.put("timeEntryId", timeEntryId);

    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/projects/{projectId}/time/{timeEntryId}");
    String url = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("DELETE " + genericUrl.toString());
    }
    
    HttpContent content = null;
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.DELETE, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #21
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse createXmlItemForHttpResponse(XmlItem xmlItem) throws IOException {
    // verify the required parameter 'xmlItem' is set
    if (xmlItem == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xmlItem' when calling createXmlItem");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/create_xml_item");

    String localVarUrl = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = apiClient.new JacksonJsonHttpContent(xmlItem);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #22
Source File: BankFeedsApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse createStatementsForHttpResponse(String accessToken,  String xeroTenantId,  Statements statements) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createStatements");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createStatements");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/jsonapplication/problem+json"); 
    headers.setUserAgent(this.getUserAgent());
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Statements");
    String url = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("POST " + genericUrl.toString());
    }
    
    HttpContent content = null;
    content = apiClient.new JacksonJsonHttpContent(statements);
    
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #23
Source File: FakeClassnameTags123Api.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testClassnameForHttpResponse(java.io.InputStream body, String mediaType) throws IOException {
    // verify the required parameter 'body' is set
        if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling testClassname");
        }
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake_classname_test");

        String localVarUrl = uriBuilder.build().toString();
        GenericUrl genericUrl = new GenericUrl(localVarUrl);

        HttpContent content = body == null ?
          apiClient.new JacksonJsonHttpContent(null) :
          new InputStreamContent(mediaType == null ? Json.MEDIA_TYPE : mediaType, body);
        return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute();
}
 
Example #24
Source File: PayrollAuApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse updateLeaveApplicationForHttpResponse(String accessToken,  String xeroTenantId,  UUID leaveApplicationId,  List<LeaveApplication> leaveApplication) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling updateLeaveApplication");
    }// verify the required parameter 'leaveApplicationId' is set
    if (leaveApplicationId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'leaveApplicationId' when calling updateLeaveApplication");
    }// verify the required parameter 'leaveApplication' is set
    if (leaveApplication == null) {
        throw new IllegalArgumentException("Missing the required parameter 'leaveApplication' when calling updateLeaveApplication");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling updateLeaveApplication");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent()); 
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("LeaveApplicationId", leaveApplicationId);

    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/LeaveApplications/{LeaveApplicationId}");
    String url = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("POST " + genericUrl.toString());
    }
    
    HttpContent content = null;
    content = apiClient.new JacksonJsonHttpContent(leaveApplication);
    
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #25
Source File: PayrollAuApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse createPayrollCalendarForHttpResponse(String accessToken,  String xeroTenantId,  List<PayrollCalendar> payrollCalendar) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createPayrollCalendar");
    }// verify the required parameter 'payrollCalendar' is set
    if (payrollCalendar == null) {
        throw new IllegalArgumentException("Missing the required parameter 'payrollCalendar' when calling createPayrollCalendar");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createPayrollCalendar");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent());
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/PayrollCalendars");
    String url = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("POST " + genericUrl.toString());
    }
    
    HttpContent content = null;
    content = apiClient.new JacksonJsonHttpContent(payrollCalendar);
    
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #26
Source File: BankFeedsApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse getFeedConnectionForHttpResponse(String accessToken,  String xeroTenantId,  UUID id) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getFeedConnection");
    }// verify the required parameter 'id' is set
    if (id == null) {
        throw new IllegalArgumentException("Missing the required parameter 'id' when calling getFeedConnection");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getFeedConnection");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent()); 
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("id", id);

    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/FeedConnections/{id}");
    String url = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(url);
    if (logger.isDebugEnabled()) {
        logger.debug("GET " + genericUrl.toString());
    }
    
    HttpContent content = null;
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
    HttpTransport transport = apiClient.getHttpTransport();       
    HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
    return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers)
        .setConnectTimeout(apiClient.getConnectionTimeout())
        .setReadTimeout(apiClient.getReadTimeout()).execute();  
}
 
Example #27
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse uploadFileForHttpResponse(Long petId, Map<String, Object> params) throws IOException {
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'petId' when calling uploadFile");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/{petId}/uploadImage");

    // Copy the params argument if present, to allow passing in immutable maps
    Map<String, Object> allParams = params == null ? new HashMap<String, Object>() : new HashMap<String, Object>(params);

    for (Map.Entry<String, Object> entry: allParams.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (key != null && value != null) {
            if (value instanceof Collection) {
                uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
            } else if (value instanceof Object[]) {
                uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
            } else {
                uriBuilder = uriBuilder.queryParam(key, value);
            }
        }
    }

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = new EmptyContent();
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #28
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse updatePetWithFormForHttpResponse(Long petId, Map<String, Object> params) throws IOException {
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'petId' when calling updatePetWithForm");
    }
    // create a map of path variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/{petId}");

    // Copy the params argument if present, to allow passing in immutable maps
    Map<String, Object> allParams = params == null ? new HashMap<String, Object>() : new HashMap<String, Object>(params);

    for (Map.Entry<String, Object> entry: allParams.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (key != null && value != null) {
            if (value instanceof Collection) {
                uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
            } else if (value instanceof Object[]) {
                uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
            } else {
                uriBuilder = uriBuilder.queryParam(key, value);
            }
        }
    }

    String localVarUrl = uriBuilder.buildFromMap(uriVariables).toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = new EmptyContent();
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #29
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse updatePetForHttpResponse(Pet body, Map<String, Object> params) throws IOException {
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new IllegalArgumentException("Missing the required parameter 'body' when calling updatePet");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet");

    // Copy the params argument if present, to allow passing in immutable maps
    Map<String, Object> allParams = params == null ? new HashMap<String, Object>() : new HashMap<String, Object>(params);

    for (Map.Entry<String, Object> entry: allParams.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (key != null && value != null) {
            if (value instanceof Collection) {
                uriBuilder = uriBuilder.queryParam(key, ((Collection) value).toArray());
            } else if (value instanceof Object[]) {
                uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
            } else {
                uriBuilder = uriBuilder.queryParam(key, value);
            }
        }
    }

    String localVarUrl = uriBuilder.build().toString();
    GenericUrl genericUrl = new GenericUrl(localVarUrl);

    HttpContent content = apiClient.new JacksonJsonHttpContent(body);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PUT, genericUrl, content).execute();
}
 
Example #30
Source File: AbstractGoogleClientRequestTest.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
public void testUserAgentSuffix() throws Exception {
  AssertUserAgentTransport transport = new AssertUserAgentTransport();
  // Specify an Application Name.
  String applicationName = "Test Application";
  transport.expectedUserAgent = applicationName + " "
      + "Google-API-Java-Client/" + GoogleUtils.VERSION + " "
      + HttpRequest.USER_AGENT_SUFFIX;
  MockGoogleClient client = new MockGoogleClient.Builder(
      transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName(
          applicationName).build();
  MockGoogleClientRequest<Void> request =
      new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class);
  request.executeUnparsed();
}