Java Code Examples for org.apache.http.entity.mime.MultipartEntityBuilder#create()

The following examples show how to use org.apache.http.entity.mime.MultipartEntityBuilder#create() . 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: LineApiImpl.java    From LineAPI4J with MIT License 6 votes vote down vote up
@Override
public void postContent(String url, Map<String, String> data, InputStream is) throws Exception {
  HttpPost httpPost = new HttpPost(url);
  httpPost.addHeader(X_LINE_ACCESS, getAuthToken());
  MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
  for(Map.Entry<String, String> entry : data.entrySet()) {
      entityBuilder.addTextBody(entry.getKey(), entry.getValue(), ContentType.APPLICATION_FORM_URLENCODED);
  }
  // The LINE object storage service doesn't support chunked encoding; therefore,
  // we must be able to specify the "Content-Length" header.
  // It can be achieved by giving Apache library either a byte array or a File object.
  entityBuilder.addBinaryBody("file", IOUtils.toByteArray(is));
  httpPost.setEntity(entityBuilder.build());
  HttpResponse response = httpClient.execute(httpPost);
  int statusCode = response.getStatusLine().getStatusCode();
  if (statusCode != HttpStatus.SC_CREATED) {
    throw new IOException("Fail to send request to URL " + url + ". Status: " + statusCode);
  }
}
 
Example 2
Source File: FileUploadParser.java    From clouddisk with MIT License 6 votes vote down vote up
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
Example 3
Source File: HttpServerTest.java    From msf4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormParamWithMultipart() throws IOException, URISyntaxException {
    HttpURLConnection connection = request("/test/v1/formParam", HttpMethod.POST);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addPart("name", new StringBody("wso2", ContentType.TEXT_PLAIN));
    builder.addPart("age", new StringBody("10", ContentType.TEXT_PLAIN));
    HttpEntity build = builder.build();
    connection.setRequestProperty("Content-Type", build.getContentType().getValue());
    try (OutputStream out = connection.getOutputStream()) {
        build.writeTo(out);
    }

    InputStream inputStream = connection.getInputStream();
    String response = StreamUtil.asString(inputStream);
    IOUtils.closeQuietly(inputStream);
    connection.disconnect();
    assertEquals(response, "wso2:10");
}
 
Example 4
Source File: BasicHttpClient.java    From zerocode with Apache License 2.0 6 votes vote down vote up
/**
    * This is the http request builder for file uploads, using Apache Http Client. In case you want to build
    * or prepare the requests differently, you can override this method.
    *
    * Note-
    * With file uploads you can send more headers too from the testcase to the server, except "Content-Type" because
    * this is reserved for "multipart/form-data" which the client sends to server during the file uploads. You can
    * also send more request-params and "boundary" from the test cases if needed. The boundary defaults to an unique
    * string of local-date-time-stamp if not provided in the request.
    *
    * You can override this method via @UseHttpClient(YourCustomHttpClient.class)
    *
    * @param httpUrl
    * @param methodName
    * @param reqBodyAsString
    * @return
    * @throws IOException
    */
   public RequestBuilder createFileUploadRequestBuilder(String httpUrl, String methodName, String reqBodyAsString) throws IOException {
       Map<String, Object> fileFieldNameValueMap = getFileFieldNameValue(reqBodyAsString);

       List<String> fileFieldsList = (List<String>) fileFieldNameValueMap.get(FILES_FIELD);

       MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();

       /*
 * Allow fileFieldsList to be null.
 * fileFieldsList can be null if multipart/form-data is sent without any files
 * Refer Issue #168 - Raised and fixed by santhoshTpixler
 */
       if(fileFieldsList != null) {
       	buildAllFilesToUpload(fileFieldsList, multipartEntityBuilder);
}

       buildOtherRequestParams(fileFieldNameValueMap, multipartEntityBuilder);

       buildMultiPartBoundary(fileFieldNameValueMap, multipartEntityBuilder);

       return createUploadRequestBuilder(httpUrl, methodName, multipartEntityBuilder);
   }
 
Example 5
Source File: WechatPayUploadHttpPost.java    From wechatpay-apache-httpclient with Apache License 2.0 6 votes vote down vote up
public WechatPayUploadHttpPost build() {
  if (fileName == null || fileSha256 == null || fileInputStream == null) {
    throw new IllegalArgumentException("缺少待上传图片文件信息");
  }

  if (uri == null) {
    throw new IllegalArgumentException("缺少上传图片接口URL");
  }

  String meta = String.format("{\"filename\":\"%s\",\"sha256\":\"%s\"}", fileName, fileSha256);
  WechatPayUploadHttpPost request = new WechatPayUploadHttpPost(uri, meta);

  MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
  entityBuilder.setMode(HttpMultipartMode.RFC6532)
      .addBinaryBody("file", fileInputStream, fileContentType, fileName)
      .addTextBody("meta", meta, org.apache.http.entity.ContentType.APPLICATION_JSON);

  request.setEntity(entityBuilder.build());
  request.addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.toString());

  return request;
}
 
Example 6
Source File: HttpClientPostingLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException {
    final CloseableHttpClient client = HttpClients.createDefault();
    final HttpPost httpPost = new HttpPost(SAMPLE_URL);

    final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addTextBody("username", DEFAULT_USER);
    builder.addTextBody("password", DEFAULT_PASS);
    builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext");
    final HttpEntity multipart = builder.build();

    httpPost.setEntity(multipart);

    final CloseableHttpResponse response = client.execute(httpPost);
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    client.close();
}
 
Example 7
Source File: OTATest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void basicOTAForNonExistingSingleUser() throws Exception {
    HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/[email protected]");
    post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth));

    String fileName = "test.bin";

    InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName);
    ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("upfile", fileBody);
    HttpEntity entity = builder.build();

    post.setEntity(entity);

    try (CloseableHttpResponse response = httpclient.execute(post)) {
        assertEquals(400, response.getStatusLine().getStatusCode());
        String er = TestUtil.consumeText(response);
        assertNotNull(er);
        assertEquals("Requested user not found.", er);
    }
}
 
Example 8
Source File: DefaultAbsSender.java    From TelegramBots with MIT License 5 votes vote down vote up
@Override
public Serializable execute(EditMessageMedia editMessageMedia) throws TelegramApiException {
    assertParamNotNull(editMessageMedia, "editMessageMedia");
    editMessageMedia.validate();
    try {
        String url = getBaseUrl() + EditMessageMedia.PATH;
        HttpPost httppost = configuredHttpPost(url);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setLaxMode();
        builder.setCharset(StandardCharsets.UTF_8);
        if (editMessageMedia.getInlineMessageId() == null) {
            builder.addTextBody(EditMessageMedia.CHATID_FIELD, editMessageMedia.getChatId(), TEXT_PLAIN_CONTENT_TYPE);
            builder.addTextBody(EditMessageMedia.MESSAGEID_FIELD, editMessageMedia.getMessageId().toString(), TEXT_PLAIN_CONTENT_TYPE);

        } else {
            builder.addTextBody(EditMessageMedia.INLINE_MESSAGE_ID_FIELD, editMessageMedia.getInlineMessageId(), TEXT_PLAIN_CONTENT_TYPE);
        }
        if (editMessageMedia.getReplyMarkup() != null) {
            builder.addTextBody(EditMessageMedia.REPLYMARKUP_FIELD, objectMapper.writeValueAsString(editMessageMedia.getReplyMarkup()), TEXT_PLAIN_CONTENT_TYPE);
        }

        addInputData(builder, editMessageMedia.getMedia(), EditMessageMedia.MEDIA_FIELD, true);

        HttpEntity multipart = builder.build();
        httppost.setEntity(multipart);

        return editMessageMedia.deserializeResponse(sendHttpPostRequest(httppost));
    } catch (IOException e) {
        throw new TelegramApiException("Unable to edit message media", e);
    }
}
 
Example 9
Source File: DatasetRestIT.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private HttpEntity createDatasetFormData(String title) throws IOException {
    MultipartEntityBuilder mb = MultipartEntityBuilder.create();
    mb.addTextBody("title", title);
    mb.addTextBody("repositoryId", "system");
    mb.addTextBody("description", "Test");
    mb.addTextBody("keywords", "Test");
    return mb.build();
}
 
Example 10
Source File: RESTRouteBuilderPOSTFileClientTests.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Test
public void stringPOSTResponseWithParameter()
    throws InterruptedException, ExecutionException, IOException {
  File file = new File(getClass().getClassLoader().getResource("payload.xml").getFile());
  HttpPost post =
      new HttpPost("http://" + HOST + ":" + PORT + SERVICE_REST_GET + "/simpleFilePOSTupload");
  HttpClient client = HttpClientBuilder.create().build();

  FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
  StringBody stringBody1 = new StringBody("bar", ContentType.MULTIPART_FORM_DATA);
  StringBody stringBody2 = new StringBody("world", ContentType.MULTIPART_FORM_DATA);
  //
  MultipartEntityBuilder builder = MultipartEntityBuilder.create();
  builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
  builder.addPart("file", fileBody);
  builder.addPart("foo", stringBody1);
  builder.addPart("hello", stringBody2);
  HttpEntity entity = builder.build();
  //
  post.setEntity(entity);
  HttpResponse response = client.execute(post);

  // Use createResponse object to verify upload success
  final String entity1 = convertStreamToString(response.getEntity().getContent());
  System.out.println("-->" + entity1);
  assertTrue(entity1.equals("barworlddfgdfg"));

  testComplete();
}
 
Example 11
Source File: DefaultAbsSender.java    From TelegramBots with MIT License 5 votes vote down vote up
@Override
public Boolean execute(CreateNewStickerSet createNewStickerSet) throws TelegramApiException {
    assertParamNotNull(createNewStickerSet, "createNewStickerSet");
    createNewStickerSet.validate();
    try {
        String url = getBaseUrl() + CreateNewStickerSet.PATH;
        HttpPost httppost = configuredHttpPost(url);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setLaxMode();
        builder.setCharset(StandardCharsets.UTF_8);
        builder.addTextBody(CreateNewStickerSet.USERID_FIELD, createNewStickerSet.getUserId().toString(), TEXT_PLAIN_CONTENT_TYPE);
        builder.addTextBody(CreateNewStickerSet.NAME_FIELD, createNewStickerSet.getName(), TEXT_PLAIN_CONTENT_TYPE);
        builder.addTextBody(CreateNewStickerSet.TITLE_FIELD, createNewStickerSet.getTitle(), TEXT_PLAIN_CONTENT_TYPE);
        builder.addTextBody(CreateNewStickerSet.EMOJIS_FIELD, createNewStickerSet.getEmojis(), TEXT_PLAIN_CONTENT_TYPE);
        builder.addTextBody(CreateNewStickerSet.CONTAINSMASKS_FIELD, createNewStickerSet.getContainsMasks().toString(), TEXT_PLAIN_CONTENT_TYPE);
        if (createNewStickerSet.getPngSticker() != null) {
            addInputFile(builder, createNewStickerSet.getPngSticker(), CreateNewStickerSet.PNGSTICKER_FIELD, true);
        } else {
            addInputFile(builder, createNewStickerSet.getTgsSticker(), CreateNewStickerSet.TGSSTICKER_FIELD, true);
        }

        if (createNewStickerSet.getMaskPosition() != null) {
            builder.addTextBody(CreateNewStickerSet.MASKPOSITION_FIELD, objectMapper.writeValueAsString(createNewStickerSet.getMaskPosition()), TEXT_PLAIN_CONTENT_TYPE);
        }
        HttpEntity multipart = builder.build();
        httppost.setEntity(multipart);

        return createNewStickerSet.deserializeResponse(sendHttpPostRequest(httppost));
    } catch (IOException e) {
        throw new TelegramApiException("Unable to create new sticker set", e);
    }
}
 
Example 12
Source File: HttpMultipartHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static HttpEntity getMultiPartEntity(String fileName, String contentType, InputStream fileStream, Map<String, String> additionalFormFields) throws IOException {

        MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();

        if (additionalFormFields != null && !additionalFormFields.isEmpty()) {
            for (Entry<String, String> field : additionalFormFields.entrySet()) {
                entityBuilder.addTextBody(field.getKey(), field.getValue());
            }
        }

        entityBuilder.addBinaryBody(fileName, IOUtils.toByteArray(fileStream), ContentType.create(contentType), fileName);

        return entityBuilder.build();
    }
 
Example 13
Source File: OTATest.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void basicOTAForSingleUserAndExistingProject() throws Exception {
    HttpPost post = new HttpPost(httpsAdminServerUrl + "/ota/start?user=" + getUserName() + "&project=My%20Dashboard");
    post.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic " + Base64.getEncoder().encodeToString(auth));

    String fileName = "test.bin";

    InputStream binFile = OTATest.class.getResourceAsStream("/static/ota/" + fileName);
    ContentBody fileBody = new InputStreamBody(binFile, ContentType.APPLICATION_OCTET_STREAM, fileName);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
    builder.addPart("upfile", fileBody);
    HttpEntity entity = builder.build();

    post.setEntity(entity);

    String path;
    try (CloseableHttpResponse response = httpclient.execute(post)) {
        assertEquals(200, response.getStatusLine().getStatusCode());
        path = TestUtil.consumeText(response);

        assertNotNull(path);
        assertTrue(path.startsWith("/static"));
        assertTrue(path.endsWith("bin"));
    }

    String responseUrl = "http://127.0.0.1:18080" + path;
    verify(clientPair.hardwareClient.responseMock, after(500).never()).channelRead(any(), eq(internal(7777, "ota " + responseUrl)));

    TestHardClient newHardwareClient = new TestHardClient("localhost", properties.getHttpPort());
    newHardwareClient.start();
    newHardwareClient.login(clientPair.token);
    verify(newHardwareClient.responseMock, timeout(1000)).channelRead(any(), eq(ok(1)));
    newHardwareClient.reset();

    newHardwareClient.send("internal " + b("ver 0.3.1 h-beat 10 buff-in 256 dev Arduino cpu ATmega328P con W5100 build 111"));
    verify(newHardwareClient.responseMock, timeout(500)).channelRead(any(), eq(ok(1)));
    verify(newHardwareClient.responseMock, timeout(500)).channelRead(any(), eq(internal(7777, "ota " + responseUrl)));
}
 
Example 14
Source File: HttpServerTest.java    From msf4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testFormDataParamWithSimpleRequest() throws IOException, URISyntaxException {
    // Send x-form-url-encoded request
    HttpURLConnection connection = request("/test/v1/formDataParam", HttpMethod.POST);
    String rawData = "name=wso2&age=10";
    ByteBuffer encodedData = Charset.defaultCharset().encode(rawData);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    connection.setRequestProperty("Content-Length", String.valueOf(encodedData.array().length));
    try (OutputStream os = connection.getOutputStream()) {
        os.write(Arrays.copyOf(encodedData.array(), encodedData.limit()));
    }

    InputStream inputStream = connection.getInputStream();
    String response = StreamUtil.asString(inputStream);
    IOUtils.closeQuietly(inputStream);
    connection.disconnect();
    assertEquals(response, "wso2:10");

    // Send multipart/form-data request
    connection = request("/test/v1/formDataParam", HttpMethod.POST);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addPart("name", new StringBody("wso2", ContentType.TEXT_PLAIN));
    builder.addPart("age", new StringBody("10", ContentType.TEXT_PLAIN));
    HttpEntity build = builder.build();
    connection.setRequestProperty("Content-Type", build.getContentType().getValue());
    try (OutputStream out = connection.getOutputStream()) {
        build.writeTo(out);
    }

    inputStream = connection.getInputStream();
    response = StreamUtil.asString(inputStream);
    IOUtils.closeQuietly(inputStream);
    connection.disconnect();
    assertEquals(response, "wso2:10");
}
 
Example 15
Source File: HttpMultipartHelper.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public static HttpEntity getMultiPartEntity(String fileName, String contentType, InputStream fileStream, Map<String, String> additionalFormFields) throws IOException {

    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();

    if (additionalFormFields != null && !additionalFormFields.isEmpty()) {
      for (Entry<String, String> field : additionalFormFields.entrySet()) {
        entityBuilder.addTextBody(field.getKey(), field.getValue());
      }
    }

    entityBuilder.addBinaryBody(fileName, IOUtils.toByteArray(fileStream), ContentType.create(contentType), fileName);

    return entityBuilder.build();
  }
 
Example 16
Source File: SlingApi.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 
 * @param alias    * @param aliasTypeHint    * @param davCreateAbsoluteUri    * @param davCreateAbsoluteUriTypeHint 
*/
public void postConfigApacheSlingDavExServlet (String alias, String aliasTypeHint, Boolean davCreateAbsoluteUri, String davCreateAbsoluteUriTypeHint, final Response.Listener<String> responseListener, final Response.ErrorListener errorListener) {
  Object postBody = null;


  // create path and map variables
  String path = "/apps/system/config/org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet".replaceAll("\\{format\\}","json");

  // query params
  List<Pair> queryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> headerParams = new HashMap<String, String>();
  // form params
  Map<String, String> formParams = new HashMap<String, String>();

  queryParams.addAll(ApiInvoker.parameterToPairs("", "alias", alias));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "alias@TypeHint", aliasTypeHint));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "dav.create-absolute-uri", davCreateAbsoluteUri));
  queryParams.addAll(ApiInvoker.parameterToPairs("", "dav.create-absolute-uri@TypeHint", davCreateAbsoluteUriTypeHint));


  String[] contentTypes = {
    
  };
  String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";

  if (contentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    HttpEntity httpEntity = localVarBuilder.build();
    postBody = httpEntity;
  } else {
    // normal form params
        }

  String[] authNames = new String[] { "aemAuth" };

  try {
    apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType, authNames,
      new Response.Listener<String>() {
        @Override
        public void onResponse(String localVarResponse) {
            responseListener.onResponse(localVarResponse);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          errorListener.onErrorResponse(error);
        }
    });
  } catch (ApiException ex) {
    errorListener.onErrorResponse(new VolleyError(ex));
  }
}
 
Example 17
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Returns pet inventories by status
 * Returns a map of status codes to quantities
 * @return Map<String, Integer>
 */
public Map<String, Integer>  getInventory () throws ApiException {
  Object localVarPostBody = null;

  // create path and map variables
  String localVarPath = "/store/inventory".replaceAll("\\{format\\}","json");

  // query params
  List<Pair> localVarQueryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> localVarHeaderParams = new HashMap<String, String>();
  // form params
  Map<String, String> localVarFormParams = new HashMap<String, String>();



  String[] localVarContentTypes = {
    
  };
  String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json";

  if (localVarContentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    localVarPostBody = localVarBuilder.build();
  } else {
    // normal form params
        }

  try {
    String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType);
    if(localVarResponse != null){
      return (Map<String, Integer>) ApiInvoker.deserialize(localVarResponse, "map", Integer.class);
    }
    else {
      return null;
    }
  } catch (ApiException ex) {
    throw ex;
  }
}
 
Example 18
Source File: SlingApi.java    From swagger-aem with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 

*/
public void getTruststoreInfo (final Response.Listener<TruststoreInfo> responseListener, final Response.ErrorListener errorListener) {
  Object postBody = null;


  // create path and map variables
  String path = "/libs/granite/security/truststore.json".replaceAll("\\{format\\}","json");

  // query params
  List<Pair> queryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> headerParams = new HashMap<String, String>();
  // form params
  Map<String, String> formParams = new HashMap<String, String>();



  String[] contentTypes = {
    
  };
  String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";

  if (contentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    HttpEntity httpEntity = localVarBuilder.build();
    postBody = httpEntity;
  } else {
    // normal form params
        }

  String[] authNames = new String[] { "aemAuth" };

  try {
    apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
      new Response.Listener<String>() {
        @Override
        public void onResponse(String localVarResponse) {
          try {
            responseListener.onResponse((TruststoreInfo) ApiInvoker.deserialize(localVarResponse,  "", TruststoreInfo.class));
          } catch (ApiException exception) {
             errorListener.onErrorResponse(new VolleyError(exception));
          }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          errorListener.onErrorResponse(error);
        }
    });
  } catch (ApiException ex) {
    errorListener.onErrorResponse(new VolleyError(ex));
  }
}
 
Example 19
Source File: UserApi.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Updated user
 * This can only be done by the logged in user.
 * @param username name that need to be deleted
 * @param user Updated user object
 * @return void
 */
public void  updateUser (String username, User user) throws ApiException {
  Object localVarPostBody = user;
  // verify the required parameter 'username' is set
  if (username == null) {
     throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser");
  }
  // verify the required parameter 'user' is set
  if (user == null) {
     throw new ApiException(400, "Missing the required parameter 'user' when calling updateUser");
  }

  // create path and map variables
  String localVarPath = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));

  // query params
  List<Pair> localVarQueryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> localVarHeaderParams = new HashMap<String, String>();
  // form params
  Map<String, String> localVarFormParams = new HashMap<String, String>();



  String[] localVarContentTypes = {
    
  };
  String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json";

  if (localVarContentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    localVarPostBody = localVarBuilder.build();
  } else {
    // normal form params
        }

  try {
    String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType);
    if(localVarResponse != null){
      return ;
    }
    else {
      return ;
    }
  } catch (ApiException ex) {
    throw ex;
  }
}
 
Example 20
Source File: UserApi.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Delete user
 * This can only be done by the logged in user.
 * @param username The name that needs to be deleted
 * @return void
 */
public void  deleteUser (String username) throws ApiException {
  Object localVarPostBody = null;
  // verify the required parameter 'username' is set
  if (username == null) {
     throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser");
  }

  // create path and map variables
  String localVarPath = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));

  // query params
  List<Pair> localVarQueryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> localVarHeaderParams = new HashMap<String, String>();
  // form params
  Map<String, String> localVarFormParams = new HashMap<String, String>();



  String[] localVarContentTypes = {
    
  };
  String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json";

  if (localVarContentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    localVarPostBody = localVarBuilder.build();
  } else {
    // normal form params
        }

  try {
    String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "DELETE", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType);
    if(localVarResponse != null){
      return ;
    }
    else {
      return ;
    }
  } catch (ApiException ex) {
    throw ex;
  }
}