| Summary | Artix can not return an MTOM binary data document |
|---|---|
| Article Number | 31376 |
| Environment | Product: Artix Version: 5.6 OS: AIX |
| Question/Problem Description | Artix 5.6 run-time returns an empty MIME document for binary documents with MTOM ennoblement. This is confirmed with wire-level traces that reveals Artix fail to attach properly a binary document. |
| Clarifying Information | |
| Error Message | No error message, but the returned MTOM binary document is empty |
| Defect/Enhancement Number | |
| Cause | |
| Resolution | Artix is not attaching binary document as MTOM attachments, because of the way JAVA implements input streams In JAVA, not all input stream classes can be reused to recapture bytes already read. For instance, after reading from a socket input stream which was reading bytes from a server, It is not possible to re-use property the input stream to re-read the data unless that same socket input stream is wrapped in a buffered stream. in JAVA, some input stream classes do support re-reading data, using the InputStream.reset() method. To take advantage of this capability you must be able to call InputStream.mark() to mark the point where you want to start reading bytes from after reset() is called. However, before you call mark() you need to see if the stream even supports the reset() capability by calling InputStream.markSupported(). If this returns false, you cannot use the stream to re-read the data. See InputStream documentation for further details: http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html In order to re-use any Inputstream, the following API can be used: InputStream.markSupported() InputStream.mark() InputStream.reset() An example Artix service implementation method that returns a binary would look similar to the following: public SendBinaryResponse sendBinary(SendBinaryRequest sendBinaryRequest) throws WSException { System.out.println("Executing operation sendBinary"); //printSendBinary(sendBinaryRequest); SendBinaryResponse sendBinaryResponse = new SendBinaryResponse(); String hash=null; try { final InputStream in = sendBinaryRequest.getBodyBinary().getInputStream(); boolean marksupported = in.markSupported(); File pdf = new File("JSR224-server.pdf"); FileOutputStream fos = new FileOutputStream(pdf); System.out.println("MARK_SUPPORTED: " marksupported); if (marksupported) { int readlimit = 1000000; in.mark(readlimit); } ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copyAndCloseInput(in, out); byte[] bytes = out.toByteArray(); System.out.println("The image data size is " out.size()); hash=this.byteArrayHash(bytes); fos.write(bytes); fos.close(); if (marksupported) { in.reset(); sendBinaryResponse.setReturnBinary(sendBinaryRequest.getBodyBinary()); sendBinaryResponse.setReturnBinaryHash(hash); } else { javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(new FileDataSource(pdf)); sendBinaryResponse.setReturnBinary(dataHandler); sendBinaryResponse.setReturnBinaryHash(hash); } } catch (Exception ex) { throw new WSException("sendBinary() operation failed...",ex); } return sendBinaryResponse; } |
| Workaround | |
| Notes | |
| Attachment |
| Created date: | 24 April 2012 |
|---|---|
| Last Modified: | 13 February 2013 |
| Last Published: | 12 May 2012 |
| First Published date: | 24 April 2012 |
#Orbix
#KnowledgeDocs




