1 16 17 package org.springframework.remoting.caucho; 18 19 import java.io.IOException ; 20 import java.lang.reflect.Constructor ; 21 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import com.caucho.burlap.io.BurlapInput; 27 import com.caucho.burlap.io.BurlapOutput; 28 import com.caucho.burlap.server.BurlapSkeleton; 29 30 import org.springframework.beans.factory.BeanInitializationException; 31 import org.springframework.beans.factory.InitializingBean; 32 import org.springframework.remoting.support.RemoteExporter; 33 import org.springframework.util.Assert; 34 import org.springframework.web.HttpRequestHandler; 35 import org.springframework.web.HttpRequestMethodNotSupportedException; 36 import org.springframework.web.util.NestedServletException; 37 38 60 public class BurlapServiceExporter extends RemoteExporter 61 implements HttpRequestHandler, InitializingBean { 62 63 private BurlapSkeleton skeleton; 64 65 66 public void afterPropertiesSet() { 67 prepare(); 68 } 69 70 73 public void prepare() { 74 try { 75 try { 76 Constructor ctor = BurlapSkeleton.class.getConstructor(new Class [] {Object .class, Class .class}); 78 checkService(); 79 checkServiceInterface(); 80 this.skeleton = (BurlapSkeleton) 81 ctor.newInstance(new Object [] {getProxyForService(), getServiceInterface()}); 82 } 83 catch (NoSuchMethodException ex) { 84 Constructor ctor = BurlapSkeleton.class.getConstructor(new Class [] {Object .class}); 86 this.skeleton = (BurlapSkeleton) ctor.newInstance(new Object [] {getProxyForService()}); 87 } 88 } 89 catch (Exception ex) { 90 throw new BeanInitializationException("Burlap skeleton initialization failed", ex); 91 } 92 } 93 94 95 98 public void handleRequest(HttpServletRequest request, HttpServletResponse response) 99 throws ServletException , IOException { 100 101 Assert.notNull(this.skeleton, "BurlapServiceExporter has not been initialized"); 102 103 if (!"POST".equals(request.getMethod())) { 104 throw new HttpRequestMethodNotSupportedException("POST", 105 "BurlapServiceExporter only supports POST requests"); 106 } 107 108 BurlapInput in = new BurlapInput(request.getInputStream()); 109 BurlapOutput out = new BurlapOutput(response.getOutputStream()); 110 try { 111 this.skeleton.invoke(in, out); 112 } 113 catch (Throwable ex) { 114 throw new NestedServletException("Burlap skeleton invocation failed", ex); 115 } 116 } 117 118 } 119 | Popular Tags |