org.atmosphere.stomp.handler.StompSendActionAtmosphereHandler Maven / Gradle / Ivy
/*
* Copyright 2014 Jeanfrancois Arcand
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.stomp.handler;
import org.atmosphere.config.managed.Decoder;
import org.atmosphere.config.managed.Encoder;
import org.atmosphere.config.service.Message;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereResourceHeartbeatEventListener;
import org.atmosphere.cpr.Broadcaster;
import org.atmosphere.handler.AbstractReflectorAtmosphereHandler;
import org.atmosphere.stomp.interceptor.FrameInterceptor;
import org.atmosphere.stomp.annotation.StompEndpoint;
import org.atmosphere.stomp.protocol.Action;
import org.atmosphere.stomp.protocol.Header;
import org.atmosphere.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
*
* This handler wraps the method to be invoked when the {@link org.atmosphere.stomp.protocol.Action#SEND send} action is performed
* with a STOMP frame. The frame indicates the particular {@link org.atmosphere.stomp.protocol.Header#DESTINATION destination}
* which is mapped to the appropriate annotated method.
*
*
* @author Guillaume DROUET
* @since 0.1
* @version 1.0
*/
public class StompSendActionAtmosphereHandler
extends AbstractReflectorAtmosphereHandler
implements AtmosphereResourceHeartbeatEventListener {
/**
* Method signature requirement message.
*/
private static final String IAE_MESSAGE = String.format(
"Method can expects as parameter '%s', '%s'. Otherwise it must provides decoders/encoders through the '%s' annotation",
AtmosphereResource.class.getName(),
String.class,
Message.class.getName());
/**
* The logger.
*/
private final Logger logger = LoggerFactory.getLogger(getClass());
/**
* The object which provides the method.
*/
private final Object toProxy;
/**
* The method to invoke.
*/
private final Method method;
/**
* Provide each parameter required to invoke the method.
*/
private final ParamProvider[] paramProviders;
/**
* Optional encoder that converts {@code String} to expected parameter type.
*/
private final Encoder