1 25 package com.scalagent.kjndi.ksoap; 26 27 import java.io.IOException ; 28 import java.io.InterruptedIOException ; 29 30 import com.scalagent.ksoap.*; 31 32 36 public class HttpConnection { 37 38 39 protected HttpTransport httpConnect; 40 41 protected String serverUrl; 42 43 protected boolean debug = false; 44 45 protected boolean compress = false; 46 47 48 public HttpConnection(String serverUrl) { 49 this.serverUrl = serverUrl; 50 51 httpConnect = new HttpTransport(serverUrl,"ProxyService"); 53 } 54 55 61 public Object call(String action, String name, Object object) throws Exception { 62 SoapObject sO; 63 Object result = null; 64 65 try { 66 httpConnect.reset(); 67 68 if (debug) { 69 System.out.println("JNDI HttpConnection.call(" + action + "," + object + ")"); 70 } 71 72 sO = ConversionSoapHelper.getSoapObject(action,name,object); 74 75 int timer=1; 77 while (true) { 78 try { 79 result = httpConnect.call(sO); 80 break; 81 } catch (InterruptedIOException iIOE) { 82 } catch (IOException ioE) { 83 ioE.printStackTrace(); 84 System.out.println("JNDI timer=" + timer); 86 timer++; 87 Thread.sleep(timer*1000); 88 if (timer > 1) 89 break; 90 timer++; 91 } 92 } 93 } 94 catch (Exception e) { 96 Exception jE = null; 97 if (e instanceof IOException ) 99 jE = new IllegalStateException ("Connection is broken."); 100 else if (e instanceof InterruptedException ) 102 jE = new InterruptedException ("Interrupted request."); 103 throw jE; 104 } 105 106 Object reply = ConversionSoapHelper.getObject((SoapObject)result); 108 if (debug) { 109 System.out.println("JNDI HttpConnection.call : " + 110 action + " reply=" + reply + ")"); 111 } 112 return reply; 114 } 115 116 } 117 | Popular Tags |