Java Reference
In-Depth Information
} catch (IOException ex) {
fail();
ex.printStackTrace();
}
}
// Returns file contents in a byte array.
private static byte[] getFileAsBytes(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get file size
long length = file.length();
if (length > Integer.MAX_VALUE) {
throw new IOException("File is too big to read: " +
file.getName());
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read the bytes in
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset,
bytes.length-offset)) >= 0) {
offset += numRead;
}
// Make sure we read all bytes
if (offset < bytes.length) {
throw new IOException("Could not read file " +
file.getName());
}
is.close();
return bytes;
}
}
As you can see, the hard part is handled by the JAX-WS runtime. All you have to do is read
the image file in from the local filesystem so you can use it as the argument to the operation.
Here is what the SOAP message looks like on the wire:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
Search WWH ::




Custom Search