Search in sources :

Example 1 with ConnectorMessageInterceptor

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ConnectorMessageInterceptor(org.apache.ignite.configuration.ConnectorMessageInterceptor) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 2 with ConnectorMessageInterceptor

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;
        }
    }
}
Also used : GridClientTaskResultBean(org.apache.ignite.internal.processors.rest.client.message.GridClientTaskResultBean) ConnectorMessageInterceptor(org.apache.ignite.configuration.ConnectorMessageInterceptor)

Example 3 with ConnectorMessageInterceptor

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));
        }
    }
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRestTaskRequest(org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest) ConnectorMessageInterceptor(org.apache.ignite.configuration.ConnectorMessageInterceptor) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ConnectorMessageInterceptor (org.apache.ignite.configuration.ConnectorMessageInterceptor)3 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ConnectorConfiguration (org.apache.ignite.configuration.ConnectorConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridClientTaskResultBean (org.apache.ignite.internal.processors.rest.client.message.GridClientTaskResultBean)1 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)1 GridRestTaskRequest (org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest)1 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)1