on ‎2020 Aug 07 12:14 PM
Hi Experts,
I am unable to post files other than text using message.setBody() in Groovy script.I am reading attachments from SOAP UI using groovy script getAttachments() method. I am unable to post content in setBody method for files other than text(png,pdf etc..)
Please find code here.
Map<String, DataHandler> attachments = message.getAttachments()
Iterator<DataHandler> it = attachments.values().iterator()
Iterator<String> it1 = attachments.keySet().iterator()
List<String> aList = new ArrayList<String>();
for (String x : attachments.keySet())
{
aList.add(x);
}
def bads=new ByteArrayDataSource(attachments.get(aList.get(0)).getInputStream().getBytes(),'image/png')
DataHandler dh = new DataHandler(bads)
message.setBody(dh.getInputStream().getBytes())
message.setHeader("fName",attachments.get(aList.get(0)).getName())
return message
HTTP Receiver Adapter
Error in Monitoring
Regards,
Sachin Belide
Request clarification before answering.
Hi All,
Seems like some changes has been done in standard adapter. Binary data is now sent to Sharepoint API without any error.
Please find the code I have used to read attachment and post binary data using HTTP adapter.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.activation.DataHandler;
def Message processData(Message message) {
def body = message.getBody();
def headers = message.getHeaders();
def value = headers.get("Auth");
message.setHeader("Authorization", "Bearer "+value);
Map<String,DataHandler> att= message.getAttachments();
def val=null;
att.keySet().each{it->
message.setProperty("fName",att.get(it).getName());
val=att.get(it)
}
message.setBody(val.getInputStream().getBytes());
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 14 | |
| 9 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.