00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package com.scalagent.kjndi.ksoap;
00026
00027 import java.io.IOException;
00028 import java.io.InterruptedIOException;
00029
00030 import com.scalagent.ksoap.*;
00031
00036 public class HttpConnection {
00037
00039 protected HttpTransport httpConnect;
00041 protected String serverUrl;
00043 protected boolean debug = false;
00045 protected boolean compress = false;
00046
00047
00048 public HttpConnection(String serverUrl) {
00049 this.serverUrl = serverUrl;
00050
00051
00052 httpConnect = new HttpTransport(serverUrl,"ProxyService");
00053 }
00054
00061 public Object call(String action, String name, Object object) throws Exception {
00062 SoapObject sO;
00063 Object result = null;
00064
00065 try {
00066 httpConnect.reset();
00067
00068 if (debug) {
00069 System.out.println("JNDI HttpConnection.call(" + action + "," + object + ")");
00070 }
00071
00072
00073 sO = ConversionSoapHelper.getSoapObject(action,name,object);
00074
00075
00076 int timer=1;
00077 while (true) {
00078 try {
00079 result = httpConnect.call(sO);
00080 break;
00081 } catch (InterruptedIOException iIOE) {
00082 } catch (IOException ioE) {
00083 ioE.printStackTrace();
00084
00085 System.out.println("JNDI timer=" + timer);
00086 timer++;
00087 Thread.sleep(timer*1000);
00088 if (timer > 1)
00089 break;
00090 timer++;
00091 }
00092 }
00093 }
00094
00095 catch (Exception e) {
00096 Exception jE = null;
00097
00098 if (e instanceof IOException)
00099 jE = new IllegalStateException("Connection is broken.");
00100
00101 else if (e instanceof InterruptedException)
00102 jE = new InterruptedException("Interrupted request.");
00103 throw jE;
00104 }
00105
00106
00107 Object reply = ConversionSoapHelper.getObject((SoapObject)result);
00108 if (debug) {
00109 System.out.println("JNDI HttpConnection.call : " +
00110 action + " reply=" + reply + ")");
00111 }
00112
00113 return reply;
00114 }
00115
00116 }