source: src/test/java/geniusweb/examples/DownloadProfileExample.java@ 44

Last change on this file since 44 was 43, checked in by ruud, 21 months ago

Fixed small issues in domaineditor.

File size: 1.8 KB
RevLine 
[43]1package geniusweb.examples;
2
3import java.io.IOException;
4import java.net.URI;
5
6import javax.websocket.ClientEndpoint;
7import javax.websocket.ContainerProvider;
8import javax.websocket.DeploymentException;
9import javax.websocket.OnError;
10import javax.websocket.OnMessage;
11import javax.websocket.OnOpen;
12import javax.websocket.Session;
13import javax.websocket.WebSocketContainer;
14
15/**
16 * This example shows how a client can download a profile from the
17 * profileserver. It uses the annotation-based javax.websocket mechanism. It
18 * assumes that the server is up and running on localhost:8080/profilesserver.
19 * We're a bit lazy here and give this example class also the annothation
20 * "@ClientEndpoint" to avoid having to create a separate class containing the
21 * actual endpoint.
22 */
23@ClientEndpoint
24public class DownloadProfileExample {
25
26 // this must be static because connectToServer will create new instance.
27 private static String received = "";
28
29 public DownloadProfileExample() {
30 }
31
32 @OnOpen
33 public void onOpen(Session session) {
34 System.out.println("Connected to endpoint: " + session);
35 }
36
37 @OnMessage
38 public void processMessage(String message) {
39 System.out.println("Received message in client: " + message);
40 received = message;
41 }
42
43 @OnError
44 public void processError(Throwable t) {
45 t.printStackTrace();
46 }
47
48 public void run() throws InterruptedException, IOException {
49 try {
50 WebSocketContainer container = ContainerProvider.getWebSocketContainer();
51 String uri = "ws://localhost:8080/profilesserver/websocket/get/jobs/jobs1";
52 System.out.println("Connecting to " + uri);
53 container.connectToServer(DownloadProfileExample.class, URI.create(uri));
54 Thread.sleep(2000);
55 } catch (DeploymentException | IOException ex) {
56 ex.printStackTrace();
57 }
58
59 }
60
61 public String getReceived() {
62 return received;
63 }
64
65}
Note: See TracBrowser for help on using the repository browser.