You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hop.apache.org by "cor277 (via GitHub)" <gi...@apache.org> on 2024/03/20 21:02:57 UTC

[I] [Bug]: REST Client, encode in string ALL data (hop)

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: issues-unsubscribe@hop.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: REST Client, encode in string ALL data (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #3746:
URL: https://github.com/apache/hop/issues/3746#issuecomment-2012264507

   This is not a P1 issue, lowering priority to P2.
   It doesn't even sound like a bug but more of a feature request, "add ability to send binary data".
   Using the HTTP Post transform seems like the correct solution as it supports posting files


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: REST Client, encode in string ALL data (hop)

Posted by "cor277 (via GitHub)" <gi...@apache.org>.
cor277 commented on issue #3746:
URL: https://github.com/apache/hop/issues/3746#issuecomment-2013070991

   Hi hansva, nope, is a bug, because I'm able to send a binary hop. It convert in a string... to solve it i worked with a script.. but a component need to work in a correct way.


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: REST Client, encode in string ALL data (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #3746:
URL: https://github.com/apache/hop/issues/3746#issuecomment-5180786479

   .take-issue


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug]: REST Client, encode in string ALL data (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva closed issue #3746: [Bug]: REST Client, encode in string ALL data
URL: https://github.com/apache/hop/issues/3746


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org