JBossWeb SVN: r2424 - branches/7.4.x.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-27 03:33:02 -0400 (Tue, 27 May 2014)
New Revision: 2424
Modified:
branches/7.4.x/pom.xml
Log:
New web build.
Modified: branches/7.4.x/pom.xml
===================================================================
--- branches/7.4.x/pom.xml 2014-05-26 22:49:55 UTC (rev 2423)
+++ branches/7.4.x/pom.xml 2014-05-27 07:33:02 UTC (rev 2424)
@@ -33,7 +33,7 @@
<groupId>org.jboss.web</groupId>
<artifactId>jbossweb</artifactId>
- <version>7.4.2.Final</version>
+ <version>7.4.3.Final</version>
<name>JBoss Web</name>
<description>Servlet 3.0 container</description>
10 years, 7 months
JBossWeb SVN: r2423 - branches/7.4.x/src/main/java/org/apache/tomcat/websocket.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-26 18:49:55 -0400 (Mon, 26 May 2014)
New Revision: 2423
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
Log:
Flip the default (no change besides that).
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java 2014-05-26 22:13:36 UTC (rev 2422)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java 2014-05-26 22:49:55 UTC (rev 2423)
@@ -60,9 +60,9 @@
public static final boolean STRICT_SPEC_COMPLIANCE =
Boolean.getBoolean(
"org.apache.tomcat.websocket.STRICT_SPEC_COMPLIANCE");
- public static final boolean STRICT_SPEC_CLOSE_EVENT =
+ public static final boolean RELAXED_CLOSE_EVENT =
Boolean.getBoolean(
- "org.apache.tomcat.websocket.STRICT_SPEC_CLOSE_EVENT");
+ "org.apache.tomcat.websocket.RELAXED_CLOSE_EVENT");
private Constants() {
// Hide default constructor
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-26 22:13:36 UTC (rev 2422)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-26 22:49:55 UTC (rev 2423)
@@ -406,7 +406,7 @@
state = State.CLOSING;
- if (Constants.STRICT_SPEC_CLOSE_EVENT) {
+ if (!Constants.RELAXED_CLOSE_EVENT) {
sendCloseMessage(closeReasonMessage);
fireEndpointOnClose(closeReasonLocal);
} else {
@@ -434,7 +434,7 @@
synchronized (stateLock) {
if (state == State.OPEN) {
- if (Constants.STRICT_SPEC_CLOSE_EVENT) {
+ if (!Constants.RELAXED_CLOSE_EVENT) {
sendCloseMessage(closeReason);
fireEndpointOnClose(closeReason);
} else {
10 years, 7 months
JBossWeb SVN: r2422 - branches/7.4.x/src/main/java/org/apache/tomcat/websocket.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-26 18:13:36 -0400 (Mon, 26 May 2014)
New Revision: 2422
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
Log:
Port Tomcat patch: catch possible ISE on write for clean handling.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java 2014-05-26 22:11:33 UTC (rev 2421)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java 2014-05-26 22:13:36 UTC (rev 2422)
@@ -49,8 +49,12 @@
}
SendHandlerToCompletionHandler sh2ch =
new SendHandlerToCompletionHandler(handler);
- channel.write(data, 0, data.length, timeout, TimeUnit.MILLISECONDS,
- null, sh2ch);
+ try {
+ channel.write(data, 0, data.length, timeout, TimeUnit.MILLISECONDS,
+ null, sh2ch);
+ } catch (IllegalStateException ise) {
+ sh2ch.failed(ise, null);
+ }
}
@Override
10 years, 7 months
JBossWeb SVN: r2421 - branches/7.4.x/src/main/java/org/apache/tomcat/websocket.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-26 18:11:33 -0400 (Mon, 26 May 2014)
New Revision: 2421
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
Log:
- Rather than just reverting again, add a system property. The default is what it was before reverting it.
- Either way passes the TCK for me.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java 2014-05-26 21:23:20 UTC (rev 2420)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/Constants.java 2014-05-26 22:11:33 UTC (rev 2421)
@@ -60,6 +60,9 @@
public static final boolean STRICT_SPEC_COMPLIANCE =
Boolean.getBoolean(
"org.apache.tomcat.websocket.STRICT_SPEC_COMPLIANCE");
+ public static final boolean STRICT_SPEC_CLOSE_EVENT =
+ Boolean.getBoolean(
+ "org.apache.tomcat.websocket.STRICT_SPEC_CLOSE_EVENT");
private Constants() {
// Hide default constructor
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-26 21:23:20 UTC (rev 2420)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-26 22:11:33 UTC (rev 2421)
@@ -406,8 +406,13 @@
state = State.CLOSING;
- sendCloseMessage(closeReasonMessage);
- fireEndpointOnClose(closeReasonLocal);
+ if (Constants.STRICT_SPEC_CLOSE_EVENT) {
+ sendCloseMessage(closeReasonMessage);
+ fireEndpointOnClose(closeReasonLocal);
+ } else {
+ fireEndpointOnClose(closeReasonLocal);
+ sendCloseMessage(closeReasonMessage);
+ }
state = State.CLOSED;
}
@@ -429,8 +434,13 @@
synchronized (stateLock) {
if (state == State.OPEN) {
- sendCloseMessage(closeReason);
- fireEndpointOnClose(closeReason);
+ if (Constants.STRICT_SPEC_CLOSE_EVENT) {
+ sendCloseMessage(closeReason);
+ fireEndpointOnClose(closeReason);
+ } else {
+ fireEndpointOnClose(closeReason);
+ sendCloseMessage(closeReason);
+ }
state = State.CLOSED;
}
10 years, 7 months
JBossWeb SVN: r2420 - branches/7.4.x/src/main/java/org/apache/tomcat/util/net.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-26 17:23:20 -0400 (Mon, 26 May 2014)
New Revision: 2420
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
Log:
Revert r2418 (useless extra sync).
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-05-26 13:35:49 UTC (rev 2419)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-05-26 21:23:20 UTC (rev 2420)
@@ -928,10 +928,10 @@
public void run() {
try {
Handler.SocketState state = null;
- synchronized (channel) {
- if (status == null) {
- state = handler.process(channel);
- } else {
+ if (status == null) {
+ state = handler.process(channel);
+ } else {
+ synchronized (channel) {
state = handler.event(channel, status);
}
}
10 years, 7 months
JBossWeb SVN: r2419 - branches/7.4.x/src/main/java/org/apache/tomcat/websocket.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-26 09:35:49 -0400 (Mon, 26 May 2014)
New Revision: 2419
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
Log:
Revert again. Besides cosmetics when using a closed session during the event processing, it doesn't cause any actual issues, but it could have side effects.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-24 13:07:18 UTC (rev 2418)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-26 13:35:49 UTC (rev 2419)
@@ -406,8 +406,8 @@
state = State.CLOSING;
+ sendCloseMessage(closeReasonMessage);
fireEndpointOnClose(closeReasonLocal);
- sendCloseMessage(closeReasonMessage);
state = State.CLOSED;
}
@@ -429,8 +429,8 @@
synchronized (stateLock) {
if (state == State.OPEN) {
+ sendCloseMessage(closeReason);
fireEndpointOnClose(closeReason);
- sendCloseMessage(closeReason);
state = State.CLOSED;
}
10 years, 7 months
JBossWeb SVN: r2418 - branches/7.4.x/src/main/java/org/apache/tomcat/util/net.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-24 09:07:18 -0400 (Sat, 24 May 2014)
New Revision: 2418
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
Log:
Sync process with event as some random behavior is still reported.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-05-23 22:13:48 UTC (rev 2417)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-05-24 13:07:18 UTC (rev 2418)
@@ -928,10 +928,10 @@
public void run() {
try {
Handler.SocketState state = null;
- if (status == null) {
- state = handler.process(channel);
- } else {
- synchronized (channel) {
+ synchronized (channel) {
+ if (status == null) {
+ state = handler.process(channel);
+ } else {
state = handler.event(channel, status);
}
}
10 years, 7 months
JBossWeb SVN: r2417 - in branches/7.4.x/src/main/java/org/apache/tomcat/websocket: pojo and 1 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-23 18:13:48 -0400 (Fri, 23 May 2014)
New Revision: 2417
Added:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/ClassIntrospecter.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceFactory.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceHandle.java
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointBase.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointServer.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerPartialBase.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerWholeBase.java
branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsServerContainer.java
Log:
BZ1086399: Tentative plumbing for CDI support, submitted by Stuart Douglas.
Added: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/ClassIntrospecter.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/ClassIntrospecter.java (rev 0)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/ClassIntrospecter.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.websocket;
+
+/**
+ * Interface that allows the container to hook into the class creation process
+ *
+ * @author Stuart Douglas
+ */
+public interface ClassIntrospecter {
+
+ InstanceFactory createInstanceFactory(final Class<?> clazz) throws NoSuchMethodException;
+
+}
Added: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceFactory.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceFactory.java (rev 0)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceFactory.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.websocket;
+
+/**
+ * Factory that creates fully injected component instances.
+ *
+ * @author Stuart Douglas
+ */
+public interface InstanceFactory {
+
+ /**
+ * Factory that creates a fully injected instance.
+ *
+ * @return The fully injected instance
+ */
+ InstanceHandle createInstance() throws InstantiationException;
+
+}
Added: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceHandle.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceHandle.java (rev 0)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/InstanceHandle.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.websocket;
+
+/**
+ * A handle for a container managed instance. When the servlet container is
+ * done with it it should call the {@link #release()} method
+ *
+ * @author Stuart Douglas
+ */
+public interface InstanceHandle {
+
+ /**
+ * @return The managed instance
+ *
+ */
+ Object getInstance();
+
+ /**
+ * releases the instance, uninjecting and calling an pre-destroy methods as appropriate
+ */
+ void release();
+
+}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsSession.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -45,6 +45,7 @@
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.tomcat.util.ExceptionUtils;
import org.jboss.web.WebsocketsLogger;
@@ -648,6 +649,14 @@
}
}
+ public ThreadBindingListener getThreadBindingListener() {
+ return webSocketContainer.getThreadBindingListener();
+ }
+
+ public ClassLoader getClassLoader() {
+ return webSocketContainer.getClassLoader();
+ }
+
private static enum State {
OPEN,
CLOSING,
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -63,6 +63,7 @@
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.tomcat.util.codec.binary.Base64;
import org.apache.tomcat.websocket.pojo.PojoEndpointClient;
import org.jboss.web.WebsocketsLogger;
@@ -70,6 +71,10 @@
public class WsWebSocketContainer
implements WebSocketContainer, BackgroundProcess {
+ protected static final ThreadBindingListener DEFAULT_THREAD_BINDING_LISTENER = (new ThreadBindingListener() {
+ public void bind() {}
+ public void unbind() {}
+ });
/**
* Property name to set to configure the value that is passed to
* {@link SSLEngine#setEnabledProtocols(String[])}. The value should be a
@@ -827,5 +832,11 @@
return processPeriod;
}
+ public ThreadBindingListener getThreadBindingListener() {
+ return DEFAULT_THREAD_BINDING_LISTENER;
+ }
+ public ClassLoader getClassLoader() {
+ return WsWebSocketContainer.class.getClassLoader();
+ }
}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointBase.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointBase.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointBase.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -27,7 +27,10 @@
import javax.websocket.MessageHandler;
import javax.websocket.Session;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.tomcat.util.ExceptionUtils;
+import org.apache.tomcat.websocket.InstanceHandle;
+import org.apache.tomcat.websocket.WsSession;
import org.jboss.web.WebsocketsLogger;
/**
@@ -38,6 +41,7 @@
public abstract class PojoEndpointBase extends Endpoint {
private Object pojo;
+ private InstanceHandle instanceHandle;
private Map<String,String> pathParameters;
private PojoMethodMapping methodMapping;
@@ -56,7 +60,11 @@
}
if (methodMapping.getOnOpen() != null) {
+ ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener();
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
+ tbl.bind();
methodMapping.getOnOpen().invoke(pojo,
methodMapping.getOnOpenArgs(
pathParameters, session, config));
@@ -73,6 +81,12 @@
} catch (Throwable t) {
handleOnOpenError(session, t);
return;
+ } finally {
+ try {
+ tbl.unbind();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
}
}
}
@@ -93,37 +107,60 @@
@Override
public final void onClose(Session session, CloseReason closeReason) {
-
- if (methodMapping.getOnClose() != null) {
- try {
- methodMapping.getOnClose().invoke(pojo,
- methodMapping.getOnCloseArgs(pathParameters, session, closeReason));
- } catch (Throwable t) {
- WebsocketsLogger.ROOT_LOGGER.onCloseFailed(pojo.getClass().getName(), t);
- handleOnCloseError(session, t);
+ try {
+ if (methodMapping.getOnClose() != null) {
+ ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener();
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
+ tbl.bind();
+ methodMapping.getOnClose().invoke(pojo,
+ methodMapping.getOnCloseArgs(pathParameters, session, closeReason));
+ } catch (Throwable t) {
+ WebsocketsLogger.ROOT_LOGGER.onCloseFailed(pojo.getClass().getName(), t);
+ handleOnCloseError(session, t);
+ } finally {
+ try {
+ tbl.unbind();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
+ }
}
- }
- // Trigger the destroy method for any associated decoders
- Set<MessageHandler> messageHandlers = session.getMessageHandlers();
- for (MessageHandler messageHandler : messageHandlers) {
- if (messageHandler instanceof PojoMessageHandlerWholeBase<?>) {
- ((PojoMessageHandlerWholeBase<?>) messageHandler).onClose();
+ // Trigger the destroy method for any associated decoders
+ Set<MessageHandler> messageHandlers = session.getMessageHandlers();
+ for (MessageHandler messageHandler : messageHandlers) {
+ if (messageHandler instanceof PojoMessageHandlerWholeBase<?>) {
+ ((PojoMessageHandlerWholeBase<?>) messageHandler).onClose();
+ }
}
+ } finally {
+ if (instanceHandle != null) {
+ instanceHandle.release();
+ instanceHandle = null;
+ }
}
}
private void handleOnCloseError(Session session, Throwable t) {
- // If really fatal - re-throw
- ExceptionUtils.handleThrowable(t);
+ try {
+ // If really fatal - re-throw
+ ExceptionUtils.handleThrowable(t);
- // Trigger the error handler and close the session
- onError(session, t);
- try {
- session.close();
- } catch (IOException ioe) {
- WebsocketsLogger.ROOT_LOGGER.closeSessionFailed(ioe);
+ // Trigger the error handler and close the session
+ onError(session, t);
+ try {
+ session.close();
+ } catch (IOException ioe) {
+ WebsocketsLogger.ROOT_LOGGER.closeSessionFailed(ioe);
+ }
+ } finally {
+ if(instanceHandle != null) {
+ instanceHandle.release();
+ instanceHandle = null;
+ }
}
}
@@ -133,7 +170,11 @@
if (methodMapping.getOnError() == null) {
WebsocketsLogger.ROOT_LOGGER.noOnError(pojo.getClass().getName(), throwable);
} else {
+ ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener();
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
+ tbl.bind();
methodMapping.getOnError().invoke(
pojo,
methodMapping.getOnErrorArgs(pathParameters, session,
@@ -141,6 +182,12 @@
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
WebsocketsLogger.ROOT_LOGGER.onErrorFailed(pojo.getClass().getName(), t);
+ } finally {
+ try {
+ tbl.unbind();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
}
}
}
@@ -148,7 +195,10 @@
protected Object getPojo() { return pojo; }
protected void setPojo(Object pojo) { this.pojo = pojo; }
+ public InstanceHandle getInstanceHandle() { return instanceHandle; }
+ public void setInstanceHandle(InstanceHandle instanceHandle) { this.instanceHandle = instanceHandle; }
+
protected Map<String,String> getPathParameters() { return pathParameters; }
protected void setPathParameters(Map<String,String> pathParameters) {
this.pathParameters = pathParameters;
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointServer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointServer.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoEndpointServer.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -16,6 +16,9 @@
*/
package org.apache.tomcat.websocket.pojo;
+import org.apache.tomcat.websocket.InstanceHandle;
+import org.apache.tomcat.websocket.WsSession;
+
import static org.jboss.web.WebsocketsMessages.MESSAGES;
import java.util.Map;
@@ -42,14 +45,24 @@
ServerEndpointConfig sec = (ServerEndpointConfig) endpointConfig;
+ InstanceHandle instanceHandle = null;
Object pojo;
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
pojo = sec.getConfigurator().getEndpointInstance(
sec.getEndpointClass());
+ if(pojo instanceof InstanceHandle) {
+ instanceHandle = (InstanceHandle) pojo;
+ pojo = instanceHandle.getInstance();
+ }
} catch (InstantiationException e) {
throw MESSAGES.pojoInstanceFailed(sec.getEndpointClass().getName(), e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
}
setPojo(pojo);
+ setInstanceHandle(instanceHandle);
@SuppressWarnings("unchecked")
Map<String,String> pathParameters =
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerPartialBase.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerPartialBase.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerPartialBase.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -24,6 +24,7 @@
import javax.websocket.MessageHandler;
import javax.websocket.Session;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.tomcat.websocket.WsSession;
/**
@@ -67,12 +68,22 @@
parameters[indexPayload] = message;
}
Object result;
+ ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener();
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
+ tbl.bind();
result = method.invoke(pojo, parameters);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(e);
+ } finally {
+ try {
+ tbl.unbind();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
}
processResult(result);
}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerWholeBase.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerWholeBase.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerWholeBase.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -23,6 +23,7 @@
import javax.websocket.MessageHandler;
import javax.websocket.Session;
+import org.apache.catalina.ThreadBindingListener;
import org.apache.tomcat.websocket.WsSession;
/**
@@ -76,12 +77,22 @@
parameters[indexPayload] = payload;
Object result;
+ ThreadBindingListener tbl = ((WsSession) session).getThreadBindingListener();
+ ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
+ Thread.currentThread().setContextClassLoader(((WsSession)session).getClassLoader());
+ tbl.bind();
result = method.invoke(pojo, parameters);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(e);
+ } finally {
+ try {
+ tbl.unbind();
+ } finally {
+ Thread.currentThread().setContextClassLoader(old);
+ }
}
processResult(result);
}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsServerContainer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsServerContainer.java 2014-05-23 14:13:07 UTC (rev 2416)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/websocket/server/WsServerContainer.java 2014-05-23 22:13:48 UTC (rev 2417)
@@ -51,6 +51,10 @@
import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.server.ServerEndpointConfig.Configurator;
+import org.apache.catalina.ThreadBindingListener;
+import org.apache.catalina.core.ApplicationContext;
+import org.apache.tomcat.websocket.ClassIntrospecter;
+import org.apache.tomcat.websocket.InstanceFactory;
import org.apache.tomcat.websocket.WsSession;
import org.apache.tomcat.websocket.WsWebSocketContainer;
import org.apache.tomcat.websocket.pojo.PojoEndpointServer;
@@ -88,10 +92,29 @@
private final ExecutorService executorService;
private final ThreadGroup threadGroup;
private volatile boolean endpointsRegistered = false;
+ private final ClassIntrospecter classIntrospecter;
+ private final ThreadBindingListener threadBindingListener;
+
WsServerContainer(ServletContext servletContext) {
+
this.servletContext = servletContext;
+ ClassIntrospecter classIntrospecter = (ClassIntrospecter) servletContext.getAttribute(ClassIntrospecter.class.getName());
+ servletContext.removeAttribute(ClassIntrospecter.class.getName()); //remove the attribute as it is only needed for bootstrap
+ if(classIntrospecter == null) {
+ classIntrospecter = null;
+ }
+ this.classIntrospecter = classIntrospecter;
+ //this is a horrible horrible hack.
+ ThreadBindingListener threadBindingListener = (ThreadBindingListener)servletContext.getAttribute(ThreadBindingListener.class.getName());
+ servletContext.removeAttribute(ThreadBindingListener.class.getName());
+ if(threadBindingListener != null) {
+ this.threadBindingListener = threadBindingListener;
+ } else {
+ this.threadBindingListener = DEFAULT_THREAD_BINDING_LISTENER;
+ }
+
// Configure servlet context wide defaults
String value = servletContext.getInitParameter(
Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM);
@@ -246,6 +269,13 @@
throw new DeploymentException(MESSAGES.configuratorFailed(annotation.configurator().getName(),
pojo.getClass().getName()), e);
}
+ } else if(classIntrospecter != null) {
+ try {
+ configurator = new ServerInstanceFactoryConfigurator(classIntrospecter.createInstanceFactory(pojo));
+ } catch (NoSuchMethodException e) {
+ throw new DeploymentException(MESSAGES.configuratorFailed(ServerInstanceFactoryConfigurator.class.getName(),
+ pojo.getClass().getName()), e);
+ }
}
sec = ServerEndpointConfig.Builder.create(pojo, path).
decoders(Arrays.asList(annotation.decoders())).
@@ -443,7 +473,15 @@
return executorService;
}
+ @Override
+ public ThreadBindingListener getThreadBindingListener() {
+ return threadBindingListener;
+ }
+ public ClassLoader getClassLoader() {
+ return servletContext.getClassLoader();
+ }
+
private void shutdownExecutor() {
if (executorService == null) {
return;
@@ -537,4 +575,20 @@
return t;
}
}
+
+
+ private static final class ServerInstanceFactoryConfigurator extends ServerEndpointConfig.Configurator {
+
+ private final InstanceFactory factory;
+
+ private ServerInstanceFactoryConfigurator(final InstanceFactory factory) {
+ this.factory = factory;
+ }
+
+ @Override
+ public <T> T getEndpointInstance(final Class<T> endpointClass) throws InstantiationException {
+ return (T) factory.createInstance();
+ }
+ }
+
}
10 years, 7 months
JBossWeb SVN: r2416 - branches/7.4.x/src/main/java/org/apache/catalina/connector.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-23 10:13:07 -0400 (Fri, 23 May 2014)
New Revision: 2416
Modified:
branches/7.4.x/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java
branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java
branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java
Log:
BZ1100486: Try again, make sure there's no keepalive after an upgraded connection processing.
Modified: branches/7.4.x/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java 2014-05-23 11:31:05 UTC (rev 2415)
+++ branches/7.4.x/src/main/java/org/apache/catalina/connector/CoyoteAdapter.java 2014-05-23 14:13:07 UTC (rev 2416)
@@ -255,6 +255,10 @@
}
if (error || close) {
response.finishResponse();
+ if (request.getUpgradeHandler() != null) {
+ // Ensure no keepalive after upgrade, even if it is not an error obviously
+ error = true;
+ }
}
return (!error);
} catch (Throwable t) {
Modified: branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java 2014-05-23 11:31:05 UTC (rev 2415)
+++ branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java 2014-05-23 14:13:07 UTC (rev 2416)
@@ -256,10 +256,10 @@
*/
public void close()
throws IOException {
- closed = true;
-
- if (request.getUpgradeHandler() != null) {
+ if (request.getUpgradeHandler() != null && request.isEventMode()) {
request.getEvent().close();
+ } else {
+ closed = true;
}
}
Modified: branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java 2014-05-23 11:31:05 UTC (rev 2415)
+++ branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java 2014-05-23 14:13:07 UTC (rev 2416)
@@ -300,6 +300,12 @@
if (suspended)
return;
+ Request request = response.getRequest();
+ if (request.getUpgradeHandler() != null && request.isEventMode()) {
+ request.getEvent().close();
+ return;
+ }
+
// If there are chars, flush all of them to the byte buffer now as bytes are used to
// calculate the content-length (if everything fits into the byte buffer, of course).
if (cb.getLength() > 0) {
@@ -320,10 +326,6 @@
coyoteResponse.finish();
- Request request = response.getRequest();
- if (request.getUpgradeHandler() != null) {
- request.getEvent().close();
- }
}
10 years, 7 months
JBossWeb SVN: r2415 - branches/7.4.x/src/main/java/org/apache/catalina/connector.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-05-23 07:31:05 -0400 (Fri, 23 May 2014)
New Revision: 2415
Modified:
branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java
branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java
Log:
BZ1100486: Try to resolve a discrepancy with Tomcat's behavior, since in the websocket implementation nothing will actually close the connection, only the streams will be closed (where they just close the socket). So try the usual close.
Modified: branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java 2014-05-23 11:29:12 UTC (rev 2414)
+++ branches/7.4.x/src/main/java/org/apache/catalina/connector/InputBuffer.java 2014-05-23 11:31:05 UTC (rev 2415)
@@ -257,6 +257,10 @@
public void close()
throws IOException {
closed = true;
+
+ if (request.getUpgradeHandler() != null) {
+ request.getEvent().close();
+ }
}
Modified: branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java 2014-05-23 11:29:12 UTC (rev 2414)
+++ branches/7.4.x/src/main/java/org/apache/catalina/connector/OutputBuffer.java 2014-05-23 11:31:05 UTC (rev 2415)
@@ -320,6 +320,10 @@
coyoteResponse.finish();
+ Request request = response.getRequest();
+ if (request.getUpgradeHandler() != null) {
+ request.getEvent().close();
+ }
}
10 years, 7 months