import com.sap.gateway.ip.core.customdev.util.Message
import javax.activation.DataHandler
import javax.mail.internet.ContentType
import javax.mail.internet.MimeBodyPart
import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.SecureStoreService
import com.sap.it.api.securestore.UserCredential
import com.sap.it.api.securestore.exception.SecureStoreException
def Message constructMultipart(Message message) {
byte[] bytes = message.getBody(byte[])
MimeBodyPart bodyPart = new MimeBodyPart()
ByteArrayDataSource dataSource = new ByteArrayDataSource(bytes, 'application/zip')
DataHandler byteDataHandler = new DataHandler(dataSource)
bodyPart.setDataHandler(byteDataHandler)
String fileName = message.getHeaders().get("CamelFileName")
bodyPart.setFileName(fileName)
String fileType = message.getProperties().get("fileType")
bodyPart.setDisposition('form-data; name="file"')
bodyPart.setHeader("Content-Type",fileType)
MimeMultipart multipart = new MimeMultipart()
multipart.addBodyPart(bodyPart)
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
multipart.writeTo(outputStream)
message.setBody(outputStream)
String boundary = (new ContentType(multipart.contentType)).getParameter('boundary')
message.setHeader('Content-Type', "multipart/form-data; boundary=${boundary}")
return message
}
def Message setAuthHeader(Message message) {
def credentialAlias = message.getProperty("credentialAlias")
def secureStorageService = ITApiFactory.getService(SecureStoreService.class, null)
def credential = secureStorageService.getUserCredential(credentialAlias)
def pwd = credential.getPassword()
message.setHeader("Authorization",pwd)
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 |
---|---|
10 | |
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |