1 57 package org.apache.soap.providers.com; 58 59 import java.io.* ; 60 import java.util.* ; 61 import java.text.MessageFormat ; 62 import javax.servlet.* ; 63 import javax.servlet.http.* ; 64 import org.apache.soap.* ; 65 import org.apache.soap.rpc.* ; 66 import org.apache.soap.server.* ; 67 import org.apache.soap.util.* ; 68 import java.lang.Math ; 69 70 public class RPCProvider implements Provider 71 { 72 private DeploymentDescriptor dd ; 73 private Envelope envelope ; 74 private Call call ; 75 private String methodName ; 76 private String targetObjectURI ; 77 private HttpServlet servlet ; 78 private HttpSession session ; 79 private byte[] vp= null; 80 private String progid= null; 81 private ServletContext sc= null; 82 private String threadingModel= null; 83 private static boolean initLog= false; 84 85 public void locate( DeploymentDescriptor dd, 86 Envelope env, 87 Call call, 88 String methodName, 89 String targetObjectURI, 90 SOAPContext reqContext) 91 throws SOAPException 92 { 93 HttpServlet servlet = (HttpServlet) reqContext.getProperty( Constants.BAG_HTTPSERVLET ); 94 HttpSession session = (HttpSession) reqContext.getProperty( Constants.BAG_HTTPSESSION ); 95 if(!initLog) 97 { 98 Log.init(servlet); 99 initlog(Log.getLevel()); 100 initLog=true; 101 } 102 103 Log.msg(Log.SUCCESS, "msg.comprovider.inlocate", getClass().getName(), targetObjectURI, methodName ); 104 if( null != dllLoadException) 105 { 106 Log.msg(Log.ERROR, "msg.comprovider.dllfail", dllLoadException ); 107 throw dllLoadException; 108 } 109 110 if (!MessageRouter.validMessage (dd, methodName)) { 112 String msg= 113 Log.msg(Log.ERROR, "msg.comprovider.badMethod", targetObjectURI, methodName); 114 throw new SOAPException (Constants.FAULT_CODE_SERVER, msg); 115 } 116 117 Vector parms= call.getParams(); 118 int noParms= 0; 119 if(parms != null) 120 { 121 vp= new byte[sizeOfVariant * parms.size()]; 122 noParms= parms.size(); 123 } 124 125 for(int i=0; i < noParms; ++i) 126 { 127 Log.msg(Log.INFORMATION, "msg.comprovider.info.parms", new Integer (i), parms.elementAt(i).getClass().getName(), parms.elementAt(i).toString()); 128 objectToVariant( ((Parameter)(parms.elementAt(noParms - i -1))).getValue(), vp, i * sizeOfVariant); 130 } 131 132 Hashtable props = dd.getProps(); 133 134 progid= (String ) props.get("progid"); 135 if(null== progid) 136 { 137 if(targetObjectURI.startsWith("urn:")) 138 { 139 progid= targetObjectURI.substring(4); 140 } 141 else 142 progid= targetObjectURI; 143 } 144 145 threadingModel= (String ) props.get("threadmodel"); 146 if( null == threadingModel) threadingModel= "MULTITHREADED"; 147 Log.msg(Log.INFORMATION, "msg.comprovider.info.cominf", progid, threadingModel ); 148 149 this.dd = dd ; 150 this.envelope = env ; 151 this.call = call ; 152 this.methodName = methodName ; 153 this.targetObjectURI = targetObjectURI ; 154 this.servlet = servlet ; 155 this.session = session ; 156 157 158 } 161 162 public void invoke(SOAPContext reqContext, SOAPContext resContext) 163 throws SOAPException 164 { 165 if( null != dllLoadException) 166 { 167 Log.msg(Log.ERROR, "msg.comprovider.dllfail", dllLoadException ); 168 throw dllLoadException; 169 } 170 if( null == progid) 171 { 172 String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nullprog", methodName, targetObjectURI); 173 throw new SOAPException( Constants.FAULT_CODE_SERVER, msg); 174 } 175 if( null == methodName) 176 { 177 String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nullmname", targetObjectURI); 178 throw new SOAPException( Constants.FAULT_CODE_SERVER, msg); 179 } 180 181 182 183 Object ret= null; 187 try{ 188 ret= invoke( threadingModel, progid, methodName, vp); 189 }catch( Exception e) 190 { 191 String msg= Log.msg(Log.ERROR, "msg.comprovider.error.nativeError", e.toString()); 192 throw new SOAPException( Constants.FAULT_CODE_SERVER, msg); 193 } 194 try { 195 Parameter pret= null; 196 if(ret != null) pret= new Parameter(RPCConstants.ELEM_RETURN , ret.getClass(), ret, null); 197 vp=null; Response resp = new Response( targetObjectURI, call.getMethodName(), pret, null, null, call.getEncodingStyleURI (), resContext ); 206 Envelope env = resp.buildEnvelope(); 207 StringWriter sw = new StringWriter(); 208 env.marshall( sw, call.getSOAPMappingRegistry(), resContext ); 209 resContext.setRootPart( sw.toString(), Constants.HEADERVAL_CONTENT_TYPE_UTF8); 210 } 211 catch( Exception e ) { 212 String msg= Log.msg(Log.ERROR, "msg.comprovider.error.exp", e.toString()); 213 if ( e instanceof SOAPException ) throw (SOAPException ) e ; 214 throw new SOAPException( Constants.FAULT_CODE_SERVER, msg ); 215 } 216 217 Log.msg(Log.SUCCESS, "msg.comprovider.ok", ret == null ? "*null*" : ret.toString() ); 218 } 220 221 static SOAPException dllLoadException= null; static final String libName= "COMProvider"; protected void logit( int level, String msg) { 225 Log.msg(level, msg); 226 } 227 228 229 static final String pname= "org.apache.soap.providers.com"; 230 static final String cname= pname + ".RPCProvider"; 231 static 232 { 233 try 234 { 235 System.loadLibrary (libName); 236 } 237 catch(java.lang.SecurityException e) 238 { 239 dllLoadException= new SOAPException(Constants.FAULT_CODE_SERVER, "SecurityException from " + cname + " loading library:" + libName + " " + e.getMessage(),e); 240 } 241 catch(java.lang.UnsatisfiedLinkError e) 242 { 243 dllLoadException= new SOAPException(Constants.FAULT_CODE_SERVER, "UnsatisfiedLinkError from " + cname + " loading library:" + libName + " " + e.getMessage(),e); 244 } 245 } 247 private static SOAPException getSOAPException( String msg) 248 { 249 return new SOAPException(Constants.FAULT_CODE_SERVER, msg); 250 } 251 252 private native Object invoke(String threadingModel, String progId, String methodName, byte[] parms) throws SOAPException; 253 private static native void initlog(short level); 254 private static native byte[] nativeConvertToBString( String o ); 255 256 257 258 private static final int sizeOfVariant= 16; 259 260 261 private final byte[] objectToVariant( Object o ) throws SOAPException 262 { 263 return objectToVariant( o, null, 0); 264 } 265 private final byte[] objectsToVariants( Object [] o ) throws SOAPException 266 { 267 byte[] bo= new byte[ o.length * sizeOfVariant]; 268 for(int i=0; i < o.length; ++i) 269 objectToVariant( o[i], bo, i * sizeOfVariant); 270 return bo; 271 } 272 private final byte[] objectToVariant( Object o, byte[] bo, int os) throws SOAPException 273 { 274 byte[] v= bo; 275 if( null == v) 276 { 277 v= new byte[sizeOfVariant]; os=0; 279 } 280 281 if( null== o) 282 { v[os+0] = 1; v[os+1] = 0; 285 } 286 else if(o instanceof java.lang.Boolean ) { 288 v[os+0] = 11; v[os+1] = 0; 290 byte x= (byte)( (((Boolean ) o).booleanValue()) ? 0xff: 0); 291 v[os+8]= x; 292 v[os+9]= x; 293 v[os+10]= x; 294 v[os+11]= x; 295 } 296 else if(o instanceof java.lang.Integer ) { 298 v[os+0] = 3; v[os+1] = 0; 300 int x= ((Integer )o).intValue(); 301 v[os+8]= (byte)x; 302 v[os+9]= (byte)((x>>>8) & 0xff); 303 v[os+10]= (byte)((x>>>16) & 0xff); 304 v[os+11]= (byte)((x>>>24) & 0xff); 305 } 306 else if( o instanceof java.lang.String ) 307 { 308 v[os+0] = 8; v[os+1] = 0; 310 byte[] pbs= nativeConvertToBString( (String ) o ); 311 v[os+8]= pbs[0]; 312 v[os+9]= pbs[1]; 313 v[os+10]= pbs[2]; 314 v[os+11]= pbs[3]; 315 } 316 else if(o instanceof java.lang.Long ) { v[os+0] = 5; v[os+1] = 0; 320 long x= Double.doubleToLongBits((double)(((Long )o).longValue())); 321 v[os+8]= (byte)x; 322 v[os+9]= (byte)((x>>>8) & 0xff); 323 v[os+10]= (byte)((x>>>16) & 0xff); 324 v[os+11]= (byte)((x>>>24) & 0xff); 325 v[os+12]= (byte)((x>>>32) & 0xff); 326 v[os+13]= (byte)((x>>>40) & 0xff); 327 v[os+14]= (byte)((x>>>48) & 0xff); 328 v[os+15]= (byte)((x>>>56) & 0xff); 329 } 330 else if(o instanceof java.lang.Short ) 331 { 332 v[os+0] = 2; v[os+1] = 0; 334 int x= ((Short )o).intValue(); 335 v[os+8]= (byte)x; 336 v[os+9]= (byte)((x>>>8) & 0xff); 337 v[os+10]= (byte)((x>>>16) & 0xff); 338 v[os+11]= (byte)((x>>>24) & 0xff); 339 } 340 else if(o instanceof java.lang.Float ) 341 { 342 v[os+0] = 4; v[os+1] = 0; 344 int x= Float.floatToIntBits(((Float )o).floatValue()); 345 v[os+8]= (byte)x; 346 v[os+9]= (byte)((x>>>8) & 0xff); 347 v[os+10]= (byte)((x>>>16) & 0xff); 348 v[os+11]= (byte)((x>>>24) & 0xff); 349 } 350 else if(o instanceof java.lang.Double ) { 352 v[os+0] = 5; v[os+1] = 0; 354 long x= Double.doubleToLongBits(((Double )o).doubleValue()); 355 v[os+8]= (byte)x; 356 v[os+9]= (byte)((x>>>8) & 0xff); 357 v[os+10]= (byte)((x>>>16) & 0xff); 358 v[os+11]= (byte)((x>>>24) & 0xff); 359 v[os+12]= (byte)((x>>>32) & 0xff); 360 v[os+13]= (byte)((x>>>40) & 0xff); 361 v[os+14]= (byte)((x>>>48) & 0xff); 362 v[os+15]= (byte)((x>>>56) & 0xff); 363 } 364 else if(o instanceof java.lang.Byte ) 365 { 366 v[os+0] = 17; v[os+1] = 0; 368 byte x= ((Byte )o).byteValue(); 369 v[os+8]= x; 370 } 371 else if(o instanceof java.lang.Character ) 372 { 373 v[os+0] = 17; v[os+1] = 0; 375 byte x= (byte) ((Character )o).charValue(); 376 v[os+8]= x; 377 } 378 else if(o instanceof java.lang.Void ) 379 { 380 v[os+0] = 1; v[os+1] = 0; 382 } 383 else if( o.getClass().isArray()) 384 { 385 throw new SOAPException(Constants.FAULT_CODE_SERVER, "Currently arrays are unsupported, type received:" + o.getClass().getName()); 388 } 389 else 390 { 391 throw new SOAPException(Constants.FAULT_CODE_SERVER, "Currently unsupported data type received:" + o.getClass().getName()); 392 413 414 } 415 return v; 416 } 417 418 } | Popular Tags |