001/* 002 * Copyright 2002-2018 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; 020 021import javax.servlet.ServletException; 022import javax.servlet.http.HttpServletRequest; 023import javax.servlet.http.HttpServletResponse; 024 025import org.springframework.web.HttpRequestHandler; 026import org.springframework.web.HttpRequestMethodNotSupportedException; 027import org.springframework.web.util.NestedServletException; 028 029/** 030 * Servlet-API-based HTTP request handler that exports the specified service bean 031 * as Hessian service endpoint, accessible via a Hessian proxy. 032 * 033 * <p>Hessian is a slim, binary RPC protocol. 034 * For information on Hessian, see the 035 * <a href="http://hessian.caucho.com">Hessian website</a>. 036 * <b>Note: As of Spring 4.0, this exporter requires Hessian 4.0 or above.</b> 037 * 038 * <p>Hessian services exported with this class can be accessed by 039 * any Hessian client, as there isn't any special handling involved. 040 * 041 * @author Juergen Hoeller 042 * @since 13.05.2003 043 * @see HessianClientInterceptor 044 * @see HessianProxyFactoryBean 045 * @see org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter 046 * @see org.springframework.remoting.rmi.RmiServiceExporter 047 */ 048public class HessianServiceExporter extends HessianExporter implements HttpRequestHandler { 049 050 /** 051 * Processes the incoming Hessian request and creates a Hessian response. 052 */ 053 @Override 054 public void handleRequest(HttpServletRequest request, HttpServletResponse response) 055 throws ServletException, IOException { 056 057 if (!"POST".equals(request.getMethod())) { 058 throw new HttpRequestMethodNotSupportedException(request.getMethod(), 059 new String[] {"POST"}, "HessianServiceExporter only supports POST requests"); 060 } 061 062 response.setContentType(CONTENT_TYPE_HESSIAN); 063 try { 064 invoke(request.getInputStream(), response.getOutputStream()); 065 } 066 catch (Throwable ex) { 067 throw new NestedServletException("Hessian skeleton invocation failed", ex); 068 } 069 } 070 071}