001/*
002 * Copyright 2002-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.remoting.caucho;
018
019import java.io.IOException;
020import javax.servlet.ServletException;
021import javax.servlet.http.HttpServletRequest;
022import javax.servlet.http.HttpServletResponse;
023
024import org.springframework.web.HttpRequestHandler;
025import org.springframework.web.HttpRequestMethodNotSupportedException;
026import org.springframework.web.util.NestedServletException;
027
028/**
029 * Servlet-API-based HTTP request handler that exports the specified service bean
030 * as Hessian service endpoint, accessible via a Hessian proxy.
031 *
032 * <p><b>Note:</b> Spring also provides an alternative version of this exporter,
033 * for Sun's JRE 1.6 HTTP server: {@link SimpleHessianServiceExporter}.
034 *
035 * <p>Hessian is a slim, binary RPC protocol.
036 * For information on Hessian, see the
037 * <a href="http://hessian.caucho.com">Hessian website</a>.
038 * <b>Note: As of Spring 4.0, this exporter requires Hessian 4.0 or above.</b>
039 *
040 * <p>Hessian services exported with this class can be accessed by
041 * any Hessian client, as there isn't any special handling involved.
042 *
043 * @author Juergen Hoeller
044 * @since 13.05.2003
045 * @see HessianClientInterceptor
046 * @see HessianProxyFactoryBean
047 * @see org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter
048 * @see org.springframework.remoting.rmi.RmiServiceExporter
049 */
050public class HessianServiceExporter extends HessianExporter implements HttpRequestHandler {
051
052        /**
053         * Processes the incoming Hessian request and creates a Hessian response.
054         */
055        @Override
056        public void handleRequest(HttpServletRequest request, HttpServletResponse response)
057                        throws ServletException, IOException {
058
059                if (!"POST".equals(request.getMethod())) {
060                        throw new HttpRequestMethodNotSupportedException(request.getMethod(),
061                                        new String[] {"POST"}, "HessianServiceExporter only supports POST requests");
062                }
063
064                response.setContentType(CONTENT_TYPE_HESSIAN);
065                try {
066                        invoke(request.getInputStream(), response.getOutputStream());
067                }
068                catch (Throwable ex) {
069                        throw new NestedServletException("Hessian skeleton invocation failed", ex);
070                }
071        }
072
073}