当前位置: 首页>>代码示例>>Java>>正文


Java AttachmentPart.setDataHandler方法代码示例

本文整理汇总了Java中javax.xml.soap.AttachmentPart.setDataHandler方法的典型用法代码示例。如果您正苦于以下问题:Java AttachmentPart.setDataHandler方法的具体用法?Java AttachmentPart.setDataHandler怎么用?Java AttachmentPart.setDataHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.soap.AttachmentPart的用法示例。


在下文中一共展示了AttachmentPart.setDataHandler方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSendMultipartSoapMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testSendMultipartSoapMessage() throws Exception {
   final MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
   final SOAPMessage msg = msgFactory.createMessage();
   final SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(
      new QName("urn:ledegen:soap-attachment:1.0", "echoImage"));
   bodyElement.addTextNode("cid:" + IN_IMG_NAME);

   final AttachmentPart ap = msg.createAttachmentPart();
   ap.setDataHandler(getResource("saaj/jbws3857/" + IN_IMG_NAME));
   ap.setContentId(IN_IMG_NAME);
   msg.addAttachmentPart(ap);

   final SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
   final SOAPConnection connection = conFactory.createConnection();
   final SOAPMessage response = connection.call(msg, new URL("http://" + baseURL.getHost()+ ":" + baseURL.getPort() + "/" + PROJECT_NAME + "/testServlet"));

   final String contentTypeWeHaveSent = getBodyElementTextValue(response);
   assertContentTypeStarts("multipart/related", contentTypeWeHaveSent);
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:22,代码来源:MultipartContentTypeTestCase.java

示例2: sendMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public SOAPMessage sendMessage() throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();

    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");

    // CXF does not set content-type.
    msg.getMimeHeaders().addHeader("Content-Type", "multipart/related; type=\"text/xml\"; start=\"<[email protected]>\"");
    msg.getSOAPPart().setContentId("<[email protected]>");

    AttachmentPart ap = msg.createAttachmentPart();
    ap.setDataHandler(new DataHandler(new StreamDataSource()));
    ap.setContentId("<switchyard.png>");
    msg.addAttachmentPart(ap);

    return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:21,代码来源:SoapAttachmentQuickstartTest.java

示例3: sendMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public SOAPMessage sendMessage() throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();

    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");

    msg.getSOAPPart().setContentId("<[email protected]>");

    AttachmentPart ap = msg.createAttachmentPart();
    ap.setDataHandler(new DataHandler(new StreamDataSource()));
    ap.setContentId("<switchyard.png>");
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    // SWITCHYARD-2818/CXF-6665 - CXF does not set content-type properly.
    String contentType = msg.getMimeHeaders().getHeader("Content-Type")[0];
    contentType += "; start=\"<[email protected]>\"; start-info=\"application/soap+xml\"; action=\"urn:switchyard-quickstart:soap-attachment:1.0:echoImage\"";
    msg.getMimeHeaders().setHeader("Content-Type", contentType);

    return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:25,代码来源:SoapAttachmentQuickstartTest.java

示例4: sendMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public static SOAPMessage sendMessage(String switchyard_web_service) throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();

    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");

    AttachmentPart ap = msg.createAttachmentPart();
    URL imageUrl = Classes.getResource("switchyard.png");
    ap.setDataHandler(new DataHandler(new URLDataSource(imageUrl)));
    ap.setContentId("switchyard.png");
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    // SWITCHYARD-2818/CXF-6665 - CXF does not set content-type properly.
    String contentType = msg.getMimeHeaders().getHeader("Content-Type")[0];
    contentType += "; start=\"<[email protected]>\"; start-info=\"application/soap+xml\"; action=\"urn:switchyard-quickstart:soap-attachment:1.0:echoImage\"";
    msg.getMimeHeaders().setHeader("Content-Type", contentType);

    return connection.call(msg, new URL(switchyard_web_service));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:SoapAttachmentClient.java

示例5: readAsSOAPMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Default implementation that uses {@link #writeTo(ContentHandler, ErrorHandler)}
 */
public SOAPMessage readAsSOAPMessage() throws SOAPException {
    SOAPMessage msg = soapVersion.saajMessageFactory.createMessage();
    SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart());
    try {
        writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER);
    } catch (SAXException e) {
        throw new SOAPException(e);
    }
    for(Attachment att : getAttachments()) {
        AttachmentPart part = msg.createAttachmentPart();
        part.setDataHandler(att.asDataHandler());
        part.setContentId('<'+att.getContentId()+'>');
        msg.addAttachmentPart(part);
    }
    return msg;
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:20,代码来源:AbstractMessageImpl.java

示例6: writeTo

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(asDataHandler());
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:JAXBAttachment.java

示例7: addAttachmentsToSOAPMessage

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
static protected void addAttachmentsToSOAPMessage(SOAPMessage msg, Message message) {
    for(Attachment att : message.getAttachments()) {
        AttachmentPart part = msg.createAttachmentPart();
        part.setDataHandler(att.asDataHandler());

        // Be safe and avoid double angle-brackets.
        String cid = att.getContentId();
        if (cid != null) {
            if (cid.startsWith("<") && cid.endsWith(">"))
                part.setContentId(cid);
            else
                part.setContentId('<' + cid + '>');
        }

        // Add any MIME headers beside Content-ID, which is already
        // accounted for above, and Content-Type, which is provided
        // by the DataHandler above.
        if (att instanceof AttachmentEx) {
            AttachmentEx ax = (AttachmentEx) att;
            Iterator<AttachmentEx.MimeHeader> imh = ax.getMimeHeaders();
            while (imh.hasNext()) {
                AttachmentEx.MimeHeader ame = imh.next();
                if ((!"Content-ID".equals(ame.getName()))
                        && (!"Content-Type".equals(ame.getName())))
                    part.addMimeHeader(ame.getName(), ame.getValue());
            }
        }
        msg.addAttachmentPart(part);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:SAAJFactory.java

示例8: addRequestPayload

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Override
public boolean addRequestPayload(Payload [] payloads){
	if (this.request == null)
		return false;

	for (int i = 0; i < payloads.length; i++){
		if (payloads[i] != null){
			AttachmentPart ap = this.request.createAttachmentPart();
			if (ap != null){
				// Create file datasource.							
				FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
				ap.setDataHandler(new DataHandler(fileDS));
				ap.setContentType(payloads[i].getContentType());
				ap.addMimeHeader("Content-Disposition", "attachment; filename=" + fileDS.getName());
				this.request.addAttachmentPart(ap);
				if (this.log != null){
					this.log.info(fileDS.getName());
					this.log.info("Adding Payload " + i + " " + payloads[i].getFilePath());
				}
			} else{
				if (this.log != null){
					this.log.error("Unable to create attachment part in SOAP request at :" + i);
				}
			}
		}
	}
	this.setRequestDirty(true);
	return true;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:30,代码来源:AS2MessageSender.java

示例9: send

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Send the web service request to Hermes2 requesting for sending  
 * a <code>AS2 message</code> loopback with a set of <code>payloads</code>.
 * 
 * @param payloads
 * 			The payload set acting as the attachment in <code>AS2 Message</code>. 
 * @return 
 * 			A String representing the ID of the message you request to send. 			
 * @throws Exception 			
 * 
 * @see hk.hku.cecid.corvus.test.Payload
 */
public String send(Payload [] payloads) throws Exception {
	// Make a SOAP Connection and SOAP Message.
	SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
	SOAPMessage request = MessageFactory.newInstance().createMessage();
	
	// Populate the SOAP Body by filling the required parameters.
	/* This is the sample WSDL request for the sending AS2 message WS request.
	 *  
	 * <as2_from> as2from </as2_from>
	 * <as2_to> as2to </as2_to>
	 * <type> type </type>  
	 */
	SOAPBody soapBody = request.getSOAPBody();
	soapBody.addChildElement(createElement("as2_from", nsPrefix, nsURI, this.as2From));
	soapBody.addChildElement(createElement("as2_to"	 , nsPrefix, nsURI, this.as2To));
	soapBody.addChildElement(createElement("type"	 , nsPrefix, nsURI, this.type));		
	
	// Add the payloads
	for (int i=0; i < payloads.length; i++) {
		AttachmentPart attachmentPart = request.createAttachmentPart();
		FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
		attachmentPart.setDataHandler(new DataHandler(fileDS));
		attachmentPart.setContentType(payloads[i].getContentType());
		request.addAttachmentPart(attachmentPart);
	}
	
	// Send the request to Hermes and return the message Id to "sender" web services.		
	SOAPMessage response = soapConn.call(request, senderWSURL);
	SOAPBody responseBody = response.getSOAPBody();		
	
	if (!responseBody.hasFault()){
		SOAPElement messageIdElement = getFirstChild(responseBody, "message_id", nsURI);
		return messageIdElement == null ? null : messageIdElement.getValue();
	} else {
		throw new SOAPException(responseBody.getFault().getFaultString());
	}		
}
 
开发者ID:cecid,项目名称:hermes,代码行数:50,代码来源:AS2Sender.java

示例10: writeTo

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(asDataHandler());
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:ByteArrayAttachment.java

示例11: writeTo

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
    AttachmentPart part = saaj.createAttachmentPart();
    part.setDataHandler(dh);
    part.setContentId(contentId);
    saaj.addAttachmentPart(part);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:DataHandlerAttachment.java

示例12: addPayloadContainer

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Add an ebXML message payload container.
 * 
 * @param dataHandler
 *            the <code>DataHandler</code> that generates the payload
 *            content.
 * @param contentId
 *            the contentId of this payload attachment. The contentId must
 *            be unique among all payload attachment.
 * @param description
 *            the description of this payload.
 * @return the <code>PayloadContainer</code> object that is created and
 *         added.
 * @throws SOAPException
 */
public PayloadContainer addPayloadContainer(DataHandler dataHandler,
        String contentId, String description) throws SOAPException {
    if (headerContainer.getStatusRequest() != null) {
        throw new EbxmlValidationException(
                EbxmlValidationException.EBXML_ERROR_INCONSISTENT,
                EbxmlValidationException.SEVERITY_ERROR, "<"
                        + ExtensionElement.NAMESPACE_PREFIX_EB + ":"
                        + StatusRequest.STATUS_REQUEST
                        + "> has already been "
                        + "added which must not exist togther with <"
                        + ExtensionElement.NAMESPACE_PREFIX_EB + ":"
                        + Manifest.MANIFEST
                        + "> referring to added payloads!");
    }

    Manifest manifest = headerContainer.getManifest();
    if (manifest == null) {
        manifest = new Manifest(soapEnvelope);
        headerContainer.addExtensionElement(manifest);
    }
    final Reference reference = manifest.addReference(contentId,
            Reference.HREF_PREFIX + contentId);
    reference.addDescription(description);

    final PayloadContainer payload;
    if (needPatch) {
        payload = new PayloadContainer(dataHandler, "<" + contentId + ">",
                reference);
    } else {
        payload = new PayloadContainer(dataHandler, contentId, reference);
    }
    payloadContainers.add(payload);

    // we now keep the SOAP message object away from attachment to avoid
    // it to load the payload to memory
    AttachmentPart attachment = soapMessage.createAttachmentPart();
    attachment.setContentId(needPatch ? " <" + contentId +
            ">" : contentId);
    attachment.setDataHandler(dataHandler);
    soapMessage.addAttachmentPart(attachment);

    return payload;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:59,代码来源:EbxmlMessage.java

示例13: send

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Send the web service request to Hermes2 requesting for sending  
 * a <code>EbXML message</code> loopback with a set of <code>payloads</code>.
 * 
 * @param payloads
 * 			The payload set acting as the attachment in <code>EbXML Message</code>. 
 * @return 
 * 			A String representing the ID of the message you request to send. 			
 * @throws Exception 			
 * 
 * @see hk.hku.cecid.corvus.test.Payload
 */
public String send(Payload [] payloads) throws Exception {
	// Make a SOAP Connection and SOAP Message.
	SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
	SOAPMessage request = MessageFactory.newInstance().createMessage();
	
	// Populate the SOAP Body by filling the required parameters.
	/* This is the sample WSDL request for the sending EbMS message WS request.
	 *  
	 * <cpaId> ebmscpaid </cpaId>
	 * <service> http://localhost:8080/corvus/httpd/ebms/inbound <service>
	 * <action> action </action>
	 * <convId> convId </convId> 
	 * <fromPartyId> fromPartyId </fromPartyId>
	 * <fromPartyType> fromPartyType </fromPartyType>
	 * <toPartyId> toPartyId </toPartyId> 
	 * <toPartyType> toPartyType </toPartyType> 
	 * <refToMessageId> </refToMessageId>  
	 */
	SOAPBody soapBody = request.getSOAPBody();
	soapBody.addChildElement(createElement("cpaId", nsPrefix, nsURI, cpaId));
	soapBody.addChildElement(createElement("service", nsPrefix, nsURI, service));
	soapBody.addChildElement(createElement("action", nsPrefix, nsURI, action));
	soapBody.addChildElement(createElement("convId", nsPrefix, nsURI, conversationId));
	soapBody.addChildElement(createElement("fromPartyId", nsPrefix, nsURI, fromPartyId));
	soapBody.addChildElement(createElement("fromPartyType", nsPrefix, nsURI, fromPartyType));
	soapBody.addChildElement(createElement("toPartyId", nsPrefix, nsURI, toPartyId));
	soapBody.addChildElement(createElement("toPartyType", nsPrefix, nsURI, toPartyType));
	soapBody.addChildElement(createElement("refToMessageId", nsPrefix, nsURI, refToMessageId));
	
	// Add the payloads
	for (int i=0; i < payloads.length; i++) {
		AttachmentPart attachmentPart = request.createAttachmentPart();
		FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
		attachmentPart.setDataHandler(new DataHandler(fileDS));
		attachmentPart.setContentType(payloads[i].getContentType());
		request.addAttachmentPart(attachmentPart);
	}
	
	// Send the request to Hermes and return the message Id to "sender" web services.		
	SOAPMessage response = soapConn.call(request, senderWSURL);
	SOAPBody responseBody = response.getSOAPBody();		
	
	if (!responseBody.hasFault()){
		SOAPElement messageIdElement = getFirstChild(responseBody, "message_id", nsURI);
		return messageIdElement == null ? null : messageIdElement.getValue();
	} else {
		throw new SOAPException(responseBody.getFault().getFaultString());
	}		
}
 
开发者ID:cecid,项目名称:hermes,代码行数:62,代码来源:EbmsSender.java

示例14: decompose

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public SOAPBindingData decompose(Exchange exchange, SOAPBindingData target) throws Exception {
    final SOAPMessage soapMessage = target.getSOAPMessage();
    final Message message = exchange.getMessage();
    final Boolean input = exchange.getPhase() == null;

    if (message != null) {
        // check to see if the payload is null or it's a full SOAP Message
        if (message.getContent() == null) {
            throw SOAPMessages.MESSAGES.unableToCreateSOAPBodyDueToNullMessageContent();
        }
        if (message.getContent() instanceof SOAPMessage) {
            return new SOAPBindingData((SOAPMessage)message.getContent());
        }
        
        try {
            // convert the message content to a form we can work with
            Node messageNode = message.getContent(Node.class);
            if (messageNode != null) {
                Node messageNodeImport = soapMessage.getSOAPBody().getOwnerDocument().importNode(messageNode, true);
                if (exchange.getState() != ExchangeState.FAULT || isSOAPFaultPayload(messageNode)) {
                    if (_documentStyle) {
                        String opName = exchange.getContract().getProviderOperation().getName();
                        if (_unwrapped) {
                            String ns = getWrapperNamespace(opName, input);
                            // Don't wrap if it's already wrapped
                            if (!messageNodeImport.getLocalName().equals(opName + DOC_LIT_WRAPPED_REPLY_SUFFIX)) {
                                Element wrapper = messageNodeImport.getOwnerDocument().createElementNS(
                                        ns, opName + DOC_LIT_WRAPPED_REPLY_SUFFIX);
                                wrapper.appendChild(messageNodeImport);
                                messageNodeImport = wrapper;
                            }
                        }
                    }
                    soapMessage.getSOAPBody().appendChild(messageNodeImport);
                    // SOAP Attachments
                    for (String name : message.getAttachmentMap().keySet()) {
                        AttachmentPart apResponse = soapMessage.createAttachmentPart();
                        apResponse.setDataHandler(new DataHandler(message.getAttachment(name)));
                        apResponse.setContentId("<" + name + ">");
                        soapMessage.addAttachmentPart(apResponse);
                    }
                } else {
                    // convert to SOAP Fault since ExchangeState is FAULT but the message is not SOAP Fault
                    SOAPUtil.addFault(soapMessage).addDetail().appendChild(messageNodeImport);
                }
            }
        } catch (Exception e) {
            // Account for exception as payload in case of fault
            if (exchange.getState().equals(ExchangeState.FAULT)
                    && exchange.getMessage().getContent() instanceof Exception) {
                // Throw the Exception and let JAX-WS format the fault.
                throw exchange.getMessage().getContent(Exception.class);
            }
            throw SOAPMessages.MESSAGES.unableToParseSOAPMessage(e);
        }
    }
    
    try {
        getContextMapper().mapTo(exchange.getContext(), target);
    } catch (Exception ex) {
        throw SOAPMessages.MESSAGES.failedToMapContextPropertiesToSOAPMessage(ex);
    }

    return target;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:70,代码来源:SOAPMessageComposer.java


注:本文中的javax.xml.soap.AttachmentPart.setDataHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。