About Question enthuware.ocejws.v6.2.140 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

About Question enthuware.ocejws.v6.2.140 :

Post by himaiMinh »

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.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.ocejws.v6.2.140 :

Post by himaiMinh »

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 :

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();
     }
     
}
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.

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.ocejws.v6.2.140 :

Post by fjwalraven »

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest