Skip to content
This repository was archived by the owner on Jan 30, 2019. It is now read-only.

Commit 97b05ef

Browse files
author
Arun Gupta
committed
Starting to migrated to 82, still need to figure out how to inject HttpSession
Former-commit-id: 32e3bd594384ccb077f456616e0a253dfde0088a
1 parent 8174e89 commit 97b05ef

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

samples/websocket/httpsession/src/main/java/org/glassfish/httpsession/MyEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import java.util.logging.Level;
4444
import java.util.logging.Logger;
4545
import javax.websocket.Endpoint;
46-
import javax.websocket.EndpointConfiguration;
46+
import javax.websocket.EndpointConfig;
4747
import javax.websocket.MessageHandler;
4848
import javax.websocket.Session;
4949

@@ -53,8 +53,8 @@
5353
public class MyEndpoint extends Endpoint {
5454

5555
@Override
56-
public void onOpen(final Session session, EndpointConfiguration ec) {
57-
session.addMessageHandler(new MessageHandler.Basic<String>() {
56+
public void onOpen(final Session session, EndpointConfig ec) {
57+
session.addMessageHandler(new MessageHandler.Whole<String>() {
5858

5959
@Override
6060
public void onMessage(String name) {

samples/websocket/httpsession/src/main/java/org/glassfish/httpsession/MyServerConfiguration.java renamed to samples/websocket/httpsession/src/main/java/org/glassfish/httpsession/MyEndpointConfiguration.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,37 @@
4040
package org.glassfish.httpsession;
4141

4242
import java.util.Collections;
43-
import java.util.List;
43+
import java.util.HashSet;
44+
import java.util.Set;
4445
import javax.servlet.http.HttpSession;
45-
import javax.websocket.Extension;
46+
import javax.websocket.Endpoint;
4647
import javax.websocket.HandshakeResponse;
47-
import javax.websocket.server.DefaultServerConfiguration;
4848
import javax.websocket.server.HandshakeRequest;
49-
import javax.websocket.server.ServerEndpointConfiguration;
49+
import javax.websocket.server.ServerApplicationConfig;
50+
import javax.websocket.server.ServerEndpointConfig;
5051

5152
/**
5253
* @author Arun Gupta
5354
*/
54-
// "implements ServerEndpointConfiguration" needs to be here,
55-
// most likely Servlet issue; see http://java.net/jira/browse/GLASSFISH-19551
56-
// (should be reopened, it is currently discussed internally)
55+
public class MyEndpointConfiguration implements ServerApplicationConfig {
5756

58-
// Also providing an implementation of three methods until
59-
// http://java.net/jira/browse/WEBSOCKET_SPEC-128 is fixed.
60-
public class MyServerConfiguration extends DefaultServerConfiguration implements ServerEndpointConfiguration {
61-
62-
public MyServerConfiguration() {
63-
super(MyEndpoint.class, "websocket");
64-
}
65-
66-
@Override
67-
public String getNegotiatedSubprotocol(List<String> requestedSubprotocols) {
68-
return null;
69-
}
70-
71-
@Override
72-
public List<Extension> getNegotiatedExtensions(List<Extension> requestedExtensions) {
73-
return Collections.emptyList();
74-
}
75-
76-
@Override
77-
public boolean checkOrigin(String originHeaderValue) {
78-
return true;
57+
@Override
58+
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> set) {
59+
return new HashSet<ServerEndpointConfig>() {{
60+
add(ServerEndpointConfig.Builder.create(MyEndpoint.class, "/websocket").build());
61+
}};
7962
}
8063

8164
@Override
82-
public void modifyHandshake(HandshakeRequest request, HandshakeResponse response) {
83-
HttpSession httpSession = (HttpSession)request.getSession();
84-
System.out.println(httpSession);
85-
System.out.println("Invoked from: " + httpSession.getServletContext().getContextPath());
86-
super.modifyHandshake(request, response);
65+
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> set) {
66+
return Collections.emptySet();
8767
}
68+
69+
// @Override
70+
// public void modifyHandshake(HandshakeRequest request, HandshakeResponse response) {
71+
// HttpSession httpSession = (HttpSession)request.getSession();
72+
// System.out.println(httpSession);
73+
// System.out.println("Invoked from: " + httpSession.getServletContext().getContextPath());
74+
// super.modifyHandshake(request, response);
75+
// }
8876
}

samples/websocket/httpsession/src/main/webapp/index.jsp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@
5757
<input onclick="sayHello();" value="Say Hello" type="button">
5858
<input id="myField" value="WebSocket" type="text"><br>
5959
</form>
60-
<form action="">
61-
<h2>Binary Data</h2>
62-
<input onclick="echoBinary();" value="Echo" type="button">
63-
<input id="myField2" value="8" type="text"><br>
64-
</form>
6560
</div>
6661
<div id="output"></div>
6762
<script language="javascript" type="text/javascript" src="websocket.js">

0 commit comments

Comments
 (0)