AttachmentPart attachment = soapMessage.createAttachment();
DataHandler dh = new FileDataHandler("picture.jpeg");
attachment.setContent(dh,"application/octet-stream");
I think this is the same as setting MTOM enabled, and the size of the attachment is more or less the same as the original data.
About Question enthuware.ocejws.v6.2.140 :
Moderators: Site Manager, fjwalraven
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
Re: About Question enthuware.ocejws.v6.2.140 :
The above code was a draft.
The jpeg image cannot be converted into application/octet-stream in the attachment when I implement it.
Here is what I tried :
Output from NetBean Platform:
number of bytes after the image is created : 682
number of bytes in attachement : 666
line ����
Attaching the image as raw byte in a SOAPMessage's attachment part, the size of the data sent to the server will be more or less the same as the original size of the data.
The jpeg image cannot be converted into application/octet-stream in the attachment when I implement it.
Here is what I tried :
Code: Select all
//This is a standalone program
public class SkiImageClient4 {
public static void main (String... args) throws SOAPException{
SOAPMessage soapmessage= MessageFactory.newInstance().createMessage();
AttachmentPart attachment = soapmessage.createAttachmentPart();
attachment.setContent(createImage1("nordic"), "image/jpeg");
InputStream input = attachment.getRawContent();
byte[] bytes = attachment.getRawContentBytes();
System.out.println("number of bytes in attachement : "+ bytes.length);
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
...
}
// from Java web service up and running chapter 3.
private static Image createImage1(String name){
byte[] bytes = getRawBytes(name);
System.out.println("number of bytes after the image is created : "+ bytes.length);
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Iterator iterators = ImageIO.getImageReadersByFormatName("jpg");
ImageReader iterator = (ImageReader) iterators.next();
try{
ImageInputStream iis = ImageIO.createImageInputStream(in);
iterator.setInput(iis, true);
return iterator.read(0);
}
catch (IOException e){
...
return null;
}
}
private static byte[] getRawBytes(String name){
ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
String cwd = System.getProperty("user.dir");
String sep = System.getProperty("file.separator");
String base_name = cwd + sep + "jpegs"+ sep;
String file_name = base_name + name + ".jpg";
System.out.println(file_name);
FileInputStream in = new FileInputStream(file_name);
byte[] buffer = new byte[2048];
int n = 0;
while ((n=in.read(buffer))!= -1){
System.out.print(" n "+ n);
out.write(buffer, 0,n);
}
in.close();
}
catch (IOException e){ ...}
return out.toByteArray();
}
}
number of bytes after the image is created : 682
number of bytes in attachement : 666
line ����
Attaching the image as raw byte in a SOAPMessage's attachment part, the size of the data sent to the server will be more or less the same as the original size of the data.
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.ocejws.v6.2.140 :
Good catch!
You have got a valid point here. I will come back to this thread with my update (I have to verify where I have used this also in other questions).
Thanks for your feedback!
Regards,
Frits
You have got a valid point here. I will come back to this thread with my update (I have to verify where I have used this also in other questions).
Thanks for your feedback!
Regards,
Frits
Who is online
Users browsing this forum: No registered users and 1 guest