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


Java MessageContext.addAttachment方法代码示例

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


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

示例1: enableCompression

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private void enableCompression(final IPayload p, final MessageContext mc) {

        // Replace current datahandler of attachment with CompressionDataHandler to facilitate compression
        final String cid = p.getPayloadURI();
        final DataHandler source = mc.getAttachment(cid);
        mc.addAttachment(cid, new CompressionDataHandler(source));
        log.debug("Replaced DataHandler to enable compression");

        // Set the part properties to indicate AS4 Compression feature was used and original MIME Type
        // First ensure that there do not exists properties with this name

        // partProperties should not be null here
        final Collection<IProperty> partProperties = p.getProperties();
        final Collection<IProperty> remove = new ArrayList<>();
        for(final IProperty pp : partProperties)
            if (CompressionFeature.FEATURE_PROPERTY_NAME.equals(pp.getName())
                || CompressionFeature.MIME_TYPE_PROPERTY_NAME.equals(pp.getName()))
                remove.add(pp);
        partProperties.removeAll(remove);

        partProperties.add(new Property(CompressionFeature.FEATURE_PROPERTY_NAME,
                                        CompressionFeature.COMPRESSED_CONTENT_TYPE));
        partProperties.add(new Property(CompressionFeature.MIME_TYPE_PROPERTY_NAME, source.getContentType()));
        log.debug("Set PartProperties to indicate compression");
    }
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:26,代码来源:CompressionHandler.java

示例2: uploadFileUsingSwA

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public OMElement uploadFileUsingSwA(OMElement request) throws Exception {

        String imageContentId = request.
            getFirstChildWithName(new QName("http://services.samples", "request")).
            getFirstChildWithName(new QName("http://services.samples", "imageId")).
            getText();

        MessageContext msgCtx   = MessageContext.getCurrentMessageContext();
        Attachments attachment  = msgCtx.getAttachmentMap();
        DataHandler dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
		fos.flush();
		fos.close();
        System.out.println("Wrote SwA attachment to temp file : " + tempFile.getAbsolutePath());

        MessageContext outMsgCtx = msgCtx.getOperationContext().
            getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        outMsgCtx.setProperty(
            org.apache.axis2.Constants.Configuration.ENABLE_SWA,
            org.apache.axis2.Constants.VALUE_TRUE);

        OMFactory factory = request.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
        OMElement payload  = factory.createOMElement("uploadFileUsingSwAResponse", ns);
        OMElement response = factory.createOMElement("response", ns);
        OMElement imageId  = factory.createOMElement("imageId", ns);

        FileDataSource fileDataSource = new FileDataSource(tempFile);
        dataHandler = new DataHandler(fileDataSource);
        imageContentId = outMsgCtx.addAttachment(dataHandler);
        imageId.setText(imageContentId);
        response.addChild(imageId);
        payload.addChild(response);

        return payload;
    }
 
开发者ID:wso2,项目名称:product-ei,代码行数:39,代码来源:MTOMSwASampleService.java

示例3: testEchoXMLSync

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void testEchoXMLSync() throws Exception {

        Options options = new Options();
        options.setTo(targetEPR);
        options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        options.setTimeOutInMilliSeconds(100000);
        options.setAction(Constants.AXIS2_NAMESPACE_URI + "/" + operationName.getLocalPart());
        options.setTo(targetEPR);

        ConfigurationContext configContext =
                ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                        TestingUtils.prefixBaseDirectory("target/test-resources/integrationRepo"), null);

        ServiceClient sender = new ServiceClient(configContext, null);
        sender.setOptions(options);
        OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

        MessageContext mc = new MessageContext();
        mc.setEnvelope(createEnvelope());
        FileDataSource fileDataSource = new FileDataSource(TestingUtils.prefixBaseDirectory("test-resources/mtom/test.jpg"));
        DataHandler dataHandler = new DataHandler(fileDataSource);
        mc.addAttachment("FirstAttachment", dataHandler);

        mepClient.addMessageContext(mc);
        mepClient.execute(true);
        MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        DataHandler dataHandler2 = response.getAttachment("FirstAttachment");
        assertNotNull(dataHandler);
        compareDataHandlers(dataHandler, dataHandler2);
    }
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:33,代码来源:EchoRawSwATest.java

示例4: sendUsingSwA

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {

        Options options = new Options();
        options.setTo(new EndpointReference(targetEPR));
        options.setAction("urn:uploadFileUsingSwA");
        options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);

        ServiceClient sender = createServiceClient();
        sender.setOptions(options);
        OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

        MessageContext mc = new MessageContext();

        System.out.println("Sending file : " + fileName + " as SwA");
        FileDataSource fileDataSource = new FileDataSource(new File(fileName));
        DataHandler dataHandler = new DataHandler(fileDataSource);
        String attachmentID = mc.addAttachment(dataHandler);


        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope env = factory.getDefaultEnvelope();
        OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
        OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
        OMElement request = factory.createOMElement("request", ns);
        OMElement imageId = factory.createOMElement("imageId", ns);
        imageId.setText(attachmentID);
        request.addChild(imageId);
        payload.addChild(request);
        env.getBody().addChild(payload);
        mc.setEnvelope(env);

        mepClient.addMessageContext(mc);
        mepClient.execute(true);
        MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        SOAPBody body = response.getEnvelope().getBody();
        String imageContentId = body.
                getFirstChildWithName(new QName("http://services.samples", "uploadFileUsingSwAResponse")).
                getFirstChildWithName(new QName("http://services.samples", "response")).
                getFirstChildWithName(new QName("http://services.samples", "imageId")).
                getText();

        Attachments attachment = response.getAttachmentMap();
        dataHandler = attachment.getDataHandler(imageContentId);
        File tempFile = File.createTempFile("swa-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        dataHandler.writeTo(fos);
        fos.flush();
        fos.close();

        System.out.println("Saved response to file : " + tempFile.getAbsolutePath());

        return response;
    }
 
开发者ID:wso2,项目名称:product-ei,代码行数:55,代码来源:MTOMSwAClient.java

示例5: doProcessing

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Override
protected InvocationResponse doProcessing(final MessageContext mc, final IUserMessageEntity um)
                                                                                      throws PersistenceException {
    // Decompression is only needed if the message contains payloads at all
    if (Utils.isNullOrEmpty(um.getPayloads()))
        return InvocationResponse.CONTINUE;

    // The compression feature can be used per payload, so check all payloads in message
    for (final IPayload p : um.getPayloads()) {
        // Only payloads contained in attachment can use compression
        if (p.getContainment() == IPayload.Containment.ATTACHMENT
           && usesCompression(p)) {
            log.debug("Payload uses compression feature, change DataHandler");
            // Replace current datahandler of attachment with CompressionDataHandler to facilitate decompression
            // First get the MIME Type the orginal data is supposed to be in
            String mimeType = null;
            for(final Iterator<IProperty> pps = p.getProperties().iterator()
                    ; pps.hasNext() && mimeType == null;) {
                final IProperty pp = pps.next();
                mimeType = CompressionFeature.MIME_TYPE_PROPERTY_NAME.equals(pp.getName()) ? pp.getValue() : null;
            }
            if (Utils.isNullOrEmpty(mimeType)) {
                log.warn("No source MIME Type specified for compressed payload!");
                // Generate error and stop processing this user messsage
                final DeCompressionFailure decompressFailure = new DeCompressionFailure();
                decompressFailure.setErrorDetail("Missing required MimeType part property for compressed payload ["
                        + p.getPayloadURI() + "]!");
                decompressFailure.setRefToMessageInError(um.getMessageId());
                MessageContextUtils.addGeneratedError(mc, decompressFailure);
                HolodeckB2BCore.getStorageManager().setProcessingState(um, ProcessingState.FAILURE);
            } else {
                // Replace DataHandler to enable decompression
                try {
                    final String cid = p.getPayloadURI();
                    mc.addAttachment(cid, new CompressionDataHandler(mc.getAttachment(cid), mimeType));
                    log.debug("Replaced DataHandler to enable decompression");
                    // Remove part property specific to AS4 Compression feature
                    removeProperty(p);
                } catch (final NullPointerException npe) {
                    /* The NPE is probably caused by a missing attachment
                        => invalid ebMS but this will be detected in the SaveUserMsgAttachment handler.
                           For now we just skip replacing the datahandler
                    */
                }
            }
        }
    }


    return InvocationResponse.CONTINUE;
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:52,代码来源:DecompressionHandler.java

示例6: transferFile

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public static void transferFile(File file, String destinationFile)
		throws Exception {

	Options options = new Options();
	options.setTo(targetEPR);
	options.setProperty(Constants.Configuration.ENABLE_SWA,
			Constants.VALUE_TRUE);
	options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
	// Increase the time out when sending large attachments
	options.setTimeOutInMilliSeconds(10000);
	options.setTo(targetEPR);
	options.setAction("urn:uploadFile");

	// assume the use runs this sample at
	// <axis2home>/samples/soapwithattachments/ dir
	ConfigurationContext configContext = ConfigurationContextFactory
			.createConfigurationContextFromFileSystem("../../repository",
					null);

	ServiceClient sender = new ServiceClient(configContext, null);
	sender.setOptions(options);
	OperationClient mepClient = sender
			.createClient(ServiceClient.ANON_OUT_IN_OP);

	MessageContext mc = new MessageContext();
	FileDataSource fileDataSource = new FileDataSource(file);

	// Create a dataHandler using the fileDataSource. Any implementation of
	// javax.activation.DataSource interface can fit here.
	DataHandler dataHandler = new DataHandler(fileDataSource);
	String attachmentID = mc.addAttachment(dataHandler);

	SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
	SOAPEnvelope env = fac.getDefaultEnvelope();
	OMNamespace omNs = fac.createOMNamespace(
			"http://service.soapwithattachments.sample", "swa");
	OMElement uploadFile = fac.createOMElement("uploadFile", omNs);
	OMElement nameEle = fac.createOMElement("name", omNs);
	nameEle.setText(destinationFile);
	OMElement idEle = fac.createOMElement("attchmentID", omNs);
	idEle.setText(attachmentID);
	uploadFile.addChild(nameEle);
	uploadFile.addChild(idEle);
	env.getBody().addChild(uploadFile);
	mc.setEnvelope(env);

	mepClient.addMessageContext(mc);
	mepClient.execute(true);
	MessageContext response = mepClient
			.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
  	SOAPBody body = response.getEnvelope().getBody();
  	OMElement element = body.getFirstElement().getFirstChildWithName(
  	new QName("http://service.soapwithattachments.sample","return"));
	System.out.println(element.getText());
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:56,代码来源:SWAClient.java


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