1 48 49 package com.caucho.burlap.server; 50 51 import com.caucho.burlap.io.BurlapInput; 52 import com.caucho.burlap.io.BurlapOutput; 53 import com.caucho.services.server.AbstractSkeleton; 54 import com.caucho.services.server.ServiceContext; 55 56 import java.lang.reflect.InvocationTargetException ; 57 import java.lang.reflect.Method ; 58 59 62 public class BurlapSkeleton extends AbstractSkeleton { 63 private Object _service; 64 65 71 public BurlapSkeleton(Object service, Class apiClass) 72 { 73 super(apiClass); 74 75 _service = service; 76 } 77 78 84 public void invoke(BurlapInput in, BurlapOutput out) 85 throws Throwable 86 { 87 in.readCall(); 88 89 ServiceContext context = ServiceContext.getContext(); 90 91 String header; 92 while ((header = in.readHeader()) != null) { 93 Object value = in.readObject(); 94 95 context.addHeader(header, value); 96 } 97 98 String methodName = in.readMethod(); 99 Method method = getMethod(methodName); 100 101 if (method != null) { 102 } 103 else if ("_burlap_getAttribute".equals(in.getMethod())) { 104 String attrName = in.readString(); 105 in.completeCall(); 106 107 String value = null; 108 109 if ("java.api.class".equals(attrName)) 110 value = getAPIClassName(); 111 else if ("java.home.class".equals(attrName)) 112 value = getHomeClassName(); 113 else if ("java.object.class".equals(attrName)) 114 value = getObjectClassName(); 115 116 out.startReply(); 117 118 out.writeObject(value); 119 120 out.completeReply(); 121 return; 122 } 123 else if (method == null) { 124 out.startReply(); 125 out.writeFault("NoSuchMethodException", 126 "The service has no method named: " + in.getMethod(), 127 null); 128 out.completeReply(); 129 return; 130 } 131 132 Class []args = method.getParameterTypes(); 133 Object []values = new Object [args.length]; 134 135 for (int i = 0; i < args.length; i++) 136 values[i] = in.readObject(args[i]); 137 138 in.completeCall(); 139 140 Object result = null; 141 142 try { 143 result = method.invoke(_service, values); 144 } catch (Throwable e) { 145 if (e instanceof InvocationTargetException ) 146 e = ((InvocationTargetException ) e).getTargetException(); 147 out.startReply(); 148 out.writeFault("ServiceException", e.getMessage(), e); 149 out.completeReply(); 150 return; 151 } 152 153 out.startReply(); 154 155 out.writeObject(result); 156 157 out.completeReply(); 158 } 159 } 160 | Popular Tags |