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.server.AxisServer; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileNotFoundException ; 27 import java.io.FileOutputStream ; 28 29 35 public class FileReader extends Thread { 36 static int nextNum = 1 ; 37 boolean pleaseStop = false ; 38 boolean halted = false ; 39 40 public void run() { 41 AxisServer server = new AxisServer(); 42 server.init(); 43 44 while( !pleaseStop ) { 45 try { 46 Thread.sleep( 100 ); 47 File file = new File ( "xml" + nextNum + ".req" ); 48 if ( !file.exists() ) continue ; 49 50 if (pleaseStop) continue; 52 53 Thread.sleep( 100 ); FileInputStream fis = new FileInputStream ( file ); 55 56 int thisNum = nextNum++; 58 Message msg = new Message( fis ); 59 msg.getSOAPPartAsBytes(); 60 61 fis.close(); 62 file.delete(); 63 64 MessageContext msgContext = new MessageContext(server); 65 msgContext.setRequestMessage( msg ); 66 67 try { 68 server.invoke( msgContext ); 69 msg = msgContext.getResponseMessage(); 70 } catch (AxisFault af) { 71 msg = new Message(af); 72 msg.setMessageContext(msgContext); 73 } catch (Exception e) { 74 msg = new Message(new AxisFault(e.toString())); 75 msg.setMessageContext(msgContext); 76 } 77 78 byte[] buf = msg.getSOAPPartAsBytes(); 79 FileOutputStream fos = new FileOutputStream ( "xml" + thisNum + ".res" ); 80 fos.write( buf ); 81 fos.close(); 82 } 83 catch( Exception e ) { 84 if ( !(e instanceof FileNotFoundException ) ) 85 e.printStackTrace(); 86 } 87 } 88 89 halted = true; 90 System.out.println("FileReader halted."); 91 } 92 93 public void halt() { 94 pleaseStop = true ; 95 while (!halted) { 96 try { 97 Thread.sleep(100); 98 } catch (InterruptedException ie) { 99 break; 100 } 101 } 102 } 103 } 104 | Popular Tags |