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

The following examples show how to use com.google.api.client.http.HttpContent. 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: PetApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse findPetsByTagsForHttpResponse(Set<String> tags) throws IOException {
    // verify the required parameter 'tags' is set
    if (tags == null) {
        throw new IllegalArgumentException("Missing the required parameter 'tags' when calling findPetsByTags");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/findByTags");
    if (tags != null) {
        String key = "tags";
        Object value = tags;
        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 = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute();
}
 
Example #2
Source File: GooglePhotosInterface.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
MediaItemSearchResponse listMediaItems(Optional<String> albumId, Optional<String> pageToken)
    throws IOException, InvalidTokenException, PermissionDeniedException {
  Map<String, Object> params = new LinkedHashMap<>();
  params.put(PAGE_SIZE_KEY, String.valueOf(MEDIA_PAGE_SIZE));
  if (albumId.isPresent()) {
    params.put(ALBUM_ID_KEY, albumId.get());
  } else {
    params.put(FILTERS_KEY, ImmutableMap.of(INCLUDE_ARCHIVED_KEY, String.valueOf(true)));
  }
  if (pageToken.isPresent()) {
    params.put(TOKEN_KEY, pageToken.get());
  }
  HttpContent content = new JsonHttpContent(new JacksonFactory(), params);
  return makePostRequest(
      BASE_URL + "mediaItems:search", Optional.empty(), content, MediaItemSearchResponse.class);
}
 
Example #3
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 #4
Source File: MendeleyClient.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * This methods is adds a document that exists in Mendeley to a specific folder
   * via the POST https://api.mendeley.com/folders/{id}/documents endpoint.
   * @param document This methods needs a dkocument to add
   * @param folder_id This passes the folder where to document is added to
   */
  public void addDocumentToFolder(MendeleyDocument document, String folder_id){
  	refreshTokenIfNecessary();
  	
  	HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory();
  	HttpRequest request;
  	HttpRequest patch_request;
  	
  	Gson gson = new GsonBuilder().create();
  	String json_body = "{\"id\": \""+ document.getId() + "\" }";
  	String resource_url = "https://api.mendeley.com/folders/"+ folder_id + "/documents";
  	GenericUrl gen_url = new GenericUrl(resource_url);
  		
try {
	final HttpContent content = new ByteArrayContent("application/json", json_body.getBytes("UTF8") );
	patch_request = requestFactory.buildPostRequest(gen_url, content);
	patch_request.getHeaders().setAuthorization("Bearer " + access_token);
	patch_request.getHeaders().setContentType("application/vnd.mendeley-document.1+json");
	String rawResponse = patch_request.execute().parseAsString();
} catch (IOException e) {
	e.printStackTrace();
}
  }
 
Example #5
Source File: PetApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse uploadFileForHttpResponse(Long petId, String additionalMetadata, File file) 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");

    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 #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: MendeleyClient.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * This methods is used to delete a Mendeley documents via the DELETE https://api.mendeley.com/documents/{id} endpoint. 
   * @param document Pass the document that needs to be deleted from Mendeley
   */
  public void deleteDocument(MendeleyDocument document ){
  	refreshTokenIfNecessary();
  	
  	HttpRequestFactory requestFactory = new ApacheHttpTransport().createRequestFactory();
  	HttpRequest request;
  	HttpRequest delete_request;
  	
  	Gson gson = new GsonBuilder().create();
  	String json_body = gson.toJson(document);
  	String document_id = document.getId();
  	String resource_url = "https://api.mendeley.com/documents/" + document_id;
  	GenericUrl gen_url = new GenericUrl(resource_url);
  	
try {
	final HttpContent content = new ByteArrayContent("application/json", json_body.getBytes("UTF8") );
	delete_request = requestFactory.buildDeleteRequest(gen_url);
	delete_request.getHeaders().setAuthorization("Bearer " + access_token);
	
	delete_request.getHeaders().setContentType("application/vnd.mendeley-document.1+json");
	String rawResponse = delete_request.execute().parseAsString();
} catch (IOException e) {
	e.printStackTrace();
}
  }
 
Example #8
Source File: GoogleVideosInterface.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
MediaItemSearchResponse listVideoItems(Optional<String> pageToken) throws IOException {
  Map<String, Object> params = new LinkedHashMap<>();
  params.put(PAGE_SIZE_KEY, String.valueOf(MEDIA_PAGE_SIZE));

  params.put(
      FILTERS_KEY,
      ImmutableMap.of(
          MEDIA_FILTER_KEY, ImmutableMap.of("mediaTypes", ImmutableList.of("VIDEO"))));

  if (pageToken.isPresent()) {
    params.put(TOKEN_KEY, pageToken.get());
  }
  HttpContent content = new JsonHttpContent(this.jsonFactory, params);
  return makePostRequest(
      BASE_URL + "mediaItems:search", Optional.empty(), content, MediaItemSearchResponse.class);
}
 
Example #9
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public HttpResponse testEndpointParametersForHttpResponse(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, File binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) 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");

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

    HttpContent content = new EmptyContent();
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #10
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 #11
Source File: HttpEventPublisherTest.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
/** Test whether {@link HttpContent} is created from the list of {@link SplunkEvent}s. */
@Test
public void contentTest()
    throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {

  HttpEventPublisher publisher =
      HttpEventPublisher.newBuilder()
          .withUrl("http://example.com")
          .withToken("test-token")
          .withDisableCertificateValidation(false)
          .build();

  String expectedString =
      "{\"time\":12345,\"host\":\"test-host-1\",\"source\":\"test-source-1\","
          + "\"sourcetype\":\"test-source-type-1\",\"index\":\"test-index-1\","
          + "\"event\":\"test-event-1\"}{\"time\":12345,\"host\":\"test-host-2\","
          + "\"source\":\"test-source-2\",\"sourcetype\":\"test-source-type-2\","
          + "\"index\":\"test-index-2\",\"event\":\"test-event-2\"}";

  try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
    HttpContent actualContent = publisher.getContent(SPLUNK_EVENTS);
    actualContent.writeTo(bos);
    String actualString = new String(bos.toByteArray(), StandardCharsets.UTF_8);
    assertThat(actualString, is(equalTo(expectedString)));
  }
}
 
Example #12
Source File: OAuthUtils.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
static String makeRawPostRequest(HttpTransport httpTransport, String url, HttpContent httpContent)
    throws IOException {
  HttpRequestFactory factory = httpTransport.createRequestFactory();
  HttpRequest postRequest = factory.buildPostRequest(new GenericUrl(url), httpContent);
  HttpResponse response = postRequest.execute();
  int statusCode = response.getStatusCode();
  if (statusCode != 200) {
    throw new IOException(
        "Bad status code: " + statusCode + " error: " + response.getStatusMessage());
  }
  return CharStreams
      .toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
}
 
Example #13
Source File: BankFeedsApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse createFeedConnectionsForHttpResponse(String accessToken,  String xeroTenantId,  FeedConnections feedConnections) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createFeedConnections");
    }// verify the required parameter 'feedConnections' is set
    if (feedConnections == null) {
        throw new IllegalArgumentException("Missing the required parameter 'feedConnections' when calling createFeedConnections");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createFeedConnections");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Xero-Tenant-Id", xeroTenantId);
    headers.setAccept("application/json"); 
    headers.setUserAgent(this.getUserAgent());
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/FeedConnections");
    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(feedConnections);
    
    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 #14
Source File: FakeClassnameTags123Api.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testClassnameForHttpResponse(Client body) 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 = apiClient.new JacksonJsonHttpContent(body);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute();
}
 
Example #15
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 #16
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 #17
Source File: GooglePhotosInterface.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
<T> T makePostRequest(
    String url, Optional<Map<String, String>> parameters, HttpContent httpContent, Class<T> clazz)
    throws IOException, InvalidTokenException, PermissionDeniedException {
  // Wait for write permit before making request
  writeRateLimiter.acquire();

  HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
  HttpRequest postRequest =
      requestFactory.buildPostRequest(
          new GenericUrl(url + "?" + generateParamsString(parameters)), httpContent);
  postRequest.setReadTimeout(2 * 60000); // 2 minutes read timeout
  HttpResponse response;

  try {
    response = postRequest.execute();
  } catch (HttpResponseException e) {
    response =
        handleHttpResponseException(
            () ->
                requestFactory.buildPostRequest(
                    new GenericUrl(url + "?" + generateParamsString(parameters)), httpContent),
            e);
  }

  Preconditions.checkState(response.getStatusCode() == 200);
  String result =
      CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
  if (clazz.isAssignableFrom(String.class)) {
    return (T) result;
  } else {
    return objectMapper.readValue(result, clazz);
  }
}
 
Example #18
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse fakeOuterNumberSerializeForHttpResponse(java.io.InputStream body, String mediaType) throws IOException {
    
        UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/number");

        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.POST, genericUrl, content).execute();
}
 
Example #19
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse fakeOuterNumberSerializeForHttpResponse(BigDecimal body, Map<String, Object> params) throws IOException {
    
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/outer/number");

    // 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.POST, genericUrl, content).execute();
}
 
Example #20
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testBodyWithQueryParamsForHttpResponse(String query, java.io.InputStream body, String mediaType) 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 = 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 #21
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse testInlineAdditionalPropertiesForHttpResponse(Map<String, String> param, Map<String, Object> params) throws IOException {
    // verify the required parameter 'param' is set
    if (param == null) {
        throw new IllegalArgumentException("Missing the required parameter 'param' when calling testInlineAdditionalProperties");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/fake/inline-additionalProperties");

    // 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(param);
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.POST, genericUrl, content).execute();
}
 
Example #22
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 #23
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 #24
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 #25
Source File: URLFetchUtils.java    From appengine-gcs-client with Apache License 2.0 5 votes vote down vote up
HTTPRequestInfo(HttpRequest req) {
  method = req.getRequestMethod();
  url = req.getUrl().toURL();
  long myLength;
  HttpContent content = req.getContent();
  try {
    myLength = content == null ? -1 : content.getLength();
  } catch (IOException e) {
    myLength = -1;
  }
  length = myLength;
  h1 = req.getHeaders();
  h2 = null;
}
 
Example #26
Source File: PayrollAuApi.java    From Xero-Java with MIT License 5 votes vote down vote up
public HttpResponse getSuperfundForHttpResponse(String accessToken,  String xeroTenantId,  UUID superFundID) throws IOException {
    // verify the required parameter 'xeroTenantId' is set
    if (xeroTenantId == null) {
        throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getSuperfund");
    }// verify the required parameter 'superFundID' is set
    if (superFundID == null) {
        throw new IllegalArgumentException("Missing the required parameter 'superFundID' when calling getSuperfund");
    }
    if (accessToken == null) {
        throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getSuperfund");
    }
    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("SuperFundID", superFundID);

    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Superfunds/{SuperFundID}");
    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 getPetByIdForHttpResponse(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 getPetById");
    }
    // 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 = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute();
}
 
Example #28
Source File: MediaHttpUploader.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Direct Uploads the media.
 *
 * @param initiationRequestUrl The request URL where the initiation request will be sent
 * @return HTTP response
 */
private HttpResponse directUpload(GenericUrl initiationRequestUrl) throws IOException {
  updateStateAndNotifyListener(UploadState.MEDIA_IN_PROGRESS);

  HttpContent content = mediaContent;
  if (metadata != null) {
    content = new MultipartContent().setContentParts(Arrays.asList(metadata, mediaContent));
    initiationRequestUrl.put("uploadType", "multipart");
  } else {
    initiationRequestUrl.put("uploadType", "media");
  }
  HttpRequest request =
      requestFactory.buildRequest(initiationRequestMethod, initiationRequestUrl, content);
  request.getHeaders().putAll(initiationHeaders);
  // We do not have to do anything special here if media content length is unspecified because
  // direct media upload works even when the media content length == -1.
  HttpResponse response = executeCurrentRequest(request);
  boolean responseProcessed = false;
  try {
    if (isMediaLengthKnown()) {
      totalBytesServerReceived = getMediaContentLength();
    }
    updateStateAndNotifyListener(UploadState.MEDIA_COMPLETE);
    responseProcessed = true;
  } finally {
    if (!responseProcessed) {
      response.disconnect();
    }
  }
  return response;
}
 
Example #29
Source File: PetApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public HttpResponse findPetsByTagsForHttpResponse(Set<String> tags, Map<String, Object> params) throws IOException {
    // verify the required parameter 'tags' is set
    if (tags == null) {
        throw new IllegalArgumentException("Missing the required parameter 'tags' when calling findPetsByTags");
    }
    UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/pet/findByTags");

    // 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);
    // Add the required query param 'tags' to the map of query params
    allParams.put("tags", tags);

    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 = null;
    return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.GET, genericUrl, content).execute();
}
 
Example #30
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();
}