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


Java MessageContext.setAttachmentMap方法代码示例

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


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

示例1: send

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
protected MessageContext send(ClientOptions options, AxisMessage message, QName operationQName,
            boolean block, String resultMessageLabel) throws Exception {
        
        OperationClient mepClient = serviceClient.createClient(operationQName);
        MessageContext mc = new MessageContext();
        mc.setProperty(Constants.Configuration.MESSAGE_TYPE, message.getMessageType());
        mc.setEnvelope(message.getEnvelope());
        Attachments attachments = message.getAttachments();
        if (attachments != null) {
            mc.setAttachmentMap(attachments);
            mc.setDoingSwA(true);
            mc.setProperty(Constants.Configuration.ENABLE_SWA, true);
        }
        for (AxisTestClientConfigurator configurator : configurators) {
            configurator.setupRequestMessageContext(mc);
        }
        mc.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, options.getCharset());
        mc.setServiceContext(serviceClient.getServiceContext());
        if (metrics != null) {
            mc.setProperty(BaseConstants.METRICS_COLLECTOR, metrics);
        }
        mepClient.addMessageContext(mc);
        mepClient.execute(block);
//        mepClient.complete(mc);
        return resultMessageLabel == null ? null : mepClient.getMessageContext(resultMessageLabel);
    }
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:27,代码来源:AxisTestClient.java

示例2: getAttachmentsBuilder

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public static StAXBuilder getAttachmentsBuilder(MessageContext msgContext,
                                                InputStream inStream, String contentTypeString,
                                                boolean isSOAP)
        throws OMException, XMLStreamException, FactoryConfigurationError {
    StAXBuilder builder = null;
    XMLStreamReader streamReader;

    Attachments attachments = createAttachmentsMap(msgContext, inStream, contentTypeString);
    String charSetEncoding = getCharSetEncoding(attachments.getSOAPPartContentType());

    if ((charSetEncoding == null)
        || "null".equalsIgnoreCase(charSetEncoding)) {
        charSetEncoding = MessageContext.UTF_8;
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                           charSetEncoding);

    try {
        PushbackInputStream pis = getPushbackInputStream(attachments.getSOAPPartInputStream());
        String actualCharSetEncoding = getCharSetEncoding(pis, charSetEncoding);

        streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);
    } catch (IOException e) {
        throw new XMLStreamException(e);
    }

    //  Put a reference to Attachments Map in to the message context For
    // backword compatibility with Axis2 1.0 
    msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments);

    // Setting the Attachments map to new SwA API
    msgContext.setAttachmentMap(attachments);

    String soapEnvelopeNamespaceURI = getEnvelopeNamespace(contentTypeString);
   
    return MessageProcessorSelector.getAttachmentBuilder(msgContext, attachments, streamReader, soapEnvelopeNamespaceURI, isSOAP);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:38,代码来源:BuilderUtil.java

示例3: testDoProcessing

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testDoProcessing() throws Exception {
    MessageMetaData mmd = TestUtils.getMMD("handlers/full_mmd.xml", this);
    // Creating SOAP envelope
    SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
    // Adding header
    SOAPHeaderBlock headerBlock = Messaging.createElement(env);
    // Adding UserMessage from mmd
    OMElement umElement = UserMessageElement.createElement(headerBlock, mmd);

    MessageContext mc = new MessageContext();
    mc.setFLOW(MessageContext.OUT_FLOW);

    try {
        mc.setEnvelope(env);
    } catch (AxisFault axisFault) {
        fail(axisFault.getMessage());
    }

    PMode pmode = new PMode();

    Leg leg = new Leg();
    // Setting all protocol configurations checked by the tested handler
    Protocol protocolConfig = new Protocol();
    protocolConfig.setAddress("address");
    protocolConfig.setHTTPCompression(true);
    protocolConfig.setChunking(true);
    leg.setProtocol(protocolConfig);
    pmode.addLeg(leg);

    UserMessage userMessage = UserMessageElement.readElement(umElement);

    // Setting attachments
    Attachments attachments = new Attachments();
    Payload payload = new Payload();
    payload.setContainment(IPayload.Containment.ATTACHMENT);
    String payloadPath = "file://./flower.jpg";
    payload.setPayloadURI(payloadPath);
    payload.setContentLocation(baseDir + "/flower.jpg");
    userMessage.addPayload(payload);
    attachments.addDataHandler(payloadPath,
            new DataHandler(new URL(payload.getPayloadURI())));

    mc.setAttachmentMap(attachments);

    String pmodeId =
            userMessage.getCollaborationInfo().getAgreement().getPModeId();
    userMessage.setPModeId(pmodeId);
    pmode.setId(pmodeId);

    core.getPModeSet().add(pmode);

    // Setting input message property
    IUserMessageEntity userMessageEntity =
            core.getStorageManager().storeIncomingMessageUnit(userMessage);
    mc.setProperty(MessageContextProperties.OUT_USER_MESSAGE,
            userMessageEntity);

    try {
        Handler.InvocationResponse invokeResp = handler.invoke(mc);
        assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    verify(mockAppender, atLeastOnce())
            .doAppend(captorLoggingEvent.capture());
    List<LoggingEvent> events = captorLoggingEvent.getAllValues();
    String msg = "HTTP configuration done";
    assertTrue(eventContainsMsg(events, Level.DEBUG, msg));
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:72,代码来源:ConfigureHTTPTransportHandlerTest.java

示例4: testDoProcessing

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testDoProcessing() throws Exception {
    MessageMetaData mmd = TestUtils.getMMD("handlers/full_mmd_att.xml", this);
    // Creating SOAP envelope
    SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
    // Adding header
    SOAPHeaderBlock headerBlock = Messaging.createElement(env);
    // Adding UserMessage from mmd
    OMElement umElement = UserMessageElement.createElement(headerBlock, mmd);

    MessageContext mc = new MessageContext();
    mc.setFLOW(MessageContext.IN_FLOW);

    PMode pmode = new PMode();

    Leg leg = new Leg();

    UserMessageFlow umFlow = new UserMessageFlow();

    PayloadProfile plProfile = new PayloadProfile();
    plProfile.setCompressionType(CompressionFeature.COMPRESSED_CONTENT_TYPE);
    umFlow.setPayloadProfile(plProfile);

    leg.setUserMessageFlow(umFlow);

    pmode.addLeg(leg);

    UserMessage userMessage = UserMessageElement.readElement(umElement);

    Attachments attachments = new Attachments();

    // Programmatically added payload
    Payload payload = new Payload();
    payload.setContainment(IPayload.Containment.ATTACHMENT);
    String payloadURI = "some_URI_02";
    payload.setPayloadURI(payloadURI);
    userMessage.addPayload(payload);

    // todo test IPayload.Containment.BODY

    // Adding data handler for the programmatically added payload
    DataHandler dh = new DataHandler(new URL("file://" + baseDir + "/flower.jpg"));
    attachments.addDataHandler(payloadURI, dh);

    // Adding data handler for the payload loaded described in mmd
    dh = new DataHandler(new URL("file://" + baseDir + "/dandelion.jpg"));
    attachments.addDataHandler("some_URI_01", dh);

    mc.setAttachmentMap(attachments);

    String pmodeId =
            userMessage.getCollaborationInfo().getAgreement().getPModeId();
    // Copy pmodeId of the agreement to the user message
    userMessage.setPModeId(pmodeId);
    pmode.setId(pmodeId);

    core.getPModeSet().add(pmode);

    // Setting input message property
    IUserMessageEntity userMessageEntity =
            core.getStorageManager().storeIncomingMessageUnit(userMessage);
    mc.setProperty(MessageContextProperties.IN_USER_MESSAGE,
            userMessageEntity);

    assertEquals(ProcessingState.RECEIVED,
            userMessageEntity.getCurrentProcessingState().getState());

    try {
        Handler.InvocationResponse invokeResp = handler.invoke(mc);
        assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    assertEquals(ProcessingState.READY_FOR_DELIVERY,
            userMessageEntity.getCurrentProcessingState().getState());
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:78,代码来源:SaveUserMsgAttachmentsTest.java

示例5: testDoProcessing

import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testDoProcessing() throws Exception {
    MessageMetaData mmd = TestUtils.getMMD("compression/full_mmd.xml", this);
    // Creating SOAP envelope
    SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
    // Adding header
    SOAPHeaderBlock headerBlock = Messaging.createElement(env);
    // Adding UserMessage from mmd
    OMElement umElement = UserMessageElement.createElement(headerBlock, mmd);

    MessageContext mc = new MessageContext();
    mc.setFLOW(MessageContext.IN_FLOW);

    PMode pmode = new PMode();

    Leg leg = new Leg();

    UserMessageFlow umFlow = new UserMessageFlow();

    PayloadProfile plProfile = new PayloadProfile();
    plProfile.setCompressionType(CompressionFeature.COMPRESSED_CONTENT_TYPE);
    umFlow.setPayloadProfile(plProfile);

    leg.setUserMessageFlow(umFlow);

    pmode.addLeg(leg);

    UserMessage userMessage = UserMessageElement.readElement(umElement);

    // We need to add payload with containment type "attachment" to user message,
    // because PartInfoElement does not read the "containment" attribute
    // value of the PartInfo tag from file now (23-Feb-2017 T.S.)
    Payload payload = new Payload();
    payload.setContainment(IPayload.Containment.ATTACHMENT);
    ArrayList<IProperty> props = new ArrayList<>();
    Property p = new Property();
    p.setName(CompressionFeature.FEATURE_PROPERTY_NAME);
    p.setValue(CompressionFeature.COMPRESSED_CONTENT_TYPE);
    props.add(p);
    p = new Property();
    p.setName(CompressionFeature.MIME_TYPE_PROPERTY_NAME);
    p.setValue("jpeg");
    props.add(p);
    payload.setProperties(props);
    String payloadPath = "file://./uncompressed.jpg";
    payload.setPayloadURI(payloadPath);
    userMessage.addPayload(payload);

    Attachments attachments = new Attachments();
    attachments.addDataHandler(payloadPath,
            new DataHandler(new URL(payload.getPayloadURI())));
    mc.setAttachmentMap(attachments);

    String pmodeId =
            userMessage.getCollaborationInfo().getAgreement().getPModeId();
    // Copy pmodeId of the agreement to the user message
    userMessage.setPModeId(pmodeId);
    pmode.setId(pmodeId);

    core.getPModeSet().add(pmode);

    // Setting input message property
    IUserMessageEntity userMessageEntity =
            core.getStorageManager().storeIncomingMessageUnit(userMessage);
    mc.setProperty(MessageContextProperties.IN_USER_MESSAGE,
            userMessageEntity);

    try {
        Handler.InvocationResponse invokeResp = handler.invoke(mc);
        assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    verify(mockAppender, atLeastOnce())
            .doAppend(captorLoggingEvent.capture());
    List<LoggingEvent> events = captorLoggingEvent.getAllValues();
    String expLogMsg = "Replaced DataHandler to enable decompression";
    assertTrue(eventContainsMsg(events, Level.DEBUG, expLogMsg));
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:81,代码来源:DecompressionHandlerTest.java


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