On 3/11/12 12:47 PM, Imre Fazekas wrote:
> Dear All,
>
>
>
> Sorry to bother you with such simple thing, but I am not able to make the wss to work (using Grizzly 2.2.1).
> I'm using the Grizzly very simple way. Creating the server, having servlets and web socket applications too. Work fine.
>
> "WebSocketAddOn wsa = new WebSocketAddOn();
> server.getListener("grizzly").registerAddOn( wsa );"
>
>
> If i'm enable ssl
> server.getListener("grizzly").setSecure(true);
> server.getListener("grizzly").setSSLEngineConfig( new SSLEngineConfigurator(sslContextConfig, false, NEED_CLIENT_AUTHENTICATE, false) );
>
>
> the servlets are working on https fine from my Java clients, so SSL is working basically, but "wss://" is not.
> Of course the client opening ws:// is not working anymore, but even if I set the URL to use wss://, cannot connect. What should I do on client or maybe on server-side to make it work?
>
> I haven't found any sample code to use wss:// on client side with org.glassfish.grizzly.websockets.WebSocketClient
I wouldn't recommend using that WebSocketClient. It currently doesn't
support SSL.
I would instead recommend using the AHC WebSocket client with the
Grizzly Provider.
See:
http://www.notshabby.net/2012/01/async-http-client-1-7-0-released-details-on-the-grizzly-side-of-things/
The example at the bottom of the entry, doesn't include SSL, but it
should be easy enough to do:
// This example will send a WS message to a server that echoes the
message back
AsyncHttpClientConfig config = new
AsyncHttpClientConfig.Builder().setSSLContext(<Your SSLContext>).build();
AsyncHttpClient c = new AsyncHttpClient(new
GrizzlyAsyncHttpProvider(config), config));
String wsUrl = "wss://somehost/wspath";
WebSocketListener listener = new DefaultWebSocketListener() {
@Override
onMessage(String message) {
System.out.println("Received message: " + message);
}
};
WebSocketUpgradeHandler handler = new
WebSocketUpgradeHandler().Builder().addWebSocketListener(listener).build();
WebSocket socket = c.prepareGet(wsUrl).execute(handler).get();
socket.sendMessage("Hello!".getBytes("UTF-8"));
>
>
>
> Any help would be appreciated!
>
>
>
> Best regards,
>
> Imre