use of org.apache.ignite.configuration.ConnectorMessageInterceptor in project ignite by apache.
the class ClientAbstractSelfTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalHost(HOST);
assert cfg.getConnectorConfiguration() == null;
ConnectorConfiguration clientCfg = new ConnectorConfiguration();
clientCfg.setPort(BINARY_PORT);
if (useSsl()) {
clientCfg.setSslEnabled(true);
clientCfg.setSslContextFactory(sslContextFactory());
}
cfg.setConnectorConfiguration(clientCfg);
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(IP_FINDER);
cfg.setDiscoverySpi(disco);
cfg.setCacheConfiguration(cacheConfiguration(DEFAULT_CACHE_NAME), cacheConfiguration("replicated"), cacheConfiguration("partitioned"), cacheConfiguration(CACHE_NAME));
clientCfg.setMessageInterceptor(new ConnectorMessageInterceptor() {
/** {@inheritDoc} */
@Override
public Object onReceive(@Nullable Object obj) {
if (obj != null)
INTERCEPTED_OBJECTS.put(obj, obj);
return overwriteIntercepted && obj instanceof String ? obj + INTERCEPTED_SUF : obj;
}
/** {@inheritDoc} */
@Override
public Object onSend(Object obj) {
if (obj != null)
INTERCEPTED_OBJECTS.put(obj, obj);
return obj;
}
});
return cfg;
}
use of org.apache.ignite.configuration.ConnectorMessageInterceptor in project ignite by apache.
the class GridRestProcessor method interceptResponse.
/**
* Applies {@link ConnectorMessageInterceptor} from
* {@link ConnectorConfiguration#getMessageInterceptor()}
* to all user objects in the response.
*
* @param res Response.
* @param req Request.
*/
private void interceptResponse(GridRestResponse res, GridRestRequest req) {
ConnectorMessageInterceptor interceptor = config().getMessageInterceptor();
if (interceptor != null && res.getResponse() != null) {
switch(req.command()) {
case CACHE_CONTAINS_KEYS:
case CACHE_CONTAINS_KEY:
case CACHE_GET:
case CACHE_GET_ALL:
case CACHE_PUT:
case CACHE_ADD:
case CACHE_PUT_ALL:
case CACHE_REMOVE:
case CACHE_REMOVE_ALL:
case CACHE_REPLACE:
case ATOMIC_INCREMENT:
case ATOMIC_DECREMENT:
case CACHE_CAS:
case CACHE_APPEND:
case CACHE_PREPEND:
res.setResponse(interceptSendObject(res.getResponse(), interceptor));
break;
case EXE:
if (res.getResponse() instanceof GridClientTaskResultBean) {
GridClientTaskResultBean taskRes = (GridClientTaskResultBean) res.getResponse();
taskRes.setResult(interceptor.onSend(taskRes.getResult()));
}
break;
default:
break;
}
}
}
use of org.apache.ignite.configuration.ConnectorMessageInterceptor in project ignite by apache.
the class GridRestProcessor method interceptRequest.
/**
* Applies {@link ConnectorMessageInterceptor}
* from {@link ConnectorConfiguration#getMessageInterceptor()} ()}
* to all user parameters in the request.
*
* @param req Client request.
*/
private void interceptRequest(GridRestRequest req) {
ConnectorMessageInterceptor interceptor = config().getMessageInterceptor();
if (interceptor == null)
return;
if (req instanceof GridRestCacheRequest) {
GridRestCacheRequest req0 = (GridRestCacheRequest) req;
req0.key(interceptor.onReceive(req0.key()));
req0.value(interceptor.onReceive(req0.value()));
req0.value2(interceptor.onReceive(req0.value2()));
Map<Object, Object> oldVals = req0.values();
if (oldVals != null) {
Map<Object, Object> newVals = U.newHashMap(oldVals.size());
for (Map.Entry<Object, Object> e : oldVals.entrySet()) newVals.put(interceptor.onReceive(e.getKey()), interceptor.onReceive(e.getValue()));
req0.values(U.sealMap(newVals));
}
} else if (req instanceof GridRestTaskRequest) {
GridRestTaskRequest req0 = (GridRestTaskRequest) req;
List<Object> oldParams = req0.params();
if (oldParams != null) {
Collection<Object> newParams = new ArrayList<>(oldParams.size());
for (Object o : oldParams) newParams.add(interceptor.onReceive(o));
req0.params(U.sealList(newParams));
}
}
}
Aggregations