KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > google > search > AsynchronousClient


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 JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 /*
18 * Copyright 2001-2004 The Apache Software Foundation.
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */

32
33
34 public class AsynchronousClient {
35
36     /**
37      * Query parameter
38      */

39     protected String JavaDoc search = "";
40
41     /**
42      * Query parameters sent with the last request
43      */

44     protected String JavaDoc prevSearch = "";
45
46     /**
47      * Have to increase and set the start index when asking for more results
48      */

49     protected int StartIndex = 0;
50
51     /**
52      * License key
53      */

54     protected String JavaDoc key;
55
56     /** maximum results per page */
57     protected String JavaDoc maxResults = String.valueOf(10);
58
59
60     private GUIHandler gui;
61
62
63
64
65     public static void main(String JavaDoc[] 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 JavaDoc linkThread = new Thread JavaDoc(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 JavaDoc url = null;
88         try {
89                 url = new URL JavaDoc("http", "api.google.com", "/search/beta2");
90           // url = new URL("http://127.0.0.1:8080/axis2/services/axisversion/viewVersion");
91
} catch (MalformedURLException JavaDoc 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 JavaDoc opName = new QName JavaDoc("urn:GoogleSearch", "doGoogleSearch");
102             OperationDescription opdesc = new OperationDescription(opName);
103          // OperationDescription opdesc = new OperationDescription(new QName("viewVersion"));
104
call.invokeNonBlocking(opdesc, requestContext, new ClientCallbackHandler(this.gui));
105
106         } catch (AxisFault e1) {
107             e1.printStackTrace();
108         }
109     }
110
111     public String JavaDoc getSearch() {
112         return search;
113     }
114
115     public String JavaDoc getPrevSearch() {
116         return prevSearch;
117     }
118
119     public int getStartIndex() {
120         return StartIndex;
121     }
122
123     public String JavaDoc getKey() {
124         return key;
125     }
126
127     public String JavaDoc getMaxResults() {
128         return maxResults;
129     }
130
131
132
133     public void setSearch(String JavaDoc search) {
134         this.search = search;
135     }
136
137     public void setPrevSearch(String JavaDoc prevSearch) {
138         this.prevSearch = prevSearch;
139     }
140
141     public void setStartIndex(int startIndex) {
142         StartIndex = startIndex;
143     }
144
145     public void setKey(String JavaDoc key) {
146         this.key = key;
147     }
148
149     public void setMaxResults(String JavaDoc maxResults) {
150         this.maxResults = maxResults;
151     }
152
153
154 }
155
156
157
158
Popular Tags