cor277 opened a new issue, #3746:
URL: https://github.com/apache/hop/issues/3746
### Apache Hop version?
2.8
### Java version?
openjdk 11.0.22 2024-01-16 LTS
### Operating system
Windows
### What happened?
when you use this plugin, and want to send the a file content (byte, binary)
it convert in string it before work. See the code present in rest.java :
Response response = null;
String entityString = null;
if (data.useBody) {
// Set Http request entity
entityString = Const.NVL(data.inputRowMeta.getString(rowData,
data.indexOfBodyField), null);
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "Rest.Log.BodyValue",
entityString));
}
}
try {
if (data.method.equals(RestMeta.HTTP_METHOD_GET)) {
response = invocationBuilder.get(Response.class);
} else if (data.method.equals(RestMeta.HTTP_METHOD_POST)) {
if (null != contentType) {
response = invocationBuilder.post(Entity.entity(entityString,
contentType));
} else {
response = invocationBuilder.post(Entity.entity(entityString,
data.mediaType));
}
} else if (data.method.equals(RestMeta.HTTP_METHOD_PUT)) {
if (null != contentType) {
response = invocationBuilder.put(Entity.entity(entityString,
contentType));
} else {
response = invocationBuilder.put(Entity.entity(entityString,
data.mediaType));
}
} else if (data.method.equals(RestMeta.HTTP_METHOD_DELETE)) {
response = invocationBuilder.delete();
} else if (data.method.equals(RestMeta.HTTP_METHOD_HEAD)) {
you can see the row : entityString =
Const.NVL(data.inputRowMeta.getString(rowData, data.indexOfBodyField), null);
if you send the content, it encode on UTF8 (default of JVM) and it corrupt
the file.
The solution is to add a flag "send content as binary" and modify the code
likely :
byte[] entityBytes = null;
if (data.useBody) {
entityBytes = ...; // GET DATA AS BYTES
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "Rest.Log.BodyValue",
Arrays.toString(entityBytes)));
}
}
try {
if (data.method.equals(RestMeta.HTTP_METHOD_POST)) {
if (null != contentType) {
response = invocationBuilder.post(Entity.entity(entityBytes,
contentType));
} else {
response = invocationBuilder.post(Entity.entity(entityBytes,
data.mediaType));
}
} else if (data.method.equals(RestMeta.HTTP_METHOD_PUT)) {
if (null != contentType) {
response = invocationBuilder.put(Entity.entity(entityBytes,
contentType));
} else {
response = invocationBuilder.put(Entity.entity(entityBytes,
data.mediaType));
}
}
please correct it.
### Issue Priority
Priority: 1
### Issue Component
Component: Transforms
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]