Changeset 5
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/geniusweb/profilesserver/websocket/ProfilesListSocket.java
r1 r5 45 45 private Session session; 46 46 private Listener<ChangeEvent> changeListener; 47 private static transient String hostport = ""; // cache 47 48 48 49 public ProfilesListSocket() { … … 130 131 private String getIpAddressAndPort() 131 132 throws UnknownHostException, MalformedObjectNameException { 133 synchronized (hostport) { 134 if (hostport.isEmpty()) { 135 MBeanServer beanServer = ManagementFactory 136 .getPlatformMBeanServer(); 132 137 133 MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); 138 Set<ObjectName> objectNames = beanServer.queryNames( 139 new ObjectName("*:type=Connector,*"), 140 Query.match(Query.attr("protocol"), 141 Query.value("HTTP/1.1"))); 134 142 135 Set<ObjectName> objectNames = beanServer.queryNames(136 new ObjectName("*:type=Connector,*"),137 Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));143 String host = InetAddress.getLocalHost().getHostAddress(); 144 String port = objectNames.iterator().next() 145 .getKeyProperty("port"); 138 146 139 String host = InetAddress.getLocalHost().getHostAddress();140 String port = objectNames.iterator().next().getKeyProperty("port");141 142 return host + ":" + port;147 hostport = host + ":" + port; 148 } 149 return hostport; 150 } 143 151 144 152 } -
src/test/java/geniusweb/clienttest/JavaClientTest.java
r3 r5 60 60 @Test 61 61 public void clientSmokeTest() throws IOException { 62 WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000); 63 WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream"); 62 WebSocketFactory factory = new WebSocketFactory() 63 .setConnectionTimeout(5000); 64 WebSocket ws = factory.createSocket( 65 "ws://localhost:8080/profilesserver/websocket/liststream"); 64 66 } 65 67 66 68 @Test 67 public void testGetList() throws IOException, InterruptedException, WebSocketException { 69 public void testGetList() 70 throws IOException, InterruptedException, WebSocketException { 68 71 final List<String> received = new LinkedList<>(); 69 72 Thread.sleep(5000); 70 WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(20000); 71 WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream"); 73 WebSocketFactory factory = new WebSocketFactory() 74 .setConnectionTimeout(20000); 75 WebSocket ws = factory.createSocket( 76 "ws://localhost:8080/profilesserver/websocket/liststream"); 72 77 73 78 ws.addListener(new WebSocketAdapter() { 74 79 @Override 75 public void onTextMessage(WebSocket websocket, String message) throws Exception { 80 public void onTextMessage(WebSocket websocket, String message) 81 throws Exception { 76 82 System.out.println("received message: " + message); 77 83 received.add(message); … … 81 87 assertTrue(ws.isOpen()); 82 88 83 Thread.sleep( 2000);89 Thread.sleep(15000); 84 90 85 91 assertEquals(1, received.size()); // 1 answer received … … 90 96 Map<String, Object> map = mapper.readValue(received.get(0), typeRef); 91 97 92 List<String> domains = new LinkedList<>();93 for (String key : map.keySet()) {98 List<String> domains = new LinkedList<>(); 99 for (String key : map.keySet()) { 94 100 domains.add(key.substring(key.indexOf("get"))); 95 101 } 96 102 assertTrue(domains.contains("get/jobs")); 97 103 assertTrue(domains.contains("get/7issues")); … … 99 105 100 106 @Test 101 public void testExample() throws WebSocketException, InterruptedException, IOException { 107 public void testExample() 108 throws WebSocketException, InterruptedException, IOException { 102 109 DownloadProfileExample test = new DownloadProfileExample(); 103 110 test.run(); … … 106 113 107 114 @Test 108 public void testExample2() throws WebSocketException, InterruptedException, IOException { 115 public void testExample2() 116 throws WebSocketException, InterruptedException, IOException { 109 117 DownloadProfileExample2 test = new DownloadProfileExample2(); 110 118 assertEquals(JOBS1PROFILE, test.getReceived()); … … 119 127 120 128 // Create factory and coerce Jython calculator object 121 JythonObjectFactory factory = new JythonObjectFactory(WebSocketAdapter.class, "PythonDownloadProfile", 129 JythonObjectFactory factory = new JythonObjectFactory( 130 WebSocketAdapter.class, "PythonDownloadProfile", 122 131 "PythonDownloadProfile"); 123 132 factory.createObject();
Note:
See TracChangeset
for help on using the changeset viewer.