com/scalagent/kjndi/ksoap/HttpConnection.java

00001 /*
00002  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
00003  * Copyright (C) 2002 - ScalAgent Distributed Technologies
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00018  * USA.
00019  *
00020  * The present code contributor is ScalAgent Distributed Technologies.
00021  *
00022  * Initial developer(s): Nicolas Tachker (ScalAgent)
00023  * Contributor(s):
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     // Create a httpConnection
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         // Transform object in a SoapObject
00073         sO = ConversionSoapHelper.getSoapObject(action,name,object);
00074 
00075         // Send the request and wait the reply
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             //retry to connect to the proxy
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       // Catching an exception because of...
00095       catch (Exception e) {
00096         Exception jE = null;
00097         // ... a broken connection:
00098         if (e instanceof IOException)
00099           jE = new IllegalStateException("Connection is broken.");
00100         // ... an interrupted exchange:
00101         else if (e instanceof InterruptedException)
00102           jE = new InterruptedException("Interrupted request.");
00103         throw jE;
00104       }
00105 
00106       // Transform SoapObject in a reply
00107       Object reply = ConversionSoapHelper.getObject((SoapObject)result);
00108       if (debug) {
00109         System.out.println("JNDI HttpConnection.call : " + 
00110                            action + " reply=" + reply + ")");
00111       }
00112       // Finally, returning the reply:
00113       return reply;
00114     }
00115 
00116 }

Generated on Tue Sep 16 16:14:23 2008 for joram by  doxygen 1.5.0