001/*
002 * Copyright 2002-2014 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.ByteArrayOutputStream;
020import java.io.IOException;
021
022import com.sun.net.httpserver.HttpExchange;
023import com.sun.net.httpserver.HttpHandler;
024
025import org.springframework.lang.UsesSunHttpServer;
026import org.springframework.util.FileCopyUtils;
027
028/**
029 * HTTP request handler that exports the specified service bean as
030 * Burlap service endpoint, accessible via a Burlap proxy.
031 * Designed for Sun's JRE 1.6 HTTP server, implementing the
032 * {@link com.sun.net.httpserver.HttpHandler} interface.
033 *
034 * <p>Burlap is a slim, XML-based RPC protocol.
035 * For information on Burlap, see the
036 * <a href="https://www.caucho.com/burlap">Burlap website</a>.
037 * This exporter requires Burlap 3.x.
038 *
039 * <p>Note: Burlap services exported with this class can be accessed by
040 * any Burlap client, as there isn't any special handling involved.
041 *
042 * @author Juergen Hoeller
043 * @since 2.5.1
044 * @see org.springframework.remoting.caucho.BurlapClientInterceptor
045 * @see org.springframework.remoting.caucho.BurlapProxyFactoryBean
046 * @see SimpleHessianServiceExporter
047 * @see org.springframework.remoting.httpinvoker.SimpleHttpInvokerServiceExporter
048 * @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
049 * and is effectively retired (in contrast to its sibling Hessian)
050 */
051@Deprecated
052@UsesSunHttpServer
053public class SimpleBurlapServiceExporter extends BurlapExporter implements HttpHandler {
054
055        /**
056         * Processes the incoming Burlap request and creates a Burlap response.
057         */
058        @Override
059        public void handle(HttpExchange exchange) throws IOException {
060                if (!"POST".equals(exchange.getRequestMethod())) {
061                        exchange.getResponseHeaders().set("Allow", "POST");
062                        exchange.sendResponseHeaders(405, -1);
063                        return;
064                }
065
066                ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
067                try {
068                        invoke(exchange.getRequestBody(), output);
069                }
070                catch (Throwable ex) {
071                        exchange.sendResponseHeaders(500, -1);
072                        logger.error("Burlap skeleton invocation failed", ex);
073                }
074
075                exchange.sendResponseHeaders(200, output.size());
076                FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody());
077        }
078
079}