PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/example/src/main/java/example/test/Main.java

https://code.google.com/p/gwtrpccommlayer/
Java | 202 lines | 126 code | 31 blank | 45 comment | 0 complexity | 239c36da0d1bebcb5185944145172817 MD5 | raw file
  1/*
  2 * Copyright 2010 Jeff McHugh (Segue Development LLC)
  3 * 
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5 * in compliance with the License. You may obtain a copy of the License at
  6 * 
  7 * http://www.apache.org/licenses/LICENSE-2.0
  8 * 
  9 * Unless required by applicable law or agreed to in writing, software distributed under the License
 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 11 * or implied. See the License for the specific language governing permissions and limitations under
 12 * the License.
 13 */
 14package example.test;
 15
 16import com.google.gwt.user.client.rpc.AsyncCallback;
 17import com.googlecode.gwtrpccommlayer.client.GwtRpcService;
 18import com.googlecode.gwtrpccommlayer.client.impl.GwtRpcCommLayerClient;
 19import example.client.GreetingService;
 20import example.client.GreetingServiceAsync;
 21import example.shared.UserFormData;
 22
 23import java.net.URL;
 24import java.util.ArrayList;
 25
 26public class Main
 27{
 28
 29	public Main()
 30	{
 31	}
 32
 33	public void doAsynchronousCalls() throws Exception
 34	{
 35        GwtRpcService service = GwtRpcService.FACTORY.newInstance();
 36		System.out.println("doAsynchronousCalls --Start--");
 37		
 38		URL url = new URL("http://127.0.0.1:8888/example/greet?gwt.codesvr=127.0.0.1:9997");
 39		//GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url);
 40		
 41		/*
 42		 * NOTE: to make use of asynchronous mode, pass in your GWT asynch class
 43		 */
 44		//GreetingServiceAsync stub = (GreetingServiceAsync) client.createRemoteServicePojoProxy(GreetingServiceAsync.class);
 45        GreetingServiceAsync stub = service.create(url, GreetingServiceAsync.class);
 46		
 47
 48		/*
 49		 * REQUEST 1
 50		 */
 51		UserFormData formData = new UserFormData();
 52		formData.setAccountId("jsmith@gmail.com");
 53		formData.setName("jake smith");
 54		formData.setAge(32);
 55		stub.addUserFormData(formData, new AsyncCallback<String>() 
 56		{
 57			public void onSuccess(String result) 
 58			{
 59				System.out.println("Asynch-Call #1 Result->" + result);
 60			}
 61			public void onFailure(Throwable caught) 
 62			{
 63				System.out.println("Asynch-Call #1 Failure " + caught);
 64			}
 65		});
 66		System.out.println("Executed Asynch-Call #1 ");
 67
 68		/*
 69		 * REQUEST 2
 70		 */
 71		UserFormData formData2 = new UserFormData();
 72		formData2.setAccountId("maryt@gmail.com");
 73		formData2.setName("mary taylor");
 74		formData2.setAge(27);
 75		stub.addUserFormData(formData2, new AsyncCallback<String>() 
 76		{
 77			public void onSuccess(String result) 
 78			{
 79				System.out.println("Asynch-Call #2 Result->" + result);
 80			}
 81			public void onFailure(Throwable caught) 
 82			{
 83				System.out.println("Asynch-Call #2 Failure " + caught);
 84			}
 85		});
 86		System.out.println("Executed Asynch-Call #2 ");
 87		
 88
 89		/*
 90		 * REQUEST 3
 91		 */
 92		stub.getUserFormDataCount(new AsyncCallback<Integer>() 
 93		{
 94			public void onSuccess(Integer result) 
 95			{
 96				System.out.println("Asynch-Call #3 Result->" + result);
 97			}
 98			public void onFailure(Throwable caught) 
 99			{
100				System.out.println("Asynch-Call #3 Failure " + caught);
101			}
102		});
103		System.out.println("Executed Asynch-Call #3 ");
104
105		
106		/*
107		 * REQUEST 4
108		 */
109		stub.getUserFormData(0,1,new AsyncCallback<UserFormData[]>() 
110		{
111			public void onSuccess(UserFormData[] result) 
112			{
113				ArrayList<UserFormData> list = new ArrayList<UserFormData>();
114				list.addAll(java.util.Arrays.asList(result));
115				System.out.println("Asynch-Call #4 Result->" + list);
116			}
117			
118			public void onFailure(Throwable caught) 
119			{
120				System.out.println("Asynch-Call #4 Failure " + caught);
121			}
122		});
123		System.out.println("Executed Asynch-Call #4 ");
124		
125		
126		System.out.println("doAsynchronousCalls --End--");
127	}
128	
129	public void doSynchronousCalls() throws Exception
130	{
131		System.out.println("doSynchronousCalls --Start--");
132		
133		URL url = new URL("http://127.0.0.1:8888/example/greet?gwt.codesvr=127.0.0.1:9997");
134		GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url);
135		GreetingService stub = (GreetingService) client.createRemoteServicePojoProxy(GreetingService.class);
136		
137		
138		/*
139		 * REQUEST 1
140		 */
141		UserFormData formData = new UserFormData();
142		formData.setAccountId("jsmith@gmail.com");
143		formData.setName("jake smith");
144		formData.setAge(32);
145		String resp = stub.addUserFormData(formData);
146		System.out.println("Response 1 ->> " + resp);
147
148		/*
149		 * REQUEST 2
150		 */
151		UserFormData formData2 = new UserFormData();
152		formData2.setAccountId("maryt@gmail.com");
153		formData2.setName("mary taylor");
154		formData2.setAge(27);
155		String resp2 = stub.addUserFormData(formData2);
156		System.out.println("Response 2 ->> " + resp2);
157		
158
159		/*
160		 * REQUEST 3
161		 */
162		Integer resp3 = stub.getUserFormDataCount();
163		System.out.println("Response 3 ->> " + resp3);
164
165		
166		/*
167		 * REQUEST 4
168		 */
169		UserFormData[] resp4 = stub.getUserFormData(0, resp3);
170		ArrayList<UserFormData> list = new ArrayList<UserFormData>();
171		list.addAll(java.util.Arrays.asList(resp4));
172		System.out.println("Response 4 ->> " + list);
173		
174		
175		System.out.println("doSynchronousCalls --End--");
176	}
177	
178	public void run()
179	{
180		try
181		{
182			doSynchronousCalls();
183			System.out.println("");
184			System.out.println("");
185			doAsynchronousCalls();
186		}
187		catch(Exception e)
188		{
189			e.printStackTrace();
190		}
191	}
192	
193	/**
194	 * @param args
195	 */
196	public static void main(String[] args)
197	{
198		Main main = new Main();
199		main.run();
200	}
201
202}