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


Java AttachmentPart.setContentId方法代码示例

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


在下文中一共展示了AttachmentPart.setContentId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: serializeRequest

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Override
protected void serializeRequest(ServiceRequest request, SOAPElement soapRequest, SOAPEnvelope envelope) throws SOAPException {
    // Get TestServiceRequest object
    TestServiceRequest testServiceRequest = (TestServiceRequest) request.getRequestData();
    // Add responseBodySize element
    SOAPElement responseBodySize = soapRequest.addChildElement(envelope.createName("responseBodySize"));
    responseBodySize.addTextNode(testServiceRequest.getResponseBodySize());
    // Add responseAttachmentSize element
    SOAPElement responseAttachmentSize = soapRequest.addChildElement(envelope.createName("responseAttachmentSize"));
    responseAttachmentSize.addTextNode(testServiceRequest.getResponseAttachmentSize());
    // Add request payload
    SOAPElement payload = soapRequest.addChildElement(envelope.createName("payload"));
    payload.addTextNode(testServiceRequest.getRequestPayload());
    // Add request attachment
    if (testServiceRequest.getRequestAttachment() != null && !testServiceRequest.getRequestAttachment().isEmpty()) {
        String attachment = "<attachmentData>" + testServiceRequest.getRequestAttachment() + "</attachmentData>";
        AttachmentPart attachPart = request.getSoapMessage().createAttachmentPart(attachment, "text/xml");
        attachPart.setContentId("attachment_id");
        request.getSoapMessage().addAttachmentPart(attachPart);
    }
}
 
开发者ID:petkivim,项目名称:x-road-test-client,代码行数:22,代码来源:TestServiceRequestSerializer.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");

    // 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

示例4: 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

示例5: 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

示例6: getXMLAttachmentResponse

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Get the response for an XML and an Attachment request
 * @param request
 * @param dataElement
 * @return SOAPMessage
 */
private SOAPMessage getXMLAttachmentResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
    SOAPMessage response;
    
    // Additional assertion checks
    assertTrue(countAttachments(request) == 1);
    AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
    StreamSource contentSS = (StreamSource) requestAP.getContent();
    String content = getAsString(contentSS);
    assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));
    
    // Build the Response
    MessageFactory factory = MessageFactory.newInstance();
    String responseXML = responseMsgStart + ATTACHMENT_RETURN + responseMsgEnd;
    response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
    
    // Create and attach the attachment
    AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
    ap.setContentId(ID);
    response.addAttachmentPart(ap);
    
    return response;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:29,代码来源:SoapMessageProvider.java

示例7: getXMLSWARefResponse

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Get the response for an XML and an MTOM Attachment request
 * @param request
 * @param dataElement
 * @return SOAPMessage
 */
private SOAPMessage getXMLSWARefResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
    SOAPMessage response;
    
    // Additional assertion checks
    assertTrue(countAttachments(request) == 1);
    AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
    assertTrue(requestAP.getContentId().equals(ID));
    StreamSource contentSS = (StreamSource) requestAP.getContent();
    String content = getAsString(contentSS);
    assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));
    
    // Build the Response
    MessageFactory factory = MessageFactory.newInstance();
    String responseXML = responseMsgStart + SWAREF_RETURN + responseMsgEnd;
    response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
    
    // Create and attach the attachment
    AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
    ap.setContentId(ID);
    response.addAttachmentPart(ap);
    
    return response;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:30,代码来源:SoapMessageProvider.java

示例8: 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

示例9: 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

示例10: 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

示例11: addOperationSOAPAttachment

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
private void addOperationSOAPAttachment(String operationName,
    SOAPMessage request) {
AttachmentPart opAttachment = request.createAttachmentPart(
	operationName, "text/plain");
// Content id becomes <operation> when it reaches the server
opAttachment.setContentId("operation");

request.addAttachmentPart(opAttachment);
   }
 
开发者ID:asarkar,项目名称:jax-ws,代码行数:10,代码来源:JAXWSProviderDispatchClient.java

示例12: serializeResponse

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    TestServiceResponse serviceResponse = (TestServiceResponse) response.getResponseData();
    // Add "data" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("data"));
    // Add response body to "data" element
    data.addTextNode(serviceResponse.getResponseBody());
    // Add "processingTime" element
    SOAPElement processingTime = soapResponse.addChildElement(envelope.createName("processingTime"));
    // Add processing time
    processingTime.addTextNode(serviceResponse.getProcessingTime());

    // Add attachment
    if (serviceResponse.getResponseAttachment() != null && !serviceResponse.getResponseAttachment().isEmpty()) {
        AttachmentPart attachPart = response.getSoapMessage().createAttachmentPart("<attachment>" + serviceResponse.getResponseAttachment() + "</attachment>", "application/xml");
        attachPart.setContentId("attachment_id");
        response.getSoapMessage().addAttachmentPart(attachPart);
    }
}
 
开发者ID:petkivim,项目名称:x-road-test-service,代码行数:29,代码来源:Endpoint.java

示例13: createAttachmentPart

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Create an SAAJ AttachmentPart from a JAXWS Attachment
 * @param cid String content id
 * @param dh DataHandler
 * @param message SOAPMessage
 * @return AttachmentPart
 */
public static AttachmentPart createAttachmentPart(String cid, DataHandler dh, SOAPMessage message) {
    // Create the Attachment Part
    AttachmentPart ap = message.createAttachmentPart(dh);
    
    // REVIEW
    // Do we need to copy the content type from the datahandler ?
    
    // Preserve the original content id
    ap.setContentId(cid);
    return ap;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:MessageUtils.java

示例14: getXMLMTOMResponse

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Get the response for an XML and an MTOM Attachment request
 * @param request
 * @param dataElement
 * @return SOAPMessage
 */
private SOAPMessage getXMLMTOMResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
    SOAPMessage response;

    System.out.println("Received MTOM Message");
    // Additional assertion checks
    assertTrue(countAttachments(request) == 1);
    AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
    StreamSource contentSS = (StreamSource) requestAP.getContent();
    String content = getAsString(contentSS);
    assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));

    System.out.println("The MTOM Request Message appears correct.");
    
    // Build the Response
    MessageFactory factory = MessageFactory.newInstance();
    String responseXML = responseMsgStart + MTOM_RETURN + responseMsgEnd;
    response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
    
    // Create and attach the attachment
    AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
    ap.setContentId(ID);
    response.addAttachmentPart(ap);

    System.out.println("Returning the Response Message");
    return response;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:33,代码来源:SoapMessageProvider.java

示例15: getXMLMTOMResponse

import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
 * Get the response for an XML and an MTOM Attachment request
 * @param request
 * @param dataElement
 * @return SOAPMessage
 */
private SOAPMessage getXMLMTOMResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
    SOAPMessage response;

    TestLogger.logger.debug("Received MTOM Message");
    // Additional assertion checks
    assertTrue(countAttachments(request) == 1);
    AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
    StreamSource contentSS = (StreamSource) requestAP.getContent();
    String content = getAsString(contentSS);
    assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));

    TestLogger.logger.debug("The MTOM Request Message appears correct.");
    
    // Build the Response
    MessageFactory factory = MessageFactory.newInstance();
    String responseXML = responseMsgStart + MTOM_RETURN + responseMsgEnd;
    response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
    
    // Create and attach the attachment
    AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
    ap.setContentId(ID);
    response.addAttachmentPart(ap);

    TestLogger.logger.debug("Returning the Response Message");
    return response;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:33,代码来源:SoapMessageProvider.java


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