1 16 17 package sample.amazon.search; 18 19 import org.apache.axis2.Constants; 20 import org.apache.axis2.addressing.AddressingConstants; 21 import org.apache.axis2.addressing.EndpointReference; 22 import org.apache.axis2.clientapi.Call; 23 import org.apache.axis2.context.MessageContext; 24 import org.apache.axis2.description.OperationDescription; 25 import org.apache.axis2.engine.AxisFault; 26 import org.apache.axis2.om.OMOutput; 27 28 import javax.xml.namespace.QName ; 29 import javax.xml.stream.XMLOutputFactory; 30 import javax.xml.stream.XMLStreamException; 31 import java.io.File ; 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 import java.net.MalformedURLException ; 35 import java.net.URL ; 36 import java.util.Properties ; 37 38 46 47 public class AsynchronousClient { 48 49 52 protected static String search = ""; 53 54 57 protected static String prevSearch = ""; 58 59 62 protected static String amazonkey; 63 64 67 protected static Properties prop; 68 69 72 protected static String maxResults = String.valueOf(2); 73 74 77 protected static boolean doSearch = false; 78 79 public static void main(String [] args) { 80 GUIHandler gui; 81 Thread linkThread, guiThread; 82 LinkFollower page; 83 File propertyFile; 84 85 page = new LinkFollower(); LinkFollower.showURL = false; 87 gui = new GUIHandler(); 88 89 90 91 prop = new Properties (); 92 try { 93 String workingDir = System.getProperty("user.dir"); 94 propertyFile = new File (workingDir + File.separator + "samples" + File.separator + 95 "key.properties"); 96 propertyFile.createNewFile(); 97 prop.load(new FileInputStream (propertyFile)); 98 amazonkey = prop.getProperty("amazonKey"); 99 System.out.println("key is " + amazonkey); 100 if (amazonkey == null) { 101 gui.setKey(); 102 } 103 prop = null; 105 } catch (IOException e) { 106 e.printStackTrace(); 107 } 108 gui.buildFrame(); 110 linkThread = new Thread (page); 111 guiThread = new Thread (gui); 112 113 guiThread.start(); 114 linkThread.start(); 115 guiThread.run(); linkThread.run(); } 118 119 122 public AsynchronousClient() { 123 124 } 125 126 136 public static void sendMsg() throws AxisFault { 137 search.trim(); 138 prevSearch = search; 139 Call call = new Call(); 140 URL url = null; 141 try { 142 url = new URL ("http", "soap.amazon.com", "/onca/soap?Service=AlexaWebInfoService"); 143 144 145 146 148 } catch (MalformedURLException e) { 149 e.printStackTrace(); 150 } 151 call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.toString())); 152 MessageContext requestContext = ClientUtil.getMessageContext(); 153 try { 154 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 155 156 System.out.println("Sending the Async message ...."); 157 158 OMOutput omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter 159 (System.out)); 160 requestContext.getEnvelope().serialize(omOutput); 161 omOutput.flush(); 162 163 System.out.println(); 164 QName opName = new QName ("urn:GoogleSearch", "doGoogleSearch"); 165 OperationDescription opdesc = new OperationDescription(opName); 166 call.invokeNonBlocking(opdesc, requestContext, new ClientCallbackHandler()); 167 } catch (AxisFault e1) { 168 e1.printStackTrace(); 169 } catch (XMLStreamException e) { 170 e.printStackTrace(); 171 } 172 System.out.println("Message sent and the client thread is returned...."); 173 } 174 } 175 176 177 178 179 180 | Popular Tags |