com.sun.xml.internal.ws.api.message.Attachment Java Examples

The following examples show how to use com.sun.xml.internal.ws.api.message.Attachment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerMessageHandlerTube.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
            attSet.add(att);
        }
    }

    try {
        //SERVER-SIDE
        processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

    } catch (WebServiceException wse) {
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        throw re;

    }
}
 
Example #2
Source File: MimeAttachmentSet.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
public Attachment get(String contentId) {
    Attachment att;
    /**
     * First try to get the Attachment from internal map, maybe this attachment
     * is added by the user.
     */
    att = atts.get(contentId);
    if(att != null)
        return att;
    try {
        /**
         * Attachment is not found in the internal map, now do look in
         * the mpp, if found add to the internal Attachment map.
         */
        att = mpp.getAttachmentPart(contentId);
        if(att != null){
            atts.put(contentId, att);
        }
    } catch (IOException e) {
        throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(contentId), e);
    }
    return att;
}
 
Example #3
Source File: MimeAttachmentSet.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
public Attachment get(String contentId) {
    Attachment att;
    /**
     * First try to get the Attachment from internal map, maybe this attachment
     * is added by the user.
     */
    att = atts.get(contentId);
    if(att != null)
        return att;
    try {
        /**
         * Attachment is not found in the internal map, now do look in
         * the mpp, if found add to the internal Attachment map.
         */
        att = mpp.getAttachmentPart(contentId);
        if(att != null){
            atts.put(contentId, att);
        }
    } catch (IOException e) {
        throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(contentId), e);
    }
    return att;
}
 
Example #4
Source File: EndpointArgumentsBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void readRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException {
    boolean foundAttachment = false;
    // TODO not to loop
    for (Attachment att : msg.getAttachments()) {
        String part = getWSDLPartName(att);
        if (part == null) {
            continue;
        }
        if(part.equals(pname) || part.equals(pname1)){
            foundAttachment = true;
            mapAttachment(att, args);
            break;
        }
    }
    if (!foundAttachment) {
        throw new WebServiceException("Missing Attachment for "+pname);
    }
}
 
Example #5
Source File: ServerSOAPHandlerTube.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {

        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = context.packet.getMessage().getAttachments();
        for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
            String cid = entry.getKey();
            if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }

        try {
            //SERVER-SIDE
            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

        } catch (WebServiceException wse) {
            //no rewrapping
            throw wse;
        } catch (RuntimeException re) {
            throw re;

        }
    }
 
Example #6
Source File: ResponseContext.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Object get(Object key) {
    if(packet.supports(key))
        return packet.get(key);    // strongly typed

    if(packet.getHandlerScopePropertyNames(true).contains(key))
        return null;            // no such application-scope property

    Object value =  packet.invocationProperties.get(key);

    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            atts.put(att.getContentId(), att.asDataHandler());
        }
        return atts;
    }
    return value;
}
 
Example #7
Source File: MimeAttachmentSet.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Nullable
public Attachment get(String contentId) {
    Attachment att;
    /**
     * First try to get the Attachment from internal map, maybe this attachment
     * is added by the user.
     */
    att = atts.get(contentId);
    if(att != null)
        return att;
    try {
        /**
         * Attachment is not found in the internal map, now do look in
         * the mpp, if found add to the internal Attachment map.
         */
        att = mpp.getAttachmentPart(contentId);
        if(att != null){
            atts.put(contentId, att);
        }
    } catch (IOException e) {
        throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(contentId), e);
    }
    return att;
}
 
Example #8
Source File: MimeMultipartParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses the entire stream and returns all MIME parts except root MIME part.
 *
 * @return Map<String, StreamAttachment> for all attachment parts
 */
public @NotNull Map<String, Attachment> getAttachmentParts() {
    if (!gotAll) {
        MIMEPart rootPart = (start != null) ? message.getPart(start) : message.getPart(0);
        List<MIMEPart> parts = message.getAttachments();
        for(MIMEPart part : parts) {
            if (part != rootPart) {
                String cid = part.getContentId();
                if (!attachments.containsKey(cid)) {
                    PartAttachment attach = new PartAttachment(part);
                    attachments.put(attach.getContentId(), attach);
                }
            }
        }
        gotAll = true;
    }
    return attachments;
}
 
Example #9
Source File: ServerSOAPHandlerTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {

        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = context.packet.getMessage().getAttachments();
        for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
            String cid = entry.getKey();
            if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }

        try {
            //SERVER-SIDE
            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

        } catch (WebServiceException wse) {
            //no rewrapping
            throw wse;
        } catch (RuntimeException re) {
            throw re;

        }
    }
 
Example #10
Source File: MtomCodec.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("resource")
private void writeNonMtomAttachments(AttachmentSet attachments,
        OutputStream out, String boundary) throws IOException {

    for (Attachment att : attachments) {

        DataHandler dh = att.asDataHandler();
        if (dh instanceof StreamingDataHandler) {
            StreamingDataHandler sdh = (StreamingDataHandler) dh;
            // If DataHandler has href Content-ID, it is MTOM, so skip.
            if (sdh.getHrefCid() != null)
                continue;
        }

        // build attachment frame
        writeln("--" + boundary, out);
        writeMimeHeaders(att.getContentType(), att.getContentId(), out);
        att.writeTo(out);
        writeln(out); // write \r\n
    }
}
 
Example #11
Source File: EndpointMessageContextImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("element-type-mismatch")
public Object get(Object key) {
    if (packet.supports(key)) {
        return packet.get(key);    // strongly typed
    }
    if (packet.getHandlerScopePropertyNames(true).contains(key)) {
        return null;            // no such application-scope property
    }
    Object value =  packet.invocationProperties.get(key);

    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
            key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            atts.put(att.getContentId(), att.asDataHandler());
        }
        return atts;
    }
    return value;
}
 
Example #12
Source File: ServerMessageHandlerTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
            attSet.add(att);
        }
    }

    try {
        //SERVER-SIDE
        processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

    } catch (WebServiceException wse) {
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        throw re;

    }
}
 
Example #13
Source File: ServerSOAPHandlerTube.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {

        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = context.packet.getMessage().getAttachments();
        for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
            String cid = entry.getKey();
            if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }

        try {
            //SERVER-SIDE
            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

        } catch (WebServiceException wse) {
            //no rewrapping
            throw wse;
        } catch (RuntimeException re) {
            throw re;

        }
    }
 
Example #14
Source File: AttachmentSetImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Attachment get(String contentId) {
    for( int i=attList.size()-1; i>=0; i-- ) {
        Attachment a = attList.get(i);
        if(a.getContentId().equals(contentId))
            return a;
    }
    return null;
}
 
Example #15
Source File: AttachmentUnmarshallerImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataHandler getAttachmentAsDataHandler(String cid) {
    Attachment a = attachments.get(stripScheme(cid));
    if(a==null)
        throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(cid));
    return a.asDataHandler();
}
 
Example #16
Source File: DispatchImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected AttachmentSet setOutboundAttachments() {
    HashMap<String, DataHandler> attachments = (HashMap<String, DataHandler>)
            getRequestContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);

    if (attachments != null) {
        List<Attachment> alist = new ArrayList();
        for (Map.Entry<String, DataHandler> att : attachments.entrySet()) {
            DataHandlerAttachment dha = new DataHandlerAttachment(att.getKey(), att.getValue());
            alist.add(dha);
        }
        return new AttachmentSetImpl(alist);
    }
    return new AttachmentSetImpl();
}
 
Example #17
Source File: MtomCodec.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Attachment getAttachment(String cid) throws IOException {
    if (cid.startsWith("cid:"))
        cid = cid.substring(4, cid.length());
    if (cid.indexOf('%') != -1) {
        cid = decodeCid(cid);
        return mimeMP.getAttachmentPart(cid);
    }
    return mimeMP.getAttachmentPart(cid);
}
 
Example #18
Source File: MessageFiller.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void fillIn(Object[] methodArgs, Object returnValue, Message msg) {
    String contentId = getContentId();
    Object obj = (methodPos == -1) ? returnValue : getter.get(methodArgs[methodPos]);
    DataHandler dh = (obj instanceof DataHandler) ? (DataHandler)obj : new DataHandler(obj,mimeType);
    Attachment att = new DataHandlerAttachment(contentId, dh);
    msg.getAttachments().add(att);
}
 
Example #19
Source File: MessageFiller.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void fillIn(Object[] methodArgs, Object returnValue, Message msg) {
    String contentId = getContentId();
    Object obj = (methodPos == -1) ? returnValue : getter.get(methodArgs[methodPos]);
    if (obj != null) {
        Attachment att = new ByteArrayAttachment(contentId,(byte[])obj,mimeType);
        msg.getAttachments().add(att);
    }
}
 
Example #20
Source File: MessageFiller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void fillIn(Object[] methodArgs, Message msg) {
    String contentId = getContentId();
    Object obj = getter.get(methodArgs[methodPos]);
    DataHandler dh = (obj instanceof DataHandler) ? (DataHandler)obj : new DataHandler(obj,mimeType);
    Attachment att = new DataHandlerAttachment(contentId, dh);
    msg.getAttachments().add(att);
}
 
Example #21
Source File: AttachmentMarshallerImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler data) {
    String cid = encodeCid(null);
    Attachment att = new DataHandlerAttachment(cid, data);
    attachments.add(att);
    cid = "cid:" + cid;
    return cid;
}
 
Example #22
Source File: MessageContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Object get(Object key) {
    if(key == null)
        return null;
    Object value = asMapIncludingInvocationProperties.get(key);
    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
        key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            String cid = att.getContentId();
            if (cid.indexOf("@jaxws.sun.com") == -1) {
                Object a = atts.get(cid);
                if (a == null) {
                    a = atts.get("<" + cid + ">");
                    if (a == null) atts.put(att.getContentId(), att.asDataHandler());
                }
            } else {
                atts.put(att.getContentId(), att.asDataHandler());
            }
        }
        return atts;
    }
    return value;
}
 
Example #23
Source File: SwACodec.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
    // TODO: handle attachments correctly
    Attachment root = mpp.getRootPart();
    Codec rootCodec = getMimeRootCodec(packet);
    if (rootCodec instanceof RootOnlyCodec) {
        ((RootOnlyCodec)rootCodec).decode(root.asInputStream(),root.getContentType(),packet, new MimeAttachmentSet(mpp));
    } else {
        rootCodec.decode(root.asInputStream(),root.getContentType(),packet);
        Map<String, Attachment> atts = mpp.getAttachmentParts();
        for(Map.Entry<String, Attachment> att : atts.entrySet()) {
            packet.getMessage().getAttachments().add(att.getValue());
        }
    }
}
 
Example #24
Source File: MimeCodec.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeCustomMimeHeaders(Attachment att, OutputStream out) throws IOException {
    if (att instanceof AttachmentEx) {
        Iterator<AttachmentEx.MimeHeader> allMimeHeaders = ((AttachmentEx) att).getMimeHeaders();
        while (allMimeHeaders.hasNext()) {
            AttachmentEx.MimeHeader mh = allMimeHeaders.next();
            String name = mh.getName();

            if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Id".equalsIgnoreCase(name)) {
                writeln(name +": " + mh.getValue(), out);
            }
        }
    }
}
 
Example #25
Source File: ClientMessageHandlerTube.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
    boolean handlerResult;

    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        if (attSet.get(cid) == null) {  // Otherwise we would be adding attachments twice
            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
            attSet.add(att);
        }
    }

    try {
        //CLIENT-SIDE
        handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
    } catch (WebServiceException wse) {
        remedyActionTaken = true;
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        remedyActionTaken = true;

        throw new WebServiceException(re);

    }
    if (!handlerResult) {
        remedyActionTaken = true;
    }
    return handlerResult;
}
 
Example #26
Source File: AttachmentMarshallerImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String addSwaRefAttachment(DataHandler data) {
    String cid = encodeCid(null);
    Attachment att = new DataHandlerAttachment(cid, data);
    attachments.add(att);
    cid = "cid:" + cid;
    return cid;
}
 
Example #27
Source File: MessageContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Object get(Object key) {
    if(key == null)
        return null;
    Object value = asMapIncludingInvocationProperties.get(key);
    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
        key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            String cid = att.getContentId();
            if (cid.indexOf("@jaxws.sun.com") == -1) {
                Object a = atts.get(cid);
                if (a == null) {
                    a = atts.get("<" + cid + ">");
                    if (a == null) atts.put(att.getContentId(), att.asDataHandler());
                }
            } else {
                atts.put(att.getContentId(), att.asDataHandler());
            }
        }
        return atts;
    }
    return value;
}
 
Example #28
Source File: EndpointArgumentsBuilder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
void mapAttachment(Attachment att, Object[] args) {
    att.getContentType();
    StringDataContentHandler sdh = new StringDataContentHandler();
    try {
        String str = (String)sdh.getContent(new DataHandlerDataSource(att.asDataHandler()));
        setter.put(str, args);
    } catch(Exception e) {
        throw new WebServiceException(e);
    }
}
 
Example #29
Source File: ClientMessageHandlerTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
boolean callHandlersOnRequest(MessageUpdatableContext context, boolean isOneWay) {
    boolean handlerResult;

    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        if (attSet.get(cid) == null) {  // Otherwise we would be adding attachments twice
            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
            attSet.add(att);
        }
    }

    try {
        //CLIENT-SIDE
        handlerResult = processor.callHandlersRequest(HandlerProcessor.Direction.OUTBOUND, context, !isOneWay);
    } catch (WebServiceException wse) {
        remedyActionTaken = true;
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        remedyActionTaken = true;

        throw new WebServiceException(re);

    }
    if (!handlerResult) {
        remedyActionTaken = true;
    }
    return handlerResult;
}
 
Example #30
Source File: MessageFiller.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void fillIn(Object[] methodArgs, Object returnValue, Message msg) {
    String contentId = getContentId();
    Object obj = (methodPos == -1) ? returnValue : getter.get(methodArgs[methodPos]);
    if (obj != null) {
        Attachment att = new ByteArrayAttachment(contentId,(byte[])obj,mimeType);
        msg.getAttachments().add(att);
    }
}