1 2 package sample.google.search; 3 4 import org.apache.axis2.Constants; 5 import org.apache.axis2.addressing.AddressingConstants; 6 import org.apache.axis2.addressing.EndpointReference; 7 import org.apache.axis2.clientapi.Call; 8 import org.apache.axis2.context.MessageContext; 9 import org.apache.axis2.description.OperationDescription; 10 import org.apache.axis2.engine.AxisFault; 11 import sample.google.common.util.PropertyLoader; 12 13 import javax.xml.namespace.QName ; 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 17 32 33 34 public class AsynchronousClient { 35 36 39 protected String search = ""; 40 41 44 protected String prevSearch = ""; 45 46 49 protected int StartIndex = 0; 50 51 54 protected String key; 55 56 57 protected String maxResults = String.valueOf(10); 58 59 60 private GUIHandler gui; 61 62 63 64 65 public static void main(String [] args) { 66 new AsynchronousClient(); 67 } 68 69 public AsynchronousClient() { 70 71 this.key = PropertyLoader.getGoogleKey(); 72 LinkFollower page = new LinkFollower(); 73 LinkFollower.showURL = false; 74 gui = new GUIHandler(this); 75 gui.buildFrame(); 76 77 Thread linkThread = new Thread (page); 78 linkThread.start(); 79 linkThread.run(); 80 } 81 82 83 public synchronized void sendMsg() throws AxisFault { 84 search.trim(); 85 prevSearch = search; 86 Call call = new Call(); 87 URL url = null; 88 try { 89 url = new URL ("http", "api.google.com", "/search/beta2"); 90 } catch (MalformedURLException e) { 92 e.printStackTrace(); 93 System.exit(0); 94 } 95 96 call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.toString())); 97 98 MessageContext requestContext = ClientUtil.getMessageContext(this); 99 try { 100 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 101 QName opName = new QName ("urn:GoogleSearch", "doGoogleSearch"); 102 OperationDescription opdesc = new OperationDescription(opName); 103 call.invokeNonBlocking(opdesc, requestContext, new ClientCallbackHandler(this.gui)); 105 106 } catch (AxisFault e1) { 107 e1.printStackTrace(); 108 } 109 } 110 111 public String getSearch() { 112 return search; 113 } 114 115 public String getPrevSearch() { 116 return prevSearch; 117 } 118 119 public int getStartIndex() { 120 return StartIndex; 121 } 122 123 public String getKey() { 124 return key; 125 } 126 127 public String getMaxResults() { 128 return maxResults; 129 } 130 131 132 133 public void setSearch(String search) { 134 this.search = search; 135 } 136 137 public void setPrevSearch(String prevSearch) { 138 this.prevSearch = prevSearch; 139 } 140 141 public void setStartIndex(int startIndex) { 142 StartIndex = startIndex; 143 } 144 145 public void setKey(String key) { 146 this.key = key; 147 } 148 149 public void setMaxResults(String maxResults) { 150 this.maxResults = maxResults; 151 } 152 153 154 } 155 156 157 158 | Popular Tags |