use of org.apache.axiom.mime.Part in project webservices-axiom by apache.
the class IncomingAttachmentStreams method getNextStream.
/**
* Returns the next attachment stream in sequence.
*
* @return The next stream or null if no additional streams are left.
*/
public IncomingAttachmentInputStream getNextStream() throws OMException {
if (!readyToGetNextStream) {
throw new IllegalStateException("nextStreamNotReady");
}
Part part = null;
while (part == null && partIterator.hasNext()) {
part = partIterator.next();
// Skip the root part
if (part == rootPart) {
part = null;
}
}
if (part != null) {
IncomingAttachmentInputStream stream = new IncomingAttachmentInputStream(part.getInputStream(false), this);
for (Header header : part.getHeaders()) {
String name = header.getName();
String value = header.getValue();
if (IncomingAttachmentInputStream.HEADER_CONTENT_ID.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_TYPE.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_LOCATION.equals(name)) {
value = value.trim();
}
stream.addHeader(name, value);
}
readyToGetNextStream = false;
return stream;
} else {
return null;
}
}
use of org.apache.axiom.mime.Part in project webservices-axiom by apache.
the class BuilderSpec method from.
static BuilderSpec from(StAXParserConfiguration configuration, final MultipartBody message) {
Part rootPart = message.getRootPart();
InputSource is = new InputSource(rootPart.getInputStream(false));
is.setEncoding(rootPart.getContentType().getParameter("charset"));
BuilderSpec spec = create(configuration, is, false);
return new BuilderSpec(new FilteredXmlInput(spec.getInput(), new XOPDecodingFilter(new OMAttachmentAccessor() {
@Override
public DataHandler getDataHandler(String contentID) {
Part part = message.getPart(contentID);
return part == null ? null : part.getDataHandler();
}
})), new Detachable() {
@Override
public void detach() {
message.detach();
}
});
}
Aggregations