mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Merge branch 'feature/outbound-api-use-utf-8' into feature/CE-680-push-tracking-data-to-ship-station
This commit is contained in:
@ -786,7 +786,7 @@ public class BaseAPIActionUtil
|
|||||||
try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build())
|
try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build())
|
||||||
{
|
{
|
||||||
HttpPost request = new HttpPost(fullURL);
|
HttpPost request = new HttpPost(fullURL);
|
||||||
request.setEntity(new StringEntity(postBody));
|
request.setEntity(new StringEntity(postBody, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
if(setCredentialsInHeader)
|
if(setCredentialsInHeader)
|
||||||
{
|
{
|
||||||
@ -914,7 +914,7 @@ public class BaseAPIActionUtil
|
|||||||
body.put(wrapperObjectName, new JSONObject(json));
|
body.put(wrapperObjectName, new JSONObject(json));
|
||||||
json = body.toString();
|
json = body.toString();
|
||||||
}
|
}
|
||||||
return (new StringEntity(json));
|
return (new StringEntity(json, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -943,7 +943,7 @@ public class BaseAPIActionUtil
|
|||||||
body.put(wrapperObjectName, new JSONArray(json));
|
body.put(wrapperObjectName, new JSONArray(json));
|
||||||
json = body.toString();
|
json = body.toString();
|
||||||
}
|
}
|
||||||
return (new StringEntity(json));
|
return (new StringEntity(json, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -63,14 +63,18 @@ import com.kingsrook.qqq.backend.module.api.model.OutboundAPILog;
|
|||||||
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogMetaDataProvider;
|
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogMetaDataProvider;
|
||||||
import com.kingsrook.qqq.backend.module.api.model.metadata.APIBackendMetaData;
|
import com.kingsrook.qqq.backend.module.api.model.metadata.APIBackendMetaData;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -339,10 +343,32 @@ class BaseAPIActionUtilTest extends BaseTest
|
|||||||
mockApiUtilsHelper.enqueueMockResponse("""
|
mockApiUtilsHelper.enqueueMockResponse("""
|
||||||
{"id": 6}
|
{"id": 6}
|
||||||
""");
|
""");
|
||||||
|
mockApiUtilsHelper.withMockRequestAsserter(httpRequestBase ->
|
||||||
|
{
|
||||||
|
HttpEntity entity = ((HttpEntityEnclosingRequestBase) httpRequestBase).getEntity();
|
||||||
|
byte[] bytes = entity.getContent().readAllBytes();
|
||||||
|
String requestBody = new String(bytes, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// default ISO-8559-1: ... a0 ... //
|
||||||
|
// updated UTF-8: ... c2 a0 ... //
|
||||||
|
///////////////////////////////////////
|
||||||
|
byte previousByte = 0;
|
||||||
|
for(byte b : bytes)
|
||||||
|
{
|
||||||
|
if(b == (byte) 0xa0 && previousByte != (byte) 0xc2)
|
||||||
|
{
|
||||||
|
fail("Found byte 0xa0 (without being prefixed by 0xc2) - so this is invalid UTF-8!");
|
||||||
|
}
|
||||||
|
previousByte = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(requestBody).contains("van Houten");
|
||||||
|
});
|
||||||
|
|
||||||
InsertInput insertInput = new InsertInput();
|
InsertInput insertInput = new InsertInput();
|
||||||
insertInput.setTableName(TestUtils.MOCK_TABLE_NAME);
|
insertInput.setTableName(TestUtils.MOCK_TABLE_NAME);
|
||||||
insertInput.setRecords(List.of(new QRecord().withValue("name", "Milhouse")));
|
insertInput.setRecords(List.of(new QRecord().withValue("name", "Milhouse van Houten")));
|
||||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||||
assertEquals(6, insertOutput.getRecords().get(0).getValueInteger("id"));
|
assertEquals(6, insertOutput.getRecords().get(0).getValueInteger("id"));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user