1 package samples.transport ; 2 3 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Message; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.handlers.BasicHandler; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.util.Date ; 28 29 30 39 40 public class FileSender extends BasicHandler { 41 static int nextNum = 1 ; 42 43 public void invoke(MessageContext msgContext) throws AxisFault { 44 Message msg = msgContext.getRequestMessage(); 45 byte[] buf = (byte[]) msg.getSOAPPartAsBytes(); 46 boolean timedOut = false; 47 try { 48 FileOutputStream fos = new FileOutputStream ( "xml" + nextNum + ".req" ); 49 50 fos.write( buf ); 51 fos.close(); 52 } 53 catch( Exception e ) { 54 e.printStackTrace(); 55 } 56 57 long timeout = Long.MAX_VALUE; 58 if (msgContext.getTimeout()!=0) 59 timeout=(new Date ()).getTime()+msgContext.getTimeout(); 60 61 for (; timedOut == false;) { 62 try { 63 Thread.sleep( 100 ); 64 File file = new File ( "xml" + nextNum + ".res" ); 65 66 if ((new Date ().getTime())>=timeout) 67 timedOut = true; 68 69 if ( !file.exists() ) continue ; 70 Thread.sleep( 100 ); FileInputStream fis = new FileInputStream ( "xml" + nextNum + ".res" ); 72 msg = new Message( fis ); 73 msg.getSOAPPartAsBytes(); fis.close(); 75 Thread.sleep( 100 ); 76 (new File ("xml" + nextNum + ".res")).delete(); 77 msgContext.setResponseMessage( msg ); 78 break ; 79 } 80 catch( Exception e ) { 81 } 83 } 84 nextNum++ ; 85 if (timedOut) 86 throw new AxisFault("timeout"); 87 88 } 89 } 90 | Popular Tags |