本文整理汇总了Java中org.wso2.carbon.messaging.CarbonMessage类的典型用法代码示例。如果您正苦于以下问题:Java CarbonMessage类的具体用法?Java CarbonMessage怎么用?Java CarbonMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CarbonMessage类属于org.wso2.carbon.messaging包,在下文中一共展示了CarbonMessage类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getNextLBOutboundEndpoint
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* @param cMsg Carbon Message has all headers required to make decision.
* @param context LoadBalancerConfigContext.
* @return the next LBOutboundEndpoint according to implemented LB algorithm.
*/
@Override
public LBOutboundEndpoint getNextLBOutboundEndpoint(CarbonMessage cMsg, LoadBalancerConfigContext context) {
LBOutboundEndpoint endPoint = null;
synchronized (this.lock) {
if (this.lbOutboundEndpoints != null && this.lbOutboundEndpoints.size() > 0) {
endPoint = this.lbOutboundEndpoints.get((int) (Math.random() * (this.lbOutboundEndpoints.size())));
} else {
log.error("No OutboundEndpoint is available..");
}
}
return endPoint;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:23,
代码来源:Random.java
示例2: processRequest
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private void processRequest(CarbonMessage cMsg) throws MalformedURLException {
URL url = new URL(uri);
String host = url.getHost();
int port = (url.getPort() == -1) ? 80 : url.getPort();
String urlPath = url.getPath();
cMsg.setProperty(Constants.HOST, host);
cMsg.setProperty(Constants.PORT, port);
cMsg.setProperty(Constants.TO, urlPath);
//Check for PROTOCOL property and add if not exist
if (cMsg.getProperty(Constants.PROTOCOL) == null) {
cMsg.setProperty(Constants.PROTOCOL, org.wso2.carbon.transport.http.netty.common.Constants.PROTOCOL_NAME);
}
if (port != 80) {
cMsg.getHeaders().set(Constants.HOST, host + ":" + port);
} else {
cMsg.getHeaders().set(Constants.HOST, host);
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:23,
代码来源:HTTPOutboundEndpoint.java
示例3: receive
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
public boolean receive(CarbonMessage cMsg, CarbonCallback callback) {
if (log.isDebugEnabled()) {
log.debug("HTTP Endpoint : " + getName() + " received the message");
}
cMsg.setProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_CONTEXT, context);
String uri = (String) cMsg.getProperty(Constants.TO);
String[] uriSplit = uri.split(context);
String subPath = "";
if (uriSplit.length > 1) {
subPath = uriSplit[1];
}
cMsg.setProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_SUB_GROUP_PATH, subPath);
cMsg.setProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_METHOD, cMsg.getProperty("HTTP_METHOD"));
return super.receive(cMsg, callback);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:19,
代码来源:HTTPInboundEP.java
示例4: testIntegrationFlow
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Test (description = "Test the scenario of integration flow which includes a respond mediator after a log mediator")
public void testIntegrationFlow()throws Exception {
CarbonMessage carbonMessage = mock(CarbonMessage.class);
CarbonCallback carbonCallback = mock(CarbonCallback.class);
when(carbonMessage.getProperty(Constants.PROTOCOL)).thenReturn("HTTP");
when(carbonMessage.getProperty(Constants.LISTENER_INTERFACE_ID)).thenReturn("default");
when(carbonMessage.getProperty(Constants.TO)).thenReturn("/stocks/getStocks");
when(carbonMessage.getProperty("HTTP_METHOD")).thenReturn("GET");
when(carbonMessage.getProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_CONTEXT)).thenReturn("/stocks");
when(carbonMessage.getProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_SUB_GROUP_PATH)).
thenReturn("/getStocks");
when(carbonMessage.getProperty(org.wso2.carbon.gateway.core.Constants.SERVICE_METHOD)).
thenReturn("GET");
when(carbonMessage.getProperty(org.wso2.carbon.gateway.core.Constants.VARIABLE_STACK)).
thenReturn(new Stack<Map<String, Object>>());
carbonMessageProcessor.receive(carbonMessage, carbonCallback);
verify(carbonCallback, timeout(1000)).done(carbonMessage);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:23,
代码来源:IntegrationFlowTest.java
示例5: dispatch
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean dispatch(CarbonMessage cMsg, CarbonCallback callback) {
String interfaceId = (String) cMsg.getProperty(Constants.LISTENER_INTERFACE_ID);
ArrayList<HTTPInboundEP> endpointsOnPort = httpEPRegistry.get(interfaceId);
if (endpointsOnPort == null) {
log.error("No endpoint found for interface id : " + interfaceId);
return false;
}
boolean foundMatchingEndpoint = false;
for (HTTPInboundEP endpoint : endpointsOnPort) {
if (endpoint.canReceive(cMsg)) {
foundMatchingEndpoint = endpoint.receive(cMsg, callback);
break;
}
}
if (!foundMatchingEndpoint) {
callback.done(createErrorMessage("Cannot find a matching Resource", 404));
}
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:27,
代码来源:HTTPInboundEPDispatcher.java
示例6: receive
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback)
throws Exception {
Throwable throwable = (Throwable) carbonMessage.getProperty(Constants.ERROR_EXCEPTION);
String className = throwable.getClass().getName();
ErrorDetail errorDetail = stringErrorDetailMap.get(className);
if (errorDetail == null) {
for (Map.Entry entry : errorDetailMap.entrySet()) {
Class<? extends Throwable> obj = (Class) entry.getKey();
// if(throwable instanceof ){
//
// }
}
}
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:19,
代码来源:FaultMediator.java
示例7: createErrorMessage
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private CarbonMessage createErrorMessage(String payload, int statusCode) {
DefaultCarbonMessage response = new DefaultCarbonMessage();
response.setStringMessageBody(payload);
byte[] errorMessageBytes = payload.getBytes(Charset.defaultCharset());
Map<String, String> transportHeaders = new HashMap<>();
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONNECTION,
org.wso2.carbon.transport.http.netty.common.Constants.KEEP_ALIVE);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_ENCODING,
org.wso2.carbon.transport.http.netty.common.Constants.GZIP);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_TYPE,
org.wso2.carbon.transport.http.netty.common.Constants.TEXT_PLAIN);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_LENGTH,
(String.valueOf(errorMessageBytes.length)));
response.setHeaders(transportHeaders);
response.setProperty(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_STATUS_CODE, statusCode);
response.setProperty(org.wso2.carbon.messaging.Constants.DIRECTION,
org.wso2.carbon.messaging.Constants.DIRECTION_RESPONSE);
return response;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:25,
代码来源:HTTPInboundEPDispatcher.java
示例8: receive
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
Object obj = carbonMessage.getProperty(org.wso2.carbon.gateway.core.worker.Constants.PARENT_TYPE);
if (obj != null) {
String val = (String) obj;
if (val.equals(org.wso2.carbon.gateway.core.worker.Constants.CPU_BOUND)
&& getMediatorType() == MediatorType.IO_BOUND) {
WorkerModelDispatcher.getInstance().
dispatch(carbonMessage, carbonCallback, this, MediatorType.IO_BOUND);
} else if (val.equals(org.wso2.carbon.gateway.core.worker.Constants.IO_BOUND)
&& getMediatorType() == MediatorType.CPU_BOUND) {
WorkerModelDispatcher.getInstance().
dispatch(carbonMessage, carbonCallback, this, MediatorType.CPU_BOUND);
}
}
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:19,
代码来源:AbstractMediator.java
示例9: pushNewVariableStack
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Creates a new variable stack with an empty variable map if the stack size is zero or else it will create a new
* map with a reference to the map on top of the stack and push this new map onto the stack.
* @param cMsg
*/
public static void pushNewVariableStack(CarbonMessage cMsg) {
// check if stack exists in cMsg, create empty otherwise
Stack<Map<String, Object>> variableStack;
if (cMsg.getProperty(Constants.VARIABLE_STACK) != null) {
variableStack = (Stack<Map<String, Object>>) cMsg.getProperty(Constants.VARIABLE_STACK);
} else {
variableStack = new Stack<Map<String, Object>>();
cMsg.setProperty(Constants.VARIABLE_STACK, variableStack);
}
if (variableStack.size() == 0) {
variableStack.push(new HashMap<String, Object>());
} else {
Map<String, Object> newMap = new HashMap<>();
newMap.put(Constants.GW_GT_SCOPE, variableStack.peek());
variableStack.push(newMap);
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:24,
代码来源:VariableUtil.java
示例10: receive
点赞 3
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
if (carbonMessage.isAlreadyRead()) {
MessageDataSource messageDataSource = carbonMessage.getMessageDataSource();
if (messageDataSource != null) {
messageDataSource.serializeData();
carbonMessage.setEndOfMsgAdded(true);
carbonMessage.getHeaders().remove(Constants.HTTP_CONTENT_LENGTH);
carbonMessage.getHeaders()
.set(Constants.HTTP_CONTENT_LENGTH, String.valueOf(carbonMessage.getFullMessageLength()));
} else {
LOGGER.error("Message is already built but cannot find the MessageDataSource");
}
}
return true;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:18,
代码来源:AbstractOutboundEndpoint.java
示例11: getCookieValue
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* @param carbonMessage Response from which host and port are to be identified.
* @param context LoadBalancerConfigContext
* @return String of form 'hostname:port'
*/
public static String getCookieValue(CarbonMessage carbonMessage, LoadBalancerConfigContext context) {
//Extracting host and port from response to identify appropriate cookie.
return context.getCookieFromOutboundEP(
carbonMessage.getProperty(Constants.HOST).toString() +
":" + carbonMessage.getProperty(Constants.PORT).toString());
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:13,
代码来源:CommonUtil.java
示例12: getClientIP
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* @param cMsg Client's request.
* @return Client's IPAddress.
* <p>
* It looks for the following HTTP request headers.
* 1) X-Forwarded-For
* 2) Client-IP
* 3) Remote-Addr
* <p>
* NOTE: This method will be used to identify Client's IP in case of
* Client IP based hashing algorithms.
*/
public static String getClientIP(CarbonMessage cMsg) {
//If client is behind proxy, this gives the best Client IP.
if (cMsg.getHeader(LoadBalancerConstants.X_FORWARDED_FOR_HEADER) != null) {
String ipList = cMsg.getHeader(LoadBalancerConstants.X_FORWARDED_FOR_HEADER);
//The first IP in the list belongs to client.
// eg: 192.168.72.3, 10.2.53.8, ..
if (ipList.contains(",")) {
return ipList.split(",", 2)[0].trim();
} else {
//There is only one IP
return ipList;
}
} else if (cMsg.getHeader(LoadBalancerConstants.CLIENT_IP_HEADER) != null) {
return cMsg.getHeader(LoadBalancerConstants.CLIENT_IP_HEADER);
} else if (cMsg.getHeader(LoadBalancerConstants.REMOTE_ADDR_HEADER) != null) {
return cMsg.getHeader(LoadBalancerConstants.REMOTE_ADDR_HEADER);
}
return null;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:40,
代码来源:CommonUtil.java
示例13: handleFault
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* @param errorCode HTTP Error Code.
* @param throwable Throwable instance of error.
* @param response Must be DefaultCarbonMessage.
* @param carbonCallback CallBackObject for sending response.
* <p>
* NOTE: As of now, we will send empty DefaultCarbonMessage.
* It is for future use. Eg: From user request, we can findOut
* Content-Type. So error response can also be sent of that
* Content-Type and Encoding.
*/
@Override
public void handleFault(String errorCode, Throwable throwable, CarbonMessage response,
CarbonCallback carbonCallback) {
String payload = throwable.getMessage();
((DefaultCarbonMessage) response).setStringMessageBody(payload);
byte[] errorMessageBytes = payload.getBytes(Charset.defaultCharset());
Map<String, String> transportHeaders = new HashMap<>();
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONNECTION,
org.wso2.carbon.transport.http.netty.common.Constants.KEEP_ALIVE);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_ENCODING,
org.wso2.carbon.transport.http.netty.common.Constants.GZIP);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_TYPE,
org.wso2.carbon.transport.http.netty.common.Constants.TEXT_PLAIN);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_CONTENT_LENGTH,
(String.valueOf(errorMessageBytes.length)));
transportHeaders.put(Constants.ERROR_MESSAGE, payload);
transportHeaders.put(Constants.ERROR_DETAIL, payload);
transportHeaders.put(Constants.ERROR_CODE, errorCode);
transportHeaders.put(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_STATUS_CODE, errorCode);
response.setHeaders(transportHeaders);
if (carbonCallback instanceof LoadBalancerMediatorCallBack) {
((LoadBalancerMediatorCallBack) carbonCallback).getParentCallback().done(response);
} else {
carbonCallback.done(response);
}
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:49,
代码来源:LBErrorHandler.java
示例14: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
*
* @param carbonMessage CarbonMessage
* @param carbonCallback CarbonCallback
* @param context LoadBalancerConfigContext
* @param lbOutboundEndpoint LBOutboundEndpoint
* @return
* @throws Exception
*/
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback,
LoadBalancerConfigContext context,
LBOutboundEndpoint lbOutboundEndpoint) throws Exception {
incrementWeightsWindowTracker(); // To keep track of no requests elapsed for this current window
map.get(lbOutboundEndpoint.getName()).receive(carbonMessage, carbonCallback, context);
return false;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:20,
代码来源:WeightedRandom.java
示例15: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
*
* @param carbonMessage CarbonMessage
* @param carbonCallback CarbonCallback
* @param context LoadBalancerConfigContext
* @param lbOutboundEndpoint LBOutboundEndpoint
* @return
* @throws Exception
*/
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback,
LoadBalancerConfigContext context,
LBOutboundEndpoint lbOutboundEndpoint) throws Exception {
incrementWeightsWindowTracker(); // To keep track of no requests elapsed for this current window
map.get(lbOutboundEndpoint.getName()).receive(carbonMessage, carbonCallback, context);
return false;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:20,
代码来源:WeightedRoundRobin.java
示例16: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback,
LoadBalancerConfigContext context,
LBOutboundEndpoint lbOutboundEndpoint) throws Exception {
map.get(lbOutboundEndpoint.getName()).receive(carbonMessage, carbonCallback, context);
return false;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:9,
代码来源:LeastResponseTime.java
示例17: getNextLBOutboundEndpoint
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* @param cMsg Carbon Message has all headers required to make decision.
* @param context LoadBalancerConfigContext.
* @return LBOutboundEndpoint Object.
*/
@Override
public LBOutboundEndpoint getNextLBOutboundEndpoint(CarbonMessage cMsg, LoadBalancerConfigContext context) {
LBOutboundEndpoint endPoint = null;
synchronized (this.lock) {
if (this.lbOutboundEndpoints != null && this.lbOutboundEndpoints.size() > 0) {
String ipAddress = CommonUtil.getClientIP(cMsg);
log.info("IP address retrieved is : " + ipAddress);
if (CommonUtil.isValidIP(ipAddress)) {
//getting endpoint name for this ipAddress.
String hostAndPort = this.hash.get(ipAddress);
if (log.isDebugEnabled()) {
log.debug("Host and port : " + hostAndPort);
}
if (hostAndPort != null) {
endPoint = context.getLBOutboundEndpoint(map.get(hostAndPort));
}
} else {
log.error("The IP Address retrieved is : " + ipAddress +
" which is invalid according to our validation. No Endpoint will be chosen" +
" as your configuration is Strict IP Hashing..");
}
} else {
log.error("No outbound end point is available..");
}
}
return endPoint;
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:45,
代码来源:StrictClientIPHashing.java
示例18: testGetClientIP
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Test
public void testGetClientIP() {
CarbonMessage carbonMessage = new DefaultCarbonMessage();
Assert.assertEquals(null, CommonUtil.getClientIP(carbonMessage));
carbonMessage.setHeader("Client-IP", "192.165.87.23");
Assert.assertEquals("192.165.87.23", CommonUtil.getClientIP(carbonMessage));
//We are removing Client-IP header, so value of Remote-Addr should be returned.
carbonMessage.removeHeader("Client-IP");
carbonMessage.setHeader("Remote-Addr", "192.165.87.23");
Assert.assertEquals("192.165.87.23", CommonUtil.getClientIP(carbonMessage));
//If Client-IP and Remote-Addr are present, value of Client-IP should be returned.
carbonMessage.setHeader("Client-IP", "10.11.12.13");
Assert.assertEquals("10.11.12.13", CommonUtil.getClientIP(carbonMessage));
//If X-Forwarded-For, Client-IP and Remote-Addr are present value of X-Forwarded-For should be returned.
carbonMessage.setHeader("X-Forwarded-For", "19.165.87.23");
Assert.assertEquals("19.165.87.23", CommonUtil.getClientIP(carbonMessage));
//First IP in X-Forwarded-For has to be returned.
carbonMessage.setHeader("X-Forwarded-For", "90.89.88.87,19.165.87.23");
Assert.assertEquals("90.89.88.87", CommonUtil.getClientIP(carbonMessage));
}
开发者ID:wso2-incubator,
项目名称:HTTP-Load-balancer,
代码行数:29,
代码来源:CommonUtilTest.java
示例19: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback)
throws Exception {
super.receive(carbonMessage, carbonCallback);
processRequest(carbonMessage);
ServiceContextHolder.getInstance().getSender().send(carbonMessage, carbonCallback);
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:9,
代码来源:HTTPOutboundEndpoint.java
示例20: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Mediate the message.
* <p/>
* This is the execution point of the mediator.
*
* @param carbonMessage MessageContext to be mediated
* @param carbonCallback Callback which can be use to call the previous step
* @return whether mediation is success or not
**/
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
CarbonMessage convertedMsg = convertTo(carbonMessage, MIMEType.XML);
//CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
//CharBuffer charBuf = decoder.decode(convertedMsg.getMessageBody());
//String msgBody = new String(charBuf.array());
//log.info("\n" + msgBody);
return next(convertedMsg, carbonCallback);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:23,
代码来源:JSONtoXMLTestMediator.java
示例21: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Mediate the message.
* <p/>
* This is the execution point of the mediator.
*
* @param carbonMessage MessageContext to be mediated
* @param carbonCallback Callback which can be use to call the previous step
* @return whether mediation is success or not
**/
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
CarbonMessage convertedMsg = convertTo(carbonMessage, MIMEType.JSON);
//CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
//CharBuffer charBuf = decoder.decode(convertedMsg.getMessageBody());
//String msgBody = new String(charBuf.array());
//log.info("\n" + msgBody);
return next(convertedMsg, carbonCallback);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:23,
代码来源:XMLtoJSONTestMediator.java
示例22: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Process the message
*
* @param cMsg Carbon Message
* @param callback Callback to execute response flow
* @return whether forward processing is successful
*/
public boolean receive(CarbonMessage cMsg, CarbonCallback callback) {
VariableUtil.pushGlobalVariableStack(cMsg, new HashMap<>());
Resource resource = null;
for (Resource r : IntegrationConfigRegistry.getInstance().getIntegrationConfig(configName)
.getResources().values()) {
String method = (String) cMsg.getProperty(Constants.SERVICE_METHOD);
String methodAnnotation = "@" + method;
Annotation annotation = r.getAnnotation(methodAnnotation);
if (annotation.getValue().equals(Boolean.TRUE)) {
if (r.matches(cMsg)) {
resource = r;
break;
}
} else {
return false;
}
}
if (resource != null) {
return resource.receive(cMsg, callback);
}
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:35,
代码来源:InboundEndpoint.java
示例23: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage cMsg, CarbonCallback callback) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Gateway received a message");
}
WorkerModelDispatcher.getInstance().receive(cMsg, callback, MediatorType.CPU_BOUND);
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:12,
代码来源:MessageProcessor.java
示例24: getSimpleLogMessage
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private String getSimpleLogMessage(CarbonMessage carbonMessage, Reader reader) throws Exception {
StringBuffer sb = new StringBuffer();
if (carbonMessage.getHeader(org.wso2.carbon.messaging.Constants.TO) != null) {
sb.append("To: ").append(carbonMessage.getHeader(org.wso2.carbon.messaging.Constants.TO));
} else if (carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.TO) != null) {
sb.append("To: ").append(carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.TO));
} else {
sb.append("To: ");
if (carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.HOST) != null
&& carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.PORT) != null) {
String receivedFrom = carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.HOST) + ":" +
carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.PORT);
sb.append(separator).append("FROM: ").append(receivedFrom);
}
if (carbonMessage.getProperty("WSAction") != null) {
sb.append(separator).append("WSAction: ").append(carbonMessage.getProperty("WSAction"));
}
if (carbonMessage.getProperty(Constants.SOAPACTION) != null) {
sb.append(separator).append("SOAPAction: ").append(carbonMessage.getProperty(Constants.SOAPACTION));
}
if (carbonMessage.getProperty("ReplyTo") != null) {
sb.append(separator).append("ReplyTo: ").append(carbonMessage.getProperty("ReplyTo"));
}
if (carbonMessage.getProperty("MessageID") != null) {
sb.append(separator).append("MessageID: ").append(carbonMessage.getProperty("MessageID"));
sb.append(separator).append("Direction: ")
.append(carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.DIRECTION) != null ?
carbonMessage.getProperty(org.wso2.carbon.messaging.Constants.DIRECTION) :
"request");
setCustomProperties(sb, carbonMessage, reader);
}
}
return
trimLeadingSeparator(sb);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:39,
代码来源:LogMediator.java
示例25: getHeadersLogMessage
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private String getHeadersLogMessage(CarbonMessage carbonMessage, Reader reader) throws Exception {
StringBuffer sb = new StringBuffer();
MessageDataSource messageDataSource = carbonMessage.getMessageDataSource();
if (messageDataSource == null) {
messageDataSource = reader.makeMessageReadable(carbonMessage);
}
if (messageDataSource.getDataObject() != null && messageDataSource.getDataObject() instanceof OMElement) {
OMElement omElement = (OMElement) messageDataSource.getDataObject();
if (omElement instanceof SOAPEnvelope) {
try {
SOAPHeader header = (SOAPHeader) ((SOAPEnvelope) omElement).getHeader();
if (header != null) {
for (Iterator iter = header.examineAllHeaderBlocks(); iter.hasNext(); ) {
Object o = iter.next();
if (o instanceof SOAPHeaderBlock) {
SOAPHeaderBlock headerBlk = (SOAPHeaderBlock) o;
sb.append(separator).append(headerBlk.getLocalName()).
append(" : ").append(headerBlk.getText());
} else if (o instanceof OMElement) {
OMElement headerElem = (OMElement) o;
sb.append(separator).append(headerElem.getLocalName()).
append(" : ").append(headerElem.getText());
}
}
}
} catch (Exception e) {
log.error("Exception occurred while processing SOAPHeader", e);
return null;
}
}
}
setCustomProperties(sb, carbonMessage, reader);
return trimLeadingSeparator(sb);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:37,
代码来源:LogMediator.java
示例26: getFullLogMessage
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private String getFullLogMessage(CarbonMessage carbonMessage, Reader reader) throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(getSimpleLogMessage(carbonMessage, reader));
MessageDataSource messageDataSource = carbonMessage.getMessageDataSource();
if (messageDataSource == null) {
messageDataSource = reader.makeMessageReadable(carbonMessage);
}
if (isJSONMessage(messageDataSource)) {
sb.append(separator).append("Payload: ").append(messageDataSource.getValueAsString("$"));
} else if (isSOAPMessage(messageDataSource)) {
sb.append(separator).append("Envelope: ").append(messageDataSource.getDataObject().toString());
}
return trimLeadingSeparator(sb);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:16,
代码来源:LogMediator.java
示例27: getLogMessage
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private String getLogMessage(CarbonMessage carbonMessage, Reader reader) throws Exception {
switch (logLevel) {
case CUSTOM:
return getCustomLogMessage(carbonMessage, reader);
case SIMPLE:
return getSimpleLogMessage(carbonMessage, reader);
case HEADERS:
return getHeadersLogMessage(carbonMessage, reader);
case FULL:
return getFullLogMessage(carbonMessage, reader);
default:
return "Invalid log level specified";
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:16,
代码来源:LogMediator.java
示例28: setCustomProperties
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
private void setCustomProperties(StringBuffer sb, CarbonMessage carbonMessage, Reader reader) throws Exception {
if (properties != null && !properties.isEmpty()) {
for (LogMediatorProperty property : properties) {
if (property != null) {
if (property.getValue() != null) {
sb.append(separator).append(property.getKey()).append(" = ")
.append(getValue(carbonMessage, property.getValue()));
} else {
if (carbonMessage.getMessageDataSource() != null) {
sb.append(separator).append(property.getKey()).append(" = ")
.append(property.getNameSpaceMap() == null ?
carbonMessage.getMessageDataSource()
.getValueAsString(property.getExpression()) :
carbonMessage.getMessageDataSource()
.getValueAsString(property.getExpression(),
property.getNameSpaceMap()));
} else {
MessageDataSource messageDataSource = reader.makeMessageReadable(carbonMessage);
sb.append(separator).append(property.getKey()).append(" = ")
.append(property.getNameSpaceMap() == null ?
messageDataSource.getValueAsString(property.getExpression()) :
messageDataSource.getValueAsString(property.getExpression(),
property.getNameSpaceMap()));
}
}
}
}
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:30,
代码来源:LogMediator.java
示例29: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
log.info("Sleeping for " + time + " miliseconds.");
Thread.sleep(time);
return next(carbonMessage, carbonCallback);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:9,
代码来源:SleepMediator.java
示例30: isPathMatched
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Returns a boolean depending on whether the result of a given path language expression against message body
* matches with the provided pattern.
*
* @param carbonMessage The CarbonMessage of which the message body needs to be evaluated
* @param source Contains the matching condition
* @param pattern The pattern to match the path language evaluation result against
* @return Whether the pattern is matched or not
* @throws Exception
*/
public static boolean isPathMatched(CarbonMessage carbonMessage, Source source, Pattern pattern) throws Exception {
// TODO: Once we sort out whether we are using a canonical model, how exactly are we going to
// reuse the message once built, etc this should be changed as appropriate
// Cloning the message here will have an effect on memory
InputStream inputStream = MessageUtil.cloneCarbonMessageWithData(carbonMessage).getInputStream();
MessageBodyEvaluator messageBodyEvaluator = MessageBodyEvaluatorRegistry.getInstance()
.getMessageBodyEvaluator(source.getPathLanguage());
if (messageBodyEvaluator != null) {
Reader reader = ReaderRegistryImpl.getInstance().getReader(carbonMessage);
if (reader != null) {
String contentType = reader.getContentType();
if (messageBodyEvaluator.isContentTypeSupported(contentType)) {
Object result = messageBodyEvaluator.evaluate(inputStream, source.getKey());
return result != null && pattern.matcher(result.toString()).matches();
} else {
throw new MessageBodyEvaluationException(messageBodyEvaluator.getPathLanguage()
+ " cannot be applied for a message body of the type " + contentType);
}
} else {
throw new MessageBodyEvaluationException("A Reader is not found for the content type: "
+ carbonMessage.getHeader(Constants.HTTP_CONTENT_TYPE));
}
} else {
throw new MessageBodyEvaluationException("A Message Body Evaluator is not found for the path language "
+ source.getPathLanguage());
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:38,
代码来源:Evaluator.java
示例31: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
childThenMediatorList.getFirstMediator().
receive(carbonMessage, new FlowControllerExceptionCallback(carbonCallback, this,
VariableUtil.getVariableStack(carbonMessage), new DefaultExceptionHandler()));
return true;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:10,
代码来源:TryBlockMediator.java
示例32: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
/* SubroutineCall can be either inside an Integration object or inside another Global level Subroutine
First we will check if its inside an Integration, if so first look for the Subroutine implementation in its
Integrations' local Map
*/
Subroutine referredSubroutine = null;
if (this.integrationId != null) {
referredSubroutine = IntegrationConfigRegistry.getInstance().getIntegrationConfig(this.integrationId)
.getSubroutine(this.subroutineId);
}
//TODO:if referredSubroutine is not found we should look in the global level, global level Map should implement
// if incorrect number of arguments are given or subroutine is not present, skip the subroutine call
if (referredSubroutine == null || referredSubroutine.getInputArgs().size() != inputParameters.size()) {
log.error("Invalid subroutine call to " + subroutineId);
return next(carbonMessage, carbonCallback);
}
// Retrieve input parameter objects
List<Object> inputParameterObjects = new ArrayList<>();
inputParameters.forEach(
inputParameter -> inputParameterObjects.add(getObjectFromContext(carbonMessage, inputParameter)));
super.receive(carbonMessage, carbonCallback);
VariableUtil.removeParentMap(carbonMessage);
// Put retrieved objects to the new map
Iterator<String> subroutineArguments = referredSubroutine.getInputArgs().keySet().iterator();
inputParameterObjects.forEach(inputParameterObject -> VariableUtil
.addVariable(carbonMessage, subroutineArguments.next(), inputParameterObject));
// Forward the carbon message to Subroutines' MediatorCollection with new FlowControllerSubroutineCallback
CarbonCallback callback = new FlowControllerSubroutineCallback(carbonCallback, this,
VariableUtil.getVariableStack(carbonMessage), referredSubroutine);
referredSubroutine.getSubroutineMediators().getFirstMediator().receive(carbonMessage, callback);
return true;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:40,
代码来源:SubroutineCallMediator.java
示例33: receive
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public boolean receive(CarbonMessage carbonMessage, CarbonCallback carbonCallback) throws Exception {
OutboundEndpoint endpoint = outboundEndpoint;
if (endpoint == null) {
endpoint = IntegrationConfigRegistry.getInstance()
.getIntegrationConfig(integrationKey).getOutbound(outboundEPKey);
if (endpoint == null) {
log.error("Outbound Endpoint : " + outboundEPKey + " not found ");
return false;
}
}
//prepare CarbonMessage if it is a response message from a previous invoke
//If the DIRECTION property of the carbonMessage is DIRECTION_RESPONSE, we can assume service chaining
if (carbonMessage.getProperty(Constants.DIRECTION) != null &&
carbonMessage.getProperty(Constants.DIRECTION).equals(Constants.DIRECTION_RESPONSE)) {
//remove Direction property
carbonMessage.removeProperty(Constants.DIRECTION);
//remove HTTP status code
carbonMessage.removeProperty(org.wso2.carbon.transport.http.netty.common.Constants.HTTP_STATUS_CODE);
//TODO decide and remove/add any other properties (removed above to enable service chaining support)
}
// Retrieve the referenced message from the variable stack
// If the retrieved message is null, skip the Call Mediator
CarbonMessage cMsg = (CarbonMessage) getObjectFromContext(carbonMessage, messageKey);
if (cMsg != null) {
CarbonCallback callback = new FlowControllerMediateCallback(carbonCallback, this,
VariableUtil.getVariableStack(carbonMessage));
endpoint.receive(cMsg, callback);
} else {
log.error("Message with identifier: " + messageKey + ", not found in this context or value is null.");
return next(carbonMessage, carbonCallback);
}
return false;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:39,
代码来源:CallMediator.java
示例34: done
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public void done(CarbonMessage carbonMessage) {
if (canProcess(carbonMessage)) {
// Retrieve returning objects from the Subroutines' scope
List<Object> retuningObjects = new ArrayList<>();
if (subroutine.getReturnVariables() != null) {
subroutine.getReturnVariables().forEach(
identifier -> retuningObjects.add(VariableUtil.getVariable(carbonMessage, identifier)));
}
// Remove Subroutines' scope
VariableUtil.popVariableStack(carbonMessage, variableStack);
// Validate if correct number of returning values are specified at SubroutineMediatorCall
if (mediator.getReturnValueIdentifiers().size() > retuningObjects.size()) {
log.error("Invalid return value assignment in subroutine call " + mediator.getSubroutineId());
}
// Set returning objects to parents' scope
for (int i = 0; i < Math.min(mediator.getReturnValueIdentifiers().size(), retuningObjects.size()); i++) {
mediator.setObjectToContext(carbonMessage, mediator.getReturnValueIdentifiers().get(i),
retuningObjects.get(i));
}
if (mediator.hasNext()) {
try {
mediator.next(carbonMessage, parentCallback);
} catch (Exception e) {
log.error("Error while mediating from Message Callback", e);
}
} else if (parentCallback instanceof FlowControllerCallback) {
parentCallback.done(carbonMessage);
} else {
log.warn("Chain was completed without sending a response to client");
}
} else {
if (parentCallback instanceof FlowControllerCallback) {
parentCallback.done(carbonMessage);
} else {
new DefaultExceptionHandler().handleException(carbonMessage, parentCallback);
}
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:40,
代码来源:FlowControllerSubroutineCallback.java
示例35: done
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
@Override
public void done(CarbonMessage carbonMessage) {
if (canProcess(carbonMessage)) {
VariableUtil.popVariableStack(carbonMessage, variableStack);
/* Call mediator is the only mediator that uses FlowControllerMediatorCallback and return a value after
* Therefor the returning value should be set to the variable stack in the carbon message */
if (mediator instanceof CallMediator) {
((CallMediator) mediator)
.setObjectToContext(carbonMessage, ((CallMediator) mediator).getReturnedOutput(),
carbonMessage);
}
if (mediator.hasNext()) { // If Mediator has a sibling after this
try {
mediator.next(carbonMessage, parentCallback);
} catch (Exception e) {
log.error("Error while mediating from Callback", e);
}
} else if (parentCallback instanceof FlowControllerCallback) {
//If no siblings handover message to the requester
parentCallback.done(carbonMessage);
} else {
log.warn("Chain was completed without sending a response to client");
}
} else {
if (parentCallback instanceof FlowControllerCallback) {
parentCallback.done(carbonMessage);
} else {
new DefaultExceptionHandler().handleException(carbonMessage, parentCallback);
}
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:33,
代码来源:FlowControllerMediateCallback.java
示例36: convertTo
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Convert message into a specified format
*
* @param cMsg Carbon Message
* @param targetType Type to be converted
* @return CarbonMessage with converted message body
* @throws Exception
*/
public CarbonMessage convertTo(CarbonMessage cMsg, String targetType) throws Exception {
String sourceType = cMsg.getHeader("Content-Type");
if (sourceType == null) {
handleException("Content-Type header could not be found in the request");
return null; // to make findbugs happy
}
sourceType = sourceType.split(";")[0]; // remove charset from Content-Type header
return ConversionManager.getInstance().convertTo(cMsg, sourceType, targetType);
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:20,
代码来源:AbstractMediator.java
示例37: getValue
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
public Object getValue(CarbonMessage carbonMessage, String name) {
if (name.startsWith("$")) {
return VariableUtil.getVariable(carbonMessage, name.substring(1));
} else {
return name;
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:9,
代码来源:AbstractMediator.java
示例38: setObjectToContext
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
/**
* Put an object in the variable stack
*
* @param carbonMessage Carbon message with the stack
* @param objectName Name of the object
* @param object Object itself
*/
public void setObjectToContext(CarbonMessage carbonMessage, String objectName, Object object) {
Map map = (Map) VariableUtil.getMap(carbonMessage, objectName);
if (map != null) {
if (VariableUtil.isBothSameType(map.get(objectName), object)) {
map.put(objectName, object);
} else {
log.error("Not a valid assignment to variable: " + objectName);
}
} else {
log.error("Variable is not declared: " + objectName);
}
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:20,
代码来源:AbstractMediator.java
示例39: getReader
点赞 2
import org.wso2.carbon.messaging.CarbonMessage; //导入依赖的package包/类
public Reader getReader(CarbonMessage carbonMessage) {
String contentType = carbonMessage.getHeader(Constants.HTTP_CONTENT_TYPE);
contentType = ReaderUtil.parseContentType(contentType);
if (contentType != null && builderMap.containsKey(contentType)) {
return builderMap.get(contentType);
}
return null;
}
开发者ID:wso2-attic,
项目名称:carbon-gateway-framework,
代码行数:9,
代码来源:ReaderRegistryImpl.java