本文整理汇总了Java中org.apache.synapse.MessageContext.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java MessageContext.setProperty方法的具体用法?Java MessageContext.setProperty怎么用?Java MessageContext.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.synapse.MessageContext
的用法示例。
在下文中一共展示了MessageContext.setProperty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
/**
* Throw Synapse Exception for any exception in class mediator
* so that the fault handler will be invoked
*
* @param ERROR_CODE
* @param ERROR_MESSAGE
* @param ERROR_DETAIL
* @param context
*/
public static void handle(String ERROR_CODE, String ERROR_MESSAGE, String ERROR_DETAIL, MessageContext context) {
int array[] = {20, 20, 40};
int total = 0;
try {
for (int i = 5; i >= 0; i--) {
total += array[i];
}
} catch (Exception e) {
context.setProperty(ERROR_CODE, "AB005");
context.setProperty(ERROR_MESSAGE, "Error Message from class CsvValidatorMediator");
context.setProperty(ERROR_DETAIL, "Error Details from class");
String messageContextErrorCode = (String) context.getProperty(ERROR_CODE);
String messageContextErrorMessage = (String) context.getProperty(ERROR_MESSAGE);
String messageContextErrorDetail = (String) context.getProperty(ERROR_DETAIL);
String separator = "?";
String concatenatedMessage = (messageContextErrorCode + separator + messageContextErrorMessage + separator + messageContextErrorDetail);
throw new SynapseException(concatenatedMessage);
}
}
示例2: mediate
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
public boolean mediate(MessageContext msgCtx) {
try {
log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length);
SOAPBody soapBody = msgCtx.getEnvelope().getBody();
OMElement firstElement = soapBody.getFirstElement();
log.debug("First Element : "+firstElement.getLocalName());
log.debug("First Element Text : "+firstElement.getText());
OMText binaryNode =(OMText) firstElement.getFirstOMChild();
log.debug("First Element Node Text : "+binaryNode.getText());
DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler();
InputStream inputStream = dataHandler.getInputStream();
byte[] searchByte = new byte[length];
inputStream.skip(offset - 1);
int readBytes = inputStream.read(searchByte,0,length);
String outString = new String(searchByte,binaryEncoding);
msgCtx.setProperty(variableName,outString);
log.debug("Set property to MsgCtx, "+variableName+" = "+outString);
inputStream.close();
} catch (IOException e) {
log.error("Excepton on mediation : "+e.getMessage());
}
return true;
}
示例3: dispatchMessage
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
/**
* In this method we are dispatching the message to tomcat transport.
*
* @param endpoint Endpoint
* @param uri uri
* @param messageContext message context
* @return boolean
*/
private boolean dispatchMessage(String endpoint, String uri, MessageContext messageContext) {
// Adding preserver Headers
if (passThroughSenderManager != null && passThroughSenderManager.getSharedPassThroughHttpSender() != null) {
try {
passThroughSenderManager.getSharedPassThroughHttpSender().addPreserveHttpHeader(HTTP.USER_AGENT);
// This catch is added when there is no preserve headers in the PassthoughHttpSender.
} catch (ArrayIndexOutOfBoundsException e) {
if (log.isDebugEnabled()) {
log.debug("ArrayIndexOutOfBoundsException exception occurred, when adding preserve headers.");
}
}
}
if (log.isDebugEnabled()) {
log.debug("Dispatching message to " + uri);
}
messageContext.setProperty(MESSAGE_DISPATCHED, "true");
Utils.setIntegratorHeader(messageContext, uri);
setREST_URL_POSTFIX(((Axis2MessageContext) messageContext).getAxis2MessageContext(), uri);
sendMediator.setEndpoint(Utils.createEndpoint(endpoint, messageContext.getEnvironment()));
return sendMediator.mediate(messageContext);
}
示例4: mediate
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
@Override
public boolean mediate(MessageContext messageContext) {
SynapseLog synLog = getLog(messageContext);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : predict mediator");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + messageContext.getEnvelope());
}
}
String prediction = getPredictionFromModel(messageContext);
messageContext.setProperty(resultPropertyName, prediction);
synLog.traceOrDebug("End : predict mediator");
this.isUpdated = false;
return true;
}
示例5: setupLoadBalancerContextProperties
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
/**
* Setup load balancer message context properties to be used by the out block of the main sequence.
* These values will be used to update the Location value in the response header.
*
* @param synCtx
* @param currentMember
*/
private void setupLoadBalancerContextProperties(MessageContext synCtx, org.apache.axis2.clustering.Member currentMember) {
String targetHostname = extractTargetHost(synCtx);
org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
String httpTransportName = "http", httpsTransportName = "https";
String transportId = getTransportId(extractIncomingTransport(synCtx));
if (transportId != null) {
httpsTransportName = httpsTransportName.concat(transportId);
httpTransportName = httpTransportName.concat(transportId);
}
TransportInDescription httpTransportIn = axis2MsgCtx.getConfigurationContext().getAxisConfiguration().getTransportIn(httpTransportName);
TransportInDescription httpsTransportIn = axis2MsgCtx.getConfigurationContext().getAxisConfiguration().getTransportIn(httpsTransportName);
String lbHttpPort = (String) httpTransportIn.getParameter("port").getValue();
String lbHttpsPort = (String) httpsTransportIn.getParameter("port").getValue();
String clusterId = currentMember.getProperties().getProperty(LoadBalancerConstants.CLUSTER_ID);
synCtx.setProperty(LoadBalancerConstants.LB_TARGET_HOSTNAME, targetHostname);
synCtx.setProperty(LoadBalancerConstants.LB_HTTP_PORT, lbHttpPort);
synCtx.setProperty(LoadBalancerConstants.LB_HTTPS_PORT, lbHttpsPort);
synCtx.setProperty(LoadBalancerConstants.CLUSTER_ID, clusterId);
}
示例6: prepareEndPointSequence
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
private void prepareEndPointSequence(MessageContext synCtx, Endpoint endpoint) {
Object o = synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST);
List<Endpoint> endpointList;
if (o instanceof List) {
endpointList = (List<Endpoint>) o;
endpointList.add(this);
} else {
// this is the first endpoint in the hierarchy. so create the queue and
// insert this as the first element.
endpointList = new ArrayList<Endpoint>();
endpointList.add(this);
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpointList);
}
// if the next endpoint is not a session affinity one, endpoint sequence ends
// here. but we have to add the next endpoint to the list.
if (!(endpoint instanceof TenantAwareLoadBalanceEndpoint)) {
endpointList.add(endpoint);
// Clearing out if there any any session information with current message
if (dispatcher.isServerInitiatedSession()) {
dispatcher.removeSessionID(synCtx);
}
}
}
示例7: generateMessage
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
private MessageContext generateMessage(MessageContext msgCtx,OMElement payload,String msisdn) {
try {
msgCtx = build();
org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) msgCtx)
.getAxis2MessageContext();
OMElement payloadOM = AXIOMUtil.stringToOM(XML_PAYLOAD_A);
axis2MsgCtx.getEnvelope().getBody().addChild(payload !=null?payload:payloadOM);
msgCtx.setProperty(XLinkISO8583Constant.MOBILE_CONNECTION_KEY, msisdn ==null ?(UUID
.randomUUID().toString()):msisdn);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return msgCtx;
}
示例8: send
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
@Override
public void send(MessageContext synCtx) {
SessionInformation sessionInformation = null;
org.apache.axis2.clustering.Member currentMember = null;
if (isSessionAffinityBasedLB()) {
// Check existing session information
sessionInformation = (SessionInformation) synCtx.getProperty(
SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
currentMember = (org.apache.axis2.clustering.Member) synCtx.getProperty(
SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
if (sessionInformation == null && currentMember == null) {
sessionInformation = dispatcher.getSession(synCtx);
if (sessionInformation != null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Existing session found: %s for request: %s", sessionInformation.getId(),
synCtx.getMessageID()));
}
currentMember = sessionInformation.getMember();
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
// This is for reliably recovery any session information if while response is getting ,
// session information has been removed by cleaner.
// This will not be a cost as session information is not a heavy data structure
synCtx.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
}
}
}
TenantAwareLoadBalanceFaultHandler faultHandler = new TenantAwareLoadBalanceFaultHandler();
if (sessionInformation != null && currentMember != null) {
// Update axis2 member ports
updateAxis2MemberPorts(synCtx, currentMember);
// Send request to the member with the existing session
sessionInformation.updateExpiryTime();
sendToApplicationMember(synCtx, currentMember, faultHandler, false);
} else {
// No existing session found
// Find next member
org.apache.axis2.clustering.Member axis2Member = findNextMember(synCtx);
if (axis2Member != null) {
// Send request to member
sendToApplicationMember(synCtx, axis2Member, faultHandler, true);
} else {
throwSynapseException(synCtx, 404, "Active application instances not found");
}
}
}
示例9: throwSynapseException
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
private void throwSynapseException(MessageContext synCtx, int errorCode, String errorMessage) {
synCtx.setProperty(SynapseConstants.ERROR_CODE, errorCode);
synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, errorMessage);
throw new SynapseException(errorMessage);
}
示例10: sendToApplicationMember
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
protected void sendToApplicationMember(MessageContext synCtx,
org.apache.axis2.clustering.Member currentMember,
DynamicLoadbalanceFaultHandler faultHandler,
boolean newSession) {
//Rewriting the URL
org.apache.axis2.context.MessageContext axis2MsgCtx =
((Axis2MessageContext) synCtx).getAxis2MessageContext();
//Removing the REST_URL_POSTFIX - this is a hack.
//In this load balance endpoint we create an endpoint per request by setting the complete url as the address.
//If a REST message comes Axis2FlexibleMEPClient append the REST_URL_POSTFIX to the address. Hence endpoint fails
//do send the request. e.g. http://localhost:8080/example/index.html/example/index.html
axis2MsgCtx.removeProperty(NhttpConstants.REST_URL_POSTFIX);
String transport = axis2MsgCtx.getTransportIn().getName();
EndpointReference to = getEndpointReferenceAfterURLRewrite(synCtx, currentMember, transport);
synCtx.setTo(to);
Endpoint endpoint = getEndpoint(to, currentMember, synCtx);
// Push fault handler to manage statistics and fail-over logic
faultHandler.setTo(to);
faultHandler.setCurrentMember(currentMember);
faultHandler.setCurrentEp(endpoint);
synCtx.pushFaultHandler(faultHandler);
synCtx.getEnvelope().build();
if (isSessionAffinityBasedLB()) {
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, getSessionTimeout());
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_DISPATCHER, dispatcher);
if (newSession) {
prepareEndPointSequence(synCtx, endpoint);
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
// we should also indicate that this is the first message in the session. so that
// onFault(...) method can resend only the failed attempts for the first message.
synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_FIRST_MESSAGE_IN_SESSION,
Boolean.TRUE);
}
}
Map<String, String> memberHosts;
if ((memberHosts = (Map<String, String>) currentMember.getProperties().get(HttpSessionDispatcher.HOSTS)) == null) {
currentMember.getProperties().put(HttpSessionDispatcher.HOSTS,
memberHosts = new HashMap<String, String>());
}
memberHosts.put(extractTargetHost(synCtx), "true");
setupTransportHeaders(synCtx);
setupLoadBalancerContextProperties(synCtx, currentMember);
try {
if (log.isDebugEnabled()) {
log.debug(String.format("Sending request %s to endpoint: %s", synCtx.getMessageID(), to.getAddress()));
}
endpoint.send(synCtx);
// Increment in-flight request count
incrementInFlightRequestCount(synCtx);
} catch (Exception e) {
if (e.getMessage().toLowerCase().contains("io reactor shutdown")) {
log.fatal("System cannot continue normal operation. Restarting", e);
System.exit(121); // restart
} else {
throw new SynapseException(e);
}
}
}
示例11: setupAccountInfo
import org.apache.synapse.MessageContext; //导入方法依赖的package包/类
private void setupAccountInfo(MessageContext msgCtx) {
msgCtx.setProperty("cardno", "card123");
msgCtx.setProperty("accountno", "accountno123");
msgCtx.setProperty("pinno", "1234567890123456");
}