1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.remoting.caucho;
  17. import java.lang.reflect.Constructor;
  18. import javax.servlet.ServletException;
  19. import javax.servlet.http.HttpServletRequest;
  20. import javax.servlet.http.HttpServletResponse;
  21. import com.caucho.burlap.io.BurlapInput;
  22. import com.caucho.burlap.io.BurlapOutput;
  23. import com.caucho.burlap.server.BurlapSkeleton;
  24. import org.springframework.remoting.support.RemoteExporter;
  25. import org.springframework.web.servlet.ModelAndView;
  26. import org.springframework.web.servlet.mvc.Controller;
  27. /**
  28. * Web controller that exports the specified service bean as Burlap service
  29. * endpoint, accessible via a Burlap proxy.
  30. *
  31. * <p>Burlap is a slim, XML-based RPC protocol.
  32. * For information on Burlap, see the
  33. * <a href="http://www.caucho.com/burlap">Burlap website</a>
  34. *
  35. * <p>This exporter will work with both Burlap 2.x and 3.x (respectively
  36. * Resin 2.x and 3.x), auto-detecting the corresponding skeleton class.
  37. *
  38. * <p>Note: Burlap services exported with this class can be accessed by
  39. * any Burlap client, as there isn't any special handling involved.
  40. *
  41. * @author Juergen Hoeller
  42. * @since 13.05.2003
  43. * @see BurlapProxyFactoryBean
  44. */
  45. public class BurlapServiceExporter extends RemoteExporter implements Controller {
  46. private BurlapSkeleton skeleton;
  47. public void afterPropertiesSet() throws Exception {
  48. super.afterPropertiesSet();
  49. try {
  50. // try Burlap 3.x (with service interface argument)
  51. Constructor ctor = BurlapSkeleton.class.getConstructor(new Class[] {Object.class, Class.class});
  52. this.skeleton = (BurlapSkeleton) ctor.newInstance(new Object[] {getService(), getServiceInterface()});
  53. }
  54. catch (NoSuchMethodException ex) {
  55. // fall back to Burlap 2.x (without service interface argument)
  56. Constructor ctor = BurlapSkeleton.class.getConstructor(new Class[] {Object.class});
  57. this.skeleton = (BurlapSkeleton) ctor.newInstance(new Object[] {getProxyForService()});
  58. }
  59. }
  60. /**
  61. * Process the incoming Burlap request and create a Burlap response.
  62. */
  63. public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
  64. BurlapInput in = new BurlapInput(request.getInputStream());
  65. BurlapOutput out = new BurlapOutput(response.getOutputStream());
  66. try {
  67. this.skeleton.invoke(in, out);
  68. }
  69. catch (Exception ex) {
  70. throw ex;
  71. }
  72. catch (Error ex) {
  73. throw ex;
  74. }
  75. catch (Throwable ex) {
  76. throw new ServletException(ex);
  77. }
  78. return null;
  79. }
  80. }