本文整理汇总了Java中org.apache.axis2.context.MessageContext.setEnvelope方法的典型用法代码示例。如果您正苦于以下问题:Java MessageContext.setEnvelope方法的具体用法?Java MessageContext.setEnvelope怎么用?Java MessageContext.setEnvelope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.axis2.context.MessageContext
的用法示例。
在下文中一共展示了MessageContext.setEnvelope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doProcessing
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void doProcessing() throws Exception {
// Creating SOAP envelope
SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
// Adding header
SOAPHeaderBlock headerBlock = Messaging.createElement(env);
MessageContext mc = new MessageContext();
try {
mc.setEnvelope(env);
} catch (AxisFault axisFault) {
fail(axisFault.getMessage());
}
assertFalse(headerBlock.isProcessed());
try {
Handler.InvocationResponse invokeResp = handler.invoke(mc);
assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
} catch (Exception e) {
fail(e.getMessage());
}
assertTrue(headerBlock.isProcessed());
}
示例2: getResponse
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private SOAPEnvelope getResponse(SOAPEnvelope inEnvelope) throws AxisFault {
ConfigurationContext confctx = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(TestingUtils.prefixBaseDirectory("target/test-resources/integrationRepo"),
null);
ServiceClient client = new ServiceClient(confctx, null);
Options options = new Options();
client.setOptions(options);
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setExceptionToBeThrownOnSOAPFault(false);
MessageContext msgctx = new MessageContext();
msgctx.setEnvelope(inEnvelope);
OperationClient opClient = client.createClient(ServiceClient.ANON_OUT_IN_OP);
opClient.addMessageContext(msgctx);
opClient.execute(true);
return opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();
}
示例3: invokeBusinessLogic
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
/**
* Invokes the service by calling the script function
*/
public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault {
try {
log.debug("invoking script service");
outMC.setEnvelope(getSOAPFactory(inMC).getDefaultEnvelope());
BSFEngine engine = getBSFEngine(inMC);
OMElementConvertor convertor = (OMElementConvertor) inMC.getServiceContext().getProperty(CONVERTOR_PROP);
Parameter scriptFunctionParam = inMC.getAxisService().getParameter(FUNCTION_ATTR);
String scriptFunction = scriptFunctionParam == null ? DEFAULT_FUNCTION : (String) scriptFunctionParam.getValue();
ScriptMessageContext inScriptMC = new ScriptMessageContext(inMC, convertor);
ScriptMessageContext outScriptMC = new ScriptMessageContext(outMC, convertor);
Object[] args = new Object[] { inScriptMC, outScriptMC };
engine.call(null, scriptFunction, args);
} catch (BSFException e) {
throw AxisFault.makeFault(e);
}
}
示例4: handleResponse
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
/**
* If there is a fault then need to handle that
* @param responseMessageContext responseMessageContext
* @throws AxisFault
*/
protected void handleResponse(MessageContext responseMessageContext) throws AxisFault {
SOAPEnvelope envelope = responseMessageContext.getEnvelope();
if (envelope == null) {
// If request is REST we assume the responseMessageContext is REST, so
// set the variable
InputStream inStream = (InputStream) responseMessageContext.
getProperty(MessageContext.TRANSPORT_IN);
if (inStream != null && checkContentLength(responseMessageContext)) {
envelope = TransportUtils.createSOAPMessage(
responseMessageContext);
responseMessageContext.setEnvelope(envelope);
}
responseMessageContext.setEnvelope(envelope);
}
if (envelope != null) {
if (envelope.hasFault()|| responseMessageContext.isProcessingFault()) {
//receiving a fault
AxisEngine.receive(responseMessageContext);
throw Utils.getInboundFaultFromMessageContext(responseMessageContext);
}
}
}
示例5: createMessageContext
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private MessageContext createMessageContext(OperationContext oc, ConfigurationContext cc,
int flowType) throws Exception {
MessageContext mc = cc.createMessageContext();
mc.setFLOW(flowType);
mc.setTransportIn(transportIn);
mc.setTransportOut(transportOut);
mc.setServerSide(true);
// mc.setProperty(MessageContext.TRANSPORT_OUT, System.out);
SOAPFactory omFac = OMAbstractFactory.getSOAP11Factory();
mc.setEnvelope(omFac.getDefaultEnvelope());
AxisOperation axisOperation = oc.getAxisOperation();
String action = axisOperation.getName().getLocalPart();
mc.setSoapAction(action);
// System.out.flush();
mc.setMessageID(UUIDGenerator.getUUID());
axisOperation.registerOperationContext(mc, oc);
mc.setOperationContext(oc);
ServiceContext sc = oc.getServiceContext();
mc.setServiceContext(sc);
mc.setTo(new EndpointReference("axis2/services/NullService"));
mc.setWSAAction("DummyOp");
AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
mc.setAxisMessage(axisMessage);
return mc;
}
示例6: invokeBusinessLogic
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public void invokeBusinessLogic(MessageContext inMessageContext,
MessageContext outMessageContext) throws AxisFault {
log.debug("Got The message to the MessageReceiver");
String soapNamespace = inMessageContext.getEnvelope().getNamespace().getNamespaceURI();
// creating a soap factory according the the soap namespce uri
SOAPFactory soapFactory = null;
if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)){
soapFactory = OMAbstractFactory.getSOAP11Factory();
} else if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)){
soapFactory = OMAbstractFactory.getSOAP12Factory();
} else {
System.out.println("Unknow soap message");
}
SOAPEnvelope responseEnvelope = soapFactory.getDefaultEnvelope();
// creating a body element
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMNamespace omNamespace = omFactory.createOMNamespace("http://sms.test","ns1");
OMElement omElement = omFactory.createOMElement("Response", omNamespace);
omElement.setText("Sucess");
responseEnvelope.getBody().addChild(omElement);
outMessageContext.setEnvelope(responseEnvelope);
}
示例7: getFaultForTest
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private AxisFault getFaultForTest(String testName, boolean isSOAP11) throws Exception {
String testfile =
"fault-messages/" + (isSOAP11 ? "soap11" : "soap12") + "/" + testName + ".xml";
SOAPEnvelope envelope = TestUtil.getSOAPEnvelope(testfile);
MessageContext msgContext = new MessageContext();
msgContext.setConfigurationContext(
ConfigurationContextFactory.createEmptyConfigurationContext());
msgContext.setEnvelope(envelope);
AddressingInHandler afih = new AddressingInHandler();
afih.invoke(msgContext);
AddressingInFaultHandler aifh = new AddressingInFaultHandler();
aifh.invoke(msgContext);
return (AxisFault)msgContext.getProperty(Constants.INBOUND_FAULT_OVERRIDE);
}
示例8: setUp
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
objectSupplier = new DefaultObjectSupplier();
omFactory = OMAbstractFactory.getSOAP12Factory();
xsiNamespace = omFactory.createOMNamespace(Constants.XSI_NAMESPACE, "xsi");
omElement = omFactory.createOMElement(new QName("hello"));
MessageContext msgContext = new MessageContext();
msgContext.setEnvelope(omFactory.createSOAPEnvelope());
MessageContext.setCurrentMessageContext(msgContext);
}
示例9: createMessageContext
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private MessageContext createMessageContext(String textPayload) throws AxisFault {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
textWrapper.setText(textPayload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
}
示例10: dispatchResponse
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
/**
* Dispatch the message to the target endpoint
*
* @param soapEnvelope Soap Enevlop with message
* @param responseAction WSE action for the response
* @param mc Message Context
* @param isFault Whether a Fault message must be sent
* @throws AxisFault Thrown by the axis2 engine.
*/
private void dispatchResponse(SOAPEnvelope soapEnvelope, String responseAction,
MessageContext mc, boolean isFault) throws AxisFault {
MessageContext rmc = MessageContextBuilder.createOutMessageContext(mc);
rmc.getOperationContext().addMessageContext(rmc);
replicateState(mc);
rmc.setEnvelope(soapEnvelope);
rmc.setWSAAction(responseAction);
rmc.setSoapAction(responseAction);
if (isFault) {
AxisEngine.sendFault(rmc);
} else {
AxisEngine.send(rmc);
}
}
示例11: makeRequest
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
private List<ResponseData> makeRequest(String session, int iterations, long sleepTime, SOAPEnvelope[] envelopes,
ServiceClient client) throws AxisFault {
List<ResponseData> responseList = new ArrayList<ResponseData>();
int i = 0;
int sessionNumber;
String[] cookies = new String[3];
boolean httpSession = session != null && "http".equals(session);
int cookieNumber;
while (i < iterations) {
i++;
if (sleepTime != -1) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException ignored) {
}
}
MessageContext messageContext = new MessageContext();
sessionNumber = getSessionTurn(envelopes.length);
messageContext.setEnvelope(envelopes[sessionNumber]);
cookieNumber = getSessionTurn(cookies.length);
String cookie = cookies[cookieNumber];
if (httpSession) {
setSessionID(messageContext, cookie);
}
try {
OperationClient op = client.createClient(ServiceClient.ANON_OUT_IN_OP);
op.addMessageContext(messageContext);
op.execute(true);
MessageContext responseContext =
op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
String receivedCookie = extractSessionID(responseContext);
String receivedSetCookie = getSetCookieHeader(responseContext);
if (httpSession) {
if (receivedSetCookie != null && !"".equals(receivedSetCookie)) {
cookies[cookieNumber] = receivedCookie;
}
}
SOAPEnvelope responseEnvelope = responseContext.getEnvelope();
OMElement vElement =
responseEnvelope.getBody().getFirstChildWithName(new QName("Value"));
if (log.isDebugEnabled()) {
log.debug(
"Request: " + i + " with Session ID: " + (httpSession ? cookie : sessionNumber) + " ---- " +
"Response : with " + (httpSession && receivedCookie != null ?
(receivedSetCookie != null ? receivedSetCookie : receivedCookie) :
" ") + " " + vElement.getText());
}
responseList
.add(new ResponseData(true, "" + (httpSession ? cookie : sessionNumber), vElement.getText()));
} catch (AxisFault axisFault) {
if (log.isDebugEnabled()) {
log.debug("Request with session id " + (httpSession ? cookie : sessionNumber), axisFault);
}
responseList.add(
new ResponseData(false, "" + (httpSession ? cookie : sessionNumber), axisFault.getMessage()));
}
}
return responseList;
}
示例12: 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;
}
示例13: doProcessing
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Override
protected InvocationResponse doProcessing(final MessageContext mc) throws AxisFault {
SOAPEnvelope env = null;
// SOAP Envelope only needs to be created when Holodeck B2B initiates the exchange
// or when response does not yet contain one
if ((isInFlow(RESPONDER) && (env = mc.getEnvelope()) == null) || isInFlow(INITIATOR)) {
// For request use P-Mode, for response use SOAP version from request
log.debug("Check for SOAP version");
SOAPEnv.SOAPVersion version;
if (isInFlow(INITIATOR)) {
log.debug("Use P-Mode of primary message unit to get SOAP version");
final IMessageUnitEntity primaryMU = MessageContextUtils.getPrimaryMessageUnit(mc);
if (primaryMU == null) {
log.debug("No message unit in this response, no envelope needed");
return InvocationResponse.CONTINUE;
}
final IPMode pmode = HolodeckB2BCoreInterface.getPModeSet().get(primaryMU.getPModeId());
// Currently only One-Way MEPs are supported, so always on first leg
final ILeg leg = pmode.getLeg(primaryMU.getLeg());
version = leg.getProtocol() != null && "1.1".equals(leg.getProtocol().getSOAPVersion()) ?
SOAPEnv.SOAPVersion.SOAP_11 : SOAPEnv.SOAPVersion.SOAP_12;
} else {
log.debug("Get version from request context");
final OperationContext opContext = mc.getOperationContext();
final MessageContext reqMsgContext = opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
version = (reqMsgContext.isSOAP11() ? SOAPEnv.SOAPVersion.SOAP_11 : SOAPEnv.SOAPVersion.SOAP_12);
}
log.debug("Create SOAP " + (version == SOAPEnv.SOAPVersion.SOAP_11 ? "1.1" : "1.2") + " envelope");
env = SOAPEnv.createEnvelope(version);
try {
// Add the new SOAP envelope to the message context and continue processing
mc.setEnvelope(env);
} catch (final AxisFault ex) {
log.fatal("Could not add the SOAP envelope to the message!");
throw new AxisFault("Could not add the SOAP envelope to the message!");
}
log.debug("Added SOAP envelope to message context");
} else {
log.debug("Check that ebMS namespace is declared on the SOAP envelope");
SOAPEnv.declareNamespaces(env);
}
log.debug("Add empty eb3:Messaging element");
final SOAPHeaderBlock messaging = Messaging.createElement(env);
return InvocationResponse.CONTINUE;
}
示例14: testDoProcessing
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
@Test
public void testDoProcessing() throws Exception {
MessageMetaData mmd = TestUtils.getMMD("security/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();
System.out.println("mc: " + mc);
mc.setFLOW(MessageContext.IN_FLOW);
mc.setProperty(SecurityConstants.ADD_SECURITY_HEADERS, Boolean.TRUE);
UserMessage userMessage = UserMessageElement.readElement(umElement);
OperationContext operationContext = mock(OperationContext.class);
when(operationContext
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE))
.thenReturn(mc);
mc.setOperationContext(operationContext);
try {
mc.setEnvelope(env);
} catch (AxisFault axisFault) {
fail(axisFault.getMessage());
}
StorageManager storageManager = core.getStorageManager();
// Setting input message property
IUserMessageEntity userMessageEntity =
storageManager.storeIncomingMessageUnit(userMessage);
mc.setProperty(MessageContextProperties.IN_USER_MESSAGE,
userMessageEntity);
SecurityConstants.WSS_FAILURES part =
SecurityConstants.WSS_FAILURES.DECRYPTION;
String errorMessage = "some error message";
mc.setProperty(SecurityConstants.INVALID_DEFAULT_HEADER,
new KeyValuePair<>(part, errorMessage));
try {
Handler.InvocationResponse invokeResp = handler.invoke(mc);
assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
} catch (Exception e) {
fail(e.getMessage());
}
assertEquals(ProcessingState.FAILURE,
userMessageEntity.getCurrentProcessingState().getState());
}
示例15: processResponse
import org.apache.axis2.context.MessageContext; //导入方法依赖的package包/类
public static void processResponse(Object resObject,
Member[] params,
Object[] outParamValues,
DataType dataType,
AxisService service,
String methodName,
SOAPFactory fac,
String messageNameSpace,
MessageContext outMessage) throws AxisFault {
boolean qualified = service.isElementFormDefault();
OMNamespace ns = fac.createOMNamespace(messageNameSpace, service.getSchemaTargetNamespacePrefix());
OMElement bodyContent = fac.createOMElement(methodName + RESPONSE, ns);
OMElement child;
if (qualified) {
child = fac.createOMElement(RETURN_WRAPPER, ns);
} else {
child = fac.createOMElement(RETURN_WRAPPER, null);
}
bodyContent.addChild(child);
if (dataType!=null
&& !getQualifiedName(dataType).equals(VOID)
&& resObject!=null) {
processResponse(child, bodyContent, resObject, dataType, fac, ns, qualified, service);
} else {
child.addAttribute("nil", "true", fac.createOMNamespace(Constants.URI_2001_SCHEMA_XSI,
Constants.NS_PREFIX_SCHEMA_XSI));
}
Member param;
List outParamList = Arrays.asList(outParamValues);
Iterator paramsIter = outParamList.iterator();
for (int i = 0; i < params.length; i++) {
param = params[i];
if (Member.MODE_INOUT.equals(param.getMode())
|| Member.MODE_OUT.equals(param.getMode())) {
if (qualified) {
child = fac.createOMElement(param.getName(), ns);
} else {
child = fac.createOMElement(param.getName(), null);
}
bodyContent.addChild(child);
processResponse(child, bodyContent, paramsIter.next(), param.getDataType(), fac, ns, qualified, service);
}
}
SOAPEnvelope envelope = fac.getDefaultEnvelope();
envelope.getBody().addChild(bodyContent);
outMessage.setEnvelope(envelope);
}