All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rribbit.processing.SpringHttpRequestProcessorServlet Maven / Gradle / Ivy

Go to download

RRiBbit is an Open Source Java application framework that eliminates dependencies and simplifies code structure. It can be used as an Eventbus, but improves upon this by being compatible with existing code and allowing bidirectional communication between components. It also supports Remoting, so that you can use Eventbuses that run on other machines, complete with failover, loadbalancing and SSL/TLS support.

There is a newer version: 8.0.0
Show newest version
/**
 * Copyright (C) 2012-2018 RRiBbit.org
 *
 * 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.rribbit.processing;

import org.rribbit.execution.ListenerObjectExecutor;
import org.rribbit.retrieval.ListenerObjectRetriever;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * This implementation of {@link HttpRequestProcessorServlet} tries to retrieve a {@link ListenerObjectRetriever} and a {@link ListenerObjectExecutor} from the
 * Spring {@link WebApplicationContext}, if one is available. Use this class if you use Spring in combination with RRiBbit HTTP remoting. Then, you only have to wire up a
 * {@link ListenerObjectRetriever} and a {@link ListenerObjectExecutor} in your {@link ApplicationContext} and declare this class in your web.xml and the server side is done.
 *
 * @author G.J. Schouten
 *
 */
public class SpringHttpRequestProcessorServlet extends HttpRequestProcessorServlet {

	private static final Logger log = LoggerFactory.getLogger(SpringHttpRequestProcessorServlet.class);

	protected ListenerObjectRetriever listenerObjectRetriever;
	protected ListenerObjectExecutor listenerObjectExecutor;

	@Override
	protected ListenerObjectRetriever createListenerObjectRetriever() {
		return listenerObjectRetriever;
	}

	@Override
	protected ListenerObjectExecutor createListenerObjectExecutor() {
		return listenerObjectExecutor;
	}

	@Override
	public void init() {

		log.info("Retrieving WebApplicationContext from ServletContext and getting ListenerObjectRetriever and ListenerObjectExecutor");

		//First, retrieve the WebApplicationContext via the Servlet Container and get the ListenerObjectRetriever and ListenerObjectExecutor
		WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
		listenerObjectRetriever = ctx.getBean(ListenerObjectRetriever.class);
		listenerObjectExecutor = ctx.getBean(ListenerObjectExecutor.class);

		//Then call super, which in turn calls the createListenerObjectRetriever() and createListenerObjectExecutor() methods
		super.init();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy