mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 12:45:35 +00:00
first successful web socket connect to Igtimi
This commit is contained in:
+3
-2
@@ -21,6 +21,7 @@ import org.xml.sax.SAXException;
|
||||
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.igtimiadapter.Account;
|
||||
import com.sap.sailing.domain.igtimiadapter.Client;
|
||||
import com.sap.sailing.domain.igtimiadapter.IgtimiConnection;
|
||||
import com.sap.sailing.domain.igtimiadapter.IgtimiConnectionFactory;
|
||||
import com.sap.sailing.domain.igtimiadapter.Permission;
|
||||
@@ -40,7 +41,7 @@ public class SignInTest {
|
||||
ParserConfigurationException, SAXException, ClassNotFoundException, InstantiationException,
|
||||
IllegalAccessException, ClassCastException, ParseException {
|
||||
// use the credentials of "Another Test App"
|
||||
final ClientImpl testAppClient = new ClientImpl("7fcdd217e0aa16090edb4ad55b09ec43b2021090e209541fc9b7003c2a2b70c6",
|
||||
final Client testAppClient = new ClientImpl("7fcdd217e0aa16090edb4ad55b09ec43b2021090e209541fc9b7003c2a2b70c6",
|
||||
"aa569cf4909bdc7b0e04b11873f3c4ea20687421e010fcc25b771cca9e6f3f9a", "http://127.0.0.1:8888/igtimi/oauth/v1/authorizationcallback");
|
||||
final IgtimiConnectionFactoryImpl igtimiConnectionFactory = new IgtimiConnectionFactoryImpl(testAppClient);
|
||||
final String code = igtimiConnectionFactory.authorizeAndReturnAuthorizedCode("axel.uhl@gmx.de", "123456");
|
||||
@@ -55,7 +56,7 @@ public class SignInTest {
|
||||
IllegalStateException, ParserConfigurationException, SAXException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException, ClassCastException {
|
||||
// use the credentials of "Another Test App"
|
||||
final ClientImpl testAppClient = new ClientImpl("a4cecd8593e12d43a03433a6db0eea243a411749f93c278dce6a26d4804eebd2",
|
||||
final Client testAppClient = new ClientImpl("a4cecd8593e12d43a03433a6db0eea243a411749f93c278dce6a26d4804eebd2",
|
||||
"4d66022d1ec3e2991f8053514495b61cc076ff02d664f0dc8f3df9150c3864ef", "http://1.2.3.4");
|
||||
final String code = new IgtimiConnectionFactoryImpl(testAppClient).authorizeAndReturnAuthorizedCode("axel.uhl@gmx.de", "123456");
|
||||
logger.info("Igtimi OAuth code is "+code);
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.sap.sailing.domain.igtimiadapter.websocket;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.igtimiadapter.Client;
|
||||
import com.sap.sailing.domain.igtimiadapter.impl.ClientImpl;
|
||||
import com.sap.sailing.domain.igtimiadapter.impl.IgtimiConnectionFactoryImpl;
|
||||
|
||||
public class WebSocketTest {
|
||||
@Test
|
||||
public void testWebSocketConnect() throws Exception {
|
||||
final Client client = new ClientImpl("7fcdd217e0aa16090edb4ad55b09ec43b2021090e209541fc9b7003c2a2b70c6",
|
||||
"aa569cf4909bdc7b0e04b11873f3c4ea20687421e010fcc25b771cca9e6f3f9a", "http://127.0.0.1:8888/igtimi/oauth/v1/authorizationcallback");
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(new IgtimiConnectionFactoryImpl(client));
|
||||
manager.connect();
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,18 @@ Require-Bundle: org.json.simple;bundle-version="1.1.0",
|
||||
org.apache.httpcomponents.httpclient;bundle-version="4.2.5",
|
||||
org.apache.httpcomponents.httpcore;bundle-version="4.0.0",
|
||||
org.apache.commons.logging;bundle-version="1.1.1",
|
||||
com.sap.sailing.domain.common,
|
||||
org.eclipse.jetty.websocket.client;bundle-version="9.0.4"
|
||||
com.sap.sailing.domain.common
|
||||
Import-Package: javax.ws.rs;version="1.1.1",
|
||||
javax.ws.rs.core;version="1.1.1",
|
||||
javax.ws.rs.ext;version="1.1.1",
|
||||
org.apache.commons.lang,
|
||||
org.eclipse.jetty.io;version="9.0.0",
|
||||
org.eclipse.jetty.util.component;version="9.0.4",
|
||||
org.eclipse.jetty.websocket.api;version="9.0.0",
|
||||
org.eclipse.jetty.websocket.api.annotations;version="9.0.0",
|
||||
org.eclipse.jetty.websocket.api.extensions;version="9.0.0",
|
||||
org.eclipse.jetty.websocket.client;version="9.0.0",
|
||||
org.eclipse.jetty.websocket.common;version="9.0.0",
|
||||
org.osgi.framework;version="1.7.0"
|
||||
Web-ContextPath: /igtimi
|
||||
Bundle-Activator: com.sap.sailing.domain.igtimiadapter.impl.Activator
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.sap.sailing.domain.igtimiadapter.websocket;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
|
||||
@WebSocket
|
||||
public class LiveDataWebSocket implements WebSocketListener {
|
||||
@Override
|
||||
public void onWebSocketBinary(byte[] payload, int offset, int len) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketClose(int statusCode, String reason) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketConnect(Session session) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketError(Throwable cause) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWebSocketText(String message) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.sap.sailing.domain.igtimiadapter.websocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
|
||||
import com.sap.sailing.domain.igtimiadapter.IgtimiConnectionFactory;
|
||||
|
||||
public class WebSocketConnectionManager {
|
||||
private static final Logger logger = Logger.getLogger(WebSocketConnectionManager.class.getName());
|
||||
private final IgtimiConnectionFactory connectionFactory;
|
||||
|
||||
public WebSocketConnectionManager(IgtimiConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public void connect() throws Exception {
|
||||
WebSocketClient client = new WebSocketClient();
|
||||
client.start();
|
||||
LiveDataWebSocket socket = new LiveDataWebSocket();
|
||||
ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||
IOException lastException = null;
|
||||
for (URI uri : connectionFactory.getWebsocketServers()) {
|
||||
try {
|
||||
logger.log(Level.INFO, "Trying to connect to "+uri);
|
||||
client.connect(socket, uri, request);
|
||||
logger.log(Level.INFO, "Successfully connected to "+uri);
|
||||
lastException = null;
|
||||
break; // successfully connected
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.INFO, "Couldn't connect to "+uri, e);
|
||||
lastException = e;
|
||||
}
|
||||
}
|
||||
if (lastException != null) {
|
||||
throw lastException;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user