Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/eclipse/dirigible
Browse files Browse the repository at this point in the history
  • Loading branch information
delchev committed Jan 28, 2025
2 parents d87e708 + 70c48cb commit 6ad2c4e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
package org.eclipse.dirigible.components.api.http;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
Expand All @@ -17,25 +26,28 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpTrace;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.eclipse.dirigible.commons.api.helpers.GsonHelper;
import org.eclipse.dirigible.components.api.http.client.*;
import org.eclipse.dirigible.components.api.http.client.HttpClientHeader;
import org.eclipse.dirigible.components.api.http.client.HttpClientParam;
import org.eclipse.dirigible.components.api.http.client.HttpClientProxyUtils;
import org.eclipse.dirigible.components.api.http.client.HttpClientRequestOptions;
import org.eclipse.dirigible.components.api.http.client.HttpClientResponse;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
* Java face for HTTP operations.
*/
Expand Down Expand Up @@ -171,10 +183,10 @@ private static void prepareHeaders(HttpClientRequestOptions httpClientRequestOpt

/** The Constant recognizedTextMimeTypes. */
private static final HashSet<String> recognizedTextMimeTypes = new HashSet<>(Arrays.asList("application/json; charset=utf-8",
"text/json; charset=utf-8", "text/json", "application/CSV", "application/csv", "text/csv", ContentType.TEXT_PLAIN.getMimeType(),
ContentType.TEXT_HTML.getMimeType(), ContentType.TEXT_XML.getMimeType(), ContentType.APPLICATION_JSON.getMimeType(),
ContentType.APPLICATION_ATOM_XML.getMimeType(), ContentType.APPLICATION_XML.getMimeType(),
ContentType.APPLICATION_XHTML_XML.getMimeType()));
"text/json; charset=utf-8", "text/json", "application/CSV", "application/csv", "text/csv", "json",
ContentType.TEXT_PLAIN.getMimeType(), ContentType.TEXT_HTML.getMimeType(), ContentType.TEXT_XML.getMimeType(),
ContentType.APPLICATION_JSON.getMimeType(), ContentType.APPLICATION_ATOM_XML.getMimeType(),
ContentType.APPLICATION_XML.getMimeType(), ContentType.APPLICATION_XHTML_XML.getMimeType()));

/**
* Process http client response.
Expand All @@ -201,6 +213,12 @@ public static HttpClientResponse processHttpClientResponse(CloseableHttpResponse
String processedContentType = ContentType.getOrDefault(entity)
.getMimeType();
boolean isSupportedTextType = recognizedTextMimeTypes.contains(processedContentType);
if (!isSupportedTextType) {
Optional<String> recognizedTextMimeType = recognizedTextMimeTypes.stream()
.filter(e -> processedContentType.contains(e))
.findFirst();
isSupportedTextType = recognizedTextMimeType.isPresent();
}

if (!binary && isSupportedTextType) {
Charset charset = ContentType.getOrDefault(entity)
Expand Down Expand Up @@ -367,9 +385,12 @@ private static final HttpPost createPostTextRequest(String url, HttpClientReques
ContentType contentType = shouldParseContentType ? ContentType.parse(contentTypeString) : ContentType.create(contentTypeString);

EntityBuilder entityBuilder = EntityBuilder.create()
.setText(httpClientRequestOptions.getText())
.setBinary(httpClientRequestOptions.getText()
.getBytes(StandardCharsets.UTF_8))
.setContentType(contentType);

if (httpClientRequestOptions.isCharacterEncodingEnabled()) {
entityBuilder.setContentEncoding(httpClientRequestOptions.getCharacterEncoding());
}
httpPost.setEntity(entityBuilder.build());
return httpPost;
}
Expand Down Expand Up @@ -485,7 +506,8 @@ private static final HttpPut createPutTextRequest(String url, HttpClientRequestO
httpPut.setConfig(config);
prepareHeaders(httpClientRequestOptions, httpPut);
EntityBuilder entityBuilder = EntityBuilder.create()
.setText(httpClientRequestOptions.getText())
.setBinary(httpClientRequestOptions.getText()
.getBytes(StandardCharsets.UTF_8))
.setContentType(ContentType.create(httpClientRequestOptions.getContentType()));
if (httpClientRequestOptions.isCharacterEncodingEnabled()) {
entityBuilder.setContentEncoding(httpClientRequestOptions.getCharacterEncoding());
Expand Down Expand Up @@ -607,7 +629,8 @@ private static final HttpPatch createPatchTextRequest(String url, HttpClientRequ
httpPatch.setConfig(config);
prepareHeaders(httpClientRequestOptions, httpPatch);
EntityBuilder entityBuilder = EntityBuilder.create()
.setText(httpClientRequestOptions.getText())
.setBinary(httpClientRequestOptions.getText()
.getBytes(StandardCharsets.UTF_8))
.setContentType(ContentType.create(httpClientRequestOptions.getContentType()));
if (httpClientRequestOptions.isCharacterEncodingEnabled()) {
entityBuilder.setContentEncoding(httpClientRequestOptions.getCharacterEncoding());
Expand Down
2 changes: 1 addition & 1 deletion components/api/api-qldb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.amazon.ion</groupId>
<artifactId>ion-java</artifactId>
<version>1.11.9</version>
<version>1.11.10</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
Expand Down
2 changes: 1 addition & 1 deletion components/api/api-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3-transfer-manager</artifactId>
<version>2.30.5</version>
<version>2.30.6</version>
</dependency>

<!-- Test -->
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<!-- Spring -->
<spring.boot.version>3.4.2</spring.boot.version>
<spring.admin.version>3.4.1</spring.admin.version>
<springdoc.version>2.8.3</springdoc.version>
<springdoc.version>2.8.4</springdoc.version>

<!-- Webjars -->
<webjars.bootstrap.version>5.3.2</webjars.bootstrap.version>
Expand Down Expand Up @@ -174,7 +174,7 @@

<!-- JDBC -->
<mongodb.version>3.12.14</mongodb.version>
<ngdbc.version>2.23.7</ngdbc.version>
<ngdbc.version>2.23.8</ngdbc.version>
<snowflake.version>3.21.0</snowflake.version>
<mysql.version>8.4.0</mysql.version>

Expand Down

0 comments on commit 6ad2c4e

Please sign in to comment.