Skip to content
This repository was archived by the owner on Sep 21, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import javax.xml.bind.DatatypeConverter;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -56,54 +59,9 @@ public JsonElement serialize(Date date, Type type, JsonSerializationContext ctx)
*/
public static Date deserialize(String strVal) throws ParseException {

String s;

if(strVal.contains("+00:00")){
strVal = strVal.replace("+00:00", "");
}

if(strVal.length() == 19){// adapt from format yyyy-MM-ddTHH:mm:dd
s = strVal + ".+00:00";
}else if(strVal.contains(".Z")){
// Change .Z to +00:00 to adapt the string to a format
// that can be parsed in Java
s = strVal.replace(".Z", ".+00:00");
}else{
// Change Z to +00:00 to adapt the string to a format
// that can be parsed in Java
s = strVal.replace("Z", ".+00:00");
}

try {
// Remove the ":" character to adapt the string to a
// format
// that can be parsed in Java

if (s.length() > THREE_MILLISECONDS_DATE_FORMAT_LENGTH) { // yyyy-MM-ddTHH:mm:dd.SSS+00:00
// remove the extra milliseconds characters
s = s.substring(0, 23) + s.substring(s.length() - 6);
} else if (s.length() < THREE_MILLISECONDS_DATE_FORMAT_LENGTH) {
// add extra milliseconds characters
int dif = (THREE_MILLISECONDS_DATE_FORMAT_LENGTH - s.length());

String zeros = "";
for (int i = 0; i < dif; i++) {
zeros += "0";
}
s = s.substring(0, 20 + (3 - dif)) + zeros + s.substring(s.length() - 6);
}

s = s.substring(0, 26) + s.substring(27);
} catch (IndexOutOfBoundsException e) {
throw new JsonParseException("Invalid length for: " + s);
}

// Parse the well-formatted date string
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ");
dateFormat.setTimeZone(TimeZone.getDefault());
Date date = dateFormat.parse(s);

return date;
Calendar c = DatatypeConverter.parseDateTime(strVal);
c.setTimeZone(TimeZone.getTimeZone("UTC"));
return c.getTime();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@

package microsoft.aspnet.signalr.client.transport;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;

import com.google.gson.Gson;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.exceptions.InvalidDataException;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.util.Charsetfunctions;
import javax.net.ssl.SSLSocketFactory;

import microsoft.aspnet.signalr.client.ConnectionBase;
import microsoft.aspnet.signalr.client.LogLevel;
Expand All @@ -26,6 +21,14 @@
import microsoft.aspnet.signalr.client.UpdateableCancellableFuture;
import microsoft.aspnet.signalr.client.http.HttpConnection;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.exceptions.InvalidDataException;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.util.Charsetfunctions;

import com.google.gson.Gson;

/**
* Implements the WebsocketTransport for the Java SignalR library
* Created by stas on 07/07/14.
Expand Down Expand Up @@ -68,9 +71,9 @@ public SignalRFuture<Void> start(ConnectionBase connection, ConnectionType conne

String url = null;
try {
url = connection.getUrl() + "signalr/" + connectionString + '?'
+ "connectionData=" + URLEncoder.encode(URLEncoder.encode(connectionData, "UTF-8"), "UTF-8")
+ "&connectionToken=" + URLEncoder.encode(URLEncoder.encode(connectionToken, "UTF-8"), "UTF-8")
url = connection.getUrl() + connectionString + '?'
+ "connectionData=" + URLEncoder.encode(connectionData, "UTF-8")
+ "&connectionToken=" + URLEncoder.encode(connectionToken, "UTF-8")
+ "&groupsToken=" + URLEncoder.encode(groupsToken, "UTF-8")
+ "&messageId=" + URLEncoder.encode(messageId, "UTF-8")
+ "&transport=" + URLEncoder.encode(transport, "UTF-8");
Expand All @@ -80,15 +83,14 @@ public SignalRFuture<Void> start(ConnectionBase connection, ConnectionType conne

mConnectionFuture = new UpdateableCancellableFuture<Void>(null);

url = "wss" + url.substring(5); // replace https with wss
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
mConnectionFuture.triggerError(e);
return mConnectionFuture;
}

mWebSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Expand All @@ -108,6 +110,7 @@ public void onClose(int i, String s, boolean b) {
@Override
public void onError(Exception e) {
mWebSocketClient.close();
mConnectionFuture.triggerError(e);
}

@Override
Expand Down Expand Up @@ -141,6 +144,13 @@ public void onFragment(Framedata frame) {
}
}
};

try {
mWebSocketClient.setSocket(SSLSocketFactory.getDefault().createSocket());
} catch (IOException e1) {
mConnectionFuture.triggerError(e1);
return mConnectionFuture;
}
mWebSocketClient.connect();

connection.closed(new Runnable() {
Expand Down