diff --git a/cdi/modules/pom.xml b/cdi/modules/pom.xml deleted file mode 100644 index 426d87667..000000000 --- a/cdi/modules/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - 4.0.0 - - org.atmosphere - atmosphere-extensions-project - 2.6.6-SNAPSHOT - ../../pom.xml - - org.atmosphere - atmosphere-cdi - jar - 2.6.6-SNAPSHOT - atmosphere-cdi - https://github.com/Atmosphere/atmosphere - - - - org.atmosphere - atmosphere-runtime - ${atmosphere-version} - - - javax - javaee-api - 6.0 - provided - - - diff --git a/cdi/modules/src/main/java/org/atmosphere/cdi/CDIObjectFactory.java b/cdi/modules/src/main/java/org/atmosphere/cdi/CDIObjectFactory.java deleted file mode 100644 index 231cbf0c0..000000000 --- a/cdi/modules/src/main/java/org/atmosphere/cdi/CDIObjectFactory.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.cdi; - -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereObjectFactory; -import org.atmosphere.inject.AtmosphereProducers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.enterprise.context.spi.CreationalContext; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import java.util.Iterator; - -/** - * CDI support for injecting object - * - * @author Jeanfrancois Arcand - */ -public class CDIObjectFactory implements AtmosphereObjectFactory { - - private static final Logger logger = LoggerFactory.getLogger(CDIObjectFactory.class); - - private BeanManager bm; - - public CDIObjectFactory(){ - try { - bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); - } catch (NamingException ex) { - try { - bm = (BeanManager) new InitialContext().lookup("java:comp/env/BeanManager"); - } catch (NamingException e) { - logger.error("{}", e); - throw new IllegalStateException(); - } - } - } - - @Override - @SuppressWarnings("unchecked") - public U newClassInstance(Class classType, Class classToInstantiate) throws InstantiationException, IllegalAccessException { - CreationalContext cc = null; - - try { - final Iterator> i = bm.getBeans(classToInstantiate).iterator(); - if (!i.hasNext()) { - logger.trace("Unable to find {}. Creating the object directly.", classToInstantiate.getName()); - return classToInstantiate.newInstance(); - } - Bean bean = (Bean) i.next(); - CreationalContext ctx = bm.createCreationalContext(bean); - U dao = (U) bm.getReference(bean, classToInstantiate, ctx); - - return dao; - } catch (Exception e) { - logger.error("Unable to construct {}. Creating the object directly.", classToInstantiate.getName()); - return classToInstantiate.newInstance(); - } finally { - if (cc != null) cc.release(); - } - } - - @Override - public AtmosphereObjectFactory allowInjectionOf(Object o) { - return this; - } - - - public String toString() { - return "CDI ObjectFactory"; - } - - @Override - public void configure(AtmosphereConfig config) { - try { - AtmosphereProducers p = newClassInstance(AtmosphereProducers.class,AtmosphereProducers.class); - p.configure(config); - } catch (Exception e) { - logger.error("", e); - } - } - -} diff --git a/cometd/modules/pom.xml b/cometd/modules/pom.xml deleted file mode 100644 index ca0d87b6e..000000000 --- a/cometd/modules/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - org.atmosphere - atmosphere-extensions-project - 2.6.6-SNAPSHOT - ../../pom.xml - - 4.0.0 - org.atmosphere - atmosphere-cometd - bundle - 2.6.6-SNAPSHOT - atmosphere-cometd - https://github.com/Atmosphere/atmosphere - - install - - - src/main/resources - - - - - src/test/resources - - - - - org.apache.felix - maven-bundle-plugin - ${felix-version} - true - - - * - - org.atmosphere.cometd.*, - - - - - - osgi-bundle - package - - bundle - - - - - - - - - org.cometd.java - cometd-java-server - 2.4.3 - - - org.cometd.java - cometd-websocket-jetty - 2.4.3 - - - org.cometd.java - cometd-java-annotations - 2.4.3 - - - org.atmosphere - atmosphere-runtime - ${atmosphere-version} - - - javax.servlet - javax.servlet-api - ${servlet-version} - provided - - - diff --git a/cometd/modules/src/main/java/org/atmosphere/cometd/CometdAtmosphereInterceptor.java b/cometd/modules/src/main/java/org/atmosphere/cometd/CometdAtmosphereInterceptor.java deleted file mode 100644 index 2b95859d7..000000000 --- a/cometd/modules/src/main/java/org/atmosphere/cometd/CometdAtmosphereInterceptor.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.cometd; - -import org.atmosphere.cpr.Action; -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereInterceptor; -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter; -import org.atmosphere.cpr.FrameworkConfig; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationListener; -import org.eclipse.jetty.continuation.ContinuationThrowable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import javax.servlet.ServletResponse; -import java.io.IOException; - -public class CometdAtmosphereInterceptor implements AtmosphereInterceptor { - - private static final Logger logger = LoggerFactory.getLogger(JettyAsyncSupport.class); - - @Override - public void configure(AtmosphereConfig config) { - if (config.getServletContext().getServerInfo().contains("jetty")) { - config.framework().setAsyncSupport(new JettyAsyncSupport( - config)); - } - } - - @Override - public Action inspect(final AtmosphereResource r) { - AtmosphereRequest request = r.getRequest(); - - if (r.transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) { - - if (r.getRequest().getAttribute(FrameworkConfig.INJECTED_ATMOSPHERE_RESOURCE) != null) { - return Action.CANCELLED; - } - } - - request.setAttribute(Continuation.ATTRIBUTE, new AtmosphereContinuation(r)); - - return Action.CONTINUE; - } - - public final static class AtmosphereContinuation implements Continuation { - - private long timeoutMs = -1; - private ServletResponse response; - private final AtmosphereResource r; - - public AtmosphereContinuation(AtmosphereResource r) { - this.r = r; - } - - @Override - public void setTimeout(long timeoutMs) { - this.timeoutMs = timeoutMs; - } - - @Override - public void suspend() { - r.suspend(timeoutMs); - } - - @Override - public void suspend(ServletResponse response) { - this.response = response; - r.suspend(timeoutMs); - } - - @Override - public void resume() { - try { - r.getAtmosphereConfig().framework().doCometSupport(r.getRequest(), r.getResponse()); - } catch (IOException e) { - logger.warn("",e); - } catch (ServletException e) { - logger.warn("", e); - } - r.resume(); - } - - @Override - public void complete() { - r.resume(); - } - - @Override - public boolean isSuspended() { - return r.isSuspended(); - } - - @Override - public boolean isResumed() { - return r.isResumed(); - } - - @Override - public boolean isExpired() { - return r.isResumed(); - } - - @Override - public boolean isInitial() { - return r.isSuspended(); - } - - @Override - public boolean isResponseWrapped() { - return true; - } - - @Override - public ServletResponse getServletResponse() { - return response; - } - - @Override - public void addContinuationListener(final ContinuationListener listener) { - r.addEventListener(new AtmosphereResourceEventListenerAdapter() { - @Override - public void onSuspend(AtmosphereResourceEvent event) { - } - - @Override - public void onResume(AtmosphereResourceEvent event) { - if (event.isResuming()) { - listener.onComplete(AtmosphereContinuation.this); - } else { - try { - r.getAtmosphereConfig().framework().doCometSupport(r.getRequest(), r.getResponse()); - } catch (IOException e) { - logger.warn("", e); - } catch (ServletException e) { - logger.warn("", e); - } - listener.onTimeout(AtmosphereContinuation.this); - } - } - }); - } - - @Override - public void setAttribute(String name, Object attribute) { - r.getRequest().setAttribute(name, attribute); - } - - @Override - public Object getAttribute(String name) { - return r.getRequest().getAttribute(name); - } - - @Override - public void removeAttribute(String name) { - r.getRequest().removeAttribute(name); - } - - @Override - public void undispatch() throws ContinuationThrowable { - } - } - - @Override - public void postInspect(AtmosphereResource r) { - } - - @Override - public void destroy() { - } - - @Override - public String toString() { - return "CometD/Bayeux Protocol"; - } -} diff --git a/cometd/modules/src/main/java/org/atmosphere/cometd/CometdServlet.java b/cometd/modules/src/main/java/org/atmosphere/cometd/CometdServlet.java deleted file mode 100644 index da2200cac..000000000 --- a/cometd/modules/src/main/java/org/atmosphere/cometd/CometdServlet.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.cometd; - -import org.atmosphere.cpr.ApplicationConfig; -import org.atmosphere.cpr.AtmosphereServlet; -import org.atmosphere.handler.ReflectorServletProcessor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; - -/** - * Simple Servlet that support the Cometd.org Bayeux protocol. - * - * @author Jean-Francois Arcand - */ -public class CometdServlet extends AtmosphereServlet { - protected static final Logger logger = LoggerFactory.getLogger(CometdServlet.class); - - public CometdServlet() { - this(false); - } - - public CometdServlet(boolean isFilter) { - super(isFilter, false); - } - - @Override - public void init(final ServletConfig sc) throws ServletException { - framework().interceptor(new CometdAtmosphereInterceptor()); - framework().setUseStreamForFlushingComments(false); - - framework().addInitParameter("transports", WebSocketTransport.class.getName()); - framework().addInitParameter(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json"); - super.init(sc); - - ReflectorServletProcessor r = new ReflectorServletProcessor(); - r.setServletClassName(org.cometd.java.annotation.AnnotationCometdServlet.class.getName()); - framework().addAtmosphereHandler("/*", r).initAtmosphereHandler(framework().getServletConfig()); - } - - - - @Override - public void destroy() { - super.destroy(); - } -} diff --git a/cometd/modules/src/main/java/org/atmosphere/cometd/JettyAsyncSupport.java b/cometd/modules/src/main/java/org/atmosphere/cometd/JettyAsyncSupport.java deleted file mode 100644 index cb4a80da5..000000000 --- a/cometd/modules/src/main/java/org/atmosphere/cometd/JettyAsyncSupport.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.cometd; - -import org.atmosphere.container.Jetty7CometSupport; -import org.atmosphere.container.JettyWebSocketUtil; -import org.atmosphere.cpr.Action; -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResponse; -import org.atmosphere.cpr.WebSocketProcessorFactory; -import org.atmosphere.websocket.WebSocketProcessor; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.websocket.WebSocketFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import java.io.IOException; - -public class JettyAsyncSupport extends Jetty7CometSupport { - - private static final Logger logger = LoggerFactory.getLogger(JettyAsyncSupport.class); - private final WebSocketFactory webSocketFactory; - - public JettyAsyncSupport(AtmosphereConfig config) { - super(config); - final WebSocketProcessor webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(config.framework()); - - WebSocketFactory wsf; - try { - String[] jettyVersion = config.getServletContext().getServerInfo().substring(6).split("\\."); - if (Integer.valueOf(jettyVersion[0]) > 7 || Integer.valueOf(jettyVersion[0]) == 7 && Integer.valueOf(jettyVersion[1]) > 4) { - wsf = JettyWebSocketUtil.getFactory(config, webSocketProcessor); - } else { - wsf = null; - } - } catch (Throwable e) { - // If we can't parse Jetty version, assume it's 8 and up. - try { - logger.trace("Unable to parse Jetty version {}", config.getServletContext().getServerInfo()); - } catch (Throwable t) { - } - wsf = JettyWebSocketUtil.getFactory(config, webSocketProcessor); - } - webSocketFactory = wsf; - } - - /** - * {@inheritDoc} - */ - @Override - public Action service(AtmosphereRequest req, AtmosphereResponse res) - throws IOException, ServletException { - Action action = JettyWebSocketUtil.doService(this, req, res, webSocketFactory); - return action == null ? super.service(req, res) : action; - } - - /** - * Return the container's name. - */ - public String getContainerName() { - return config.getServletConfig().getServletContext().getServerInfo() + " with WebSocket enabled."; - } - - @Override - public boolean supportWebSocket() { - return true; - } - - protected Continuation getContinuation(AtmosphereRequest req) { - Continuation falseContinuation = (Continuation) req.getAttribute(Continuation.ATTRIBUTE); - req.setAttribute(Continuation.ATTRIBUTE, null); - Continuation c = ContinuationSupport.getContinuation(req); - req.setAttribute(Continuation.ATTRIBUTE, falseContinuation); - return c; - } - -} diff --git a/cometd/modules/src/main/java/org/atmosphere/cometd/WebSocketTransport.java b/cometd/modules/src/main/java/org/atmosphere/cometd/WebSocketTransport.java deleted file mode 100644 index 403fd8eee..000000000 --- a/cometd/modules/src/main/java/org/atmosphere/cometd/WebSocketTransport.java +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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. - */ - -// This class was hightly inspired by its Cometd implementation -/* - * Copyright (c) 2010 the original author or authors. - * - * 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.atmosphere.cometd; - -import org.atmosphere.cpr.HeaderConfig; -import org.cometd.bayeux.Channel; -import org.cometd.bayeux.Message; -import org.cometd.bayeux.server.ServerMessage; -import org.cometd.server.AbstractServerTransport; -import org.cometd.server.BayeuxServerImpl; -import org.cometd.server.ServerSessionImpl; -import org.cometd.server.transport.LongPollingTransport; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationListener; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.text.ParseException; -import java.util.List; -import java.util.Map; - - -public class WebSocketTransport extends LongPollingTransport { - private final Logger logger = LoggerFactory.getLogger(getClass()); - - public final static String PREFIX = "long-polling.ws"; - public final static String NAME = "websocket"; - public final static String MIME_TYPE_OPTION = "mimeType"; - public final static String CALLBACK_PARAMETER_OPTION = "callbackParameter"; - - private String _mimeType = "text/javascript;charset=UTF-8"; - private String _callbackParam = "jsonp"; - private boolean _autoBatch = true; - private boolean _allowMultiSessionsNoBrowser = false; - private long _multiSessionInterval = 2000; - - public WebSocketTransport(BayeuxServerImpl bayeux) { - super(bayeux, NAME); - setOptionPrefix(PREFIX); - } - - /** - * @see org.cometd.server.transport.LongPollingTransport#isAlwaysFlushingAfterHandle() - */ - @Override - protected boolean isAlwaysFlushingAfterHandle() { - return true; - } - - /** - * @see org.cometd.server.transport.JSONTransport#init() - */ - @Override - protected void init() { - super.init(); - _callbackParam = getOption(CALLBACK_PARAMETER_OPTION, _callbackParam); - _mimeType = getOption(MIME_TYPE_OPTION, _mimeType); - } - - @Override - public boolean accept(HttpServletRequest request) { - return request.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT) == HeaderConfig.WEBSOCKET_TRANSPORT; - } - - @Override - public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - // Is this a resumed connect? - LongPollScheduler scheduler = (LongPollScheduler) request.getAttribute(LongPollScheduler.ATTRIBUTE); - if (scheduler == null) { - // No - process messages - - // Remember if we start a batch - boolean batch = false; - - // Don't know the session until first message or handshake response. - ServerSessionImpl session = null; - boolean connect = false; - - try { - ServerMessage.Mutable[] messages = parseMessages(request); - if (messages == null) - return; - - PrintWriter writer = null; - for (ServerMessage.Mutable message : messages) { - // Is this a connect? - connect = Channel.META_CONNECT.equals(message.getChannel()); - - // Get the session from the message - String client_id = message.getClientId(); - if (session == null || client_id != null && !client_id.equals(session.getId())) { - session = (ServerSessionImpl) getBayeux().getSession(client_id); - if (_autoBatch && !batch && session != null && !connect && !message.isMeta()) { - // start a batch to group all resulting messages into a single response. - batch = true; - session.startBatch(); - } - } else if (!session.isHandshook()) { - batch = false; - session = null; - } - - if (connect && session != null) { - // cancel previous scheduler to cancel any prior waiting long poll - // this should also dec the browser ID - session.setScheduler(null); - } - - boolean wasConnected = session != null && session.isConnected(); - - // Forward handling of the message. - // The actual reply is return from the call, but other messages may - // also be queued on the session. - ServerMessage.Mutable reply = bayeuxServerHandle(session, message); - - // Do we have a reply ? - if (reply != null) { - if (session == null) { - // This must be a handshake, extract a session from the reply - session = (ServerSessionImpl) getBayeux().getSession(reply.getClientId()); - - // Get the user agent while we are at it, and add the browser ID cookie - if (session != null) { - String userAgent = request.getHeader("User-Agent"); - session.setUserAgent(userAgent); - - String browserId = findBrowserId(request); - if (browserId == null) - setBrowserId(request, response); - } - } else { - // Special handling for connect - if (connect) { - try { - writer = sendQueue(request, response, session, writer); - - // If the writer is non null, we have already started sending a response, so we should not suspend - if (writer == null && reply.isSuccessful() && session.isQueueEmpty()) { - // Detect if we have multiple sessions from the same browser - // Note that CORS requests do not send cookies, so we need to handle them specially - // CORS requests always have the Origin header - - String browserId = findBrowserId(request); - boolean allowSuspendConnect; - if (browserId != null) - allowSuspendConnect = incBrowserId(browserId); - else - allowSuspendConnect = _allowMultiSessionsNoBrowser; - - if (allowSuspendConnect) { - long timeout = session.calculateTimeout(getTimeout()); - - // Support old clients that do not send advice:{timeout:0} on the first connect - if (timeout > 0 && wasConnected && session.isConnected()) { - // Suspend and wait for messages - Continuation continuation = ContinuationSupport.getContinuation(request); - continuation.setTimeout(timeout); - continuation.suspend(response); - scheduler = new LongPollScheduler(session, continuation, reply, browserId); - session.setScheduler(scheduler); - request.setAttribute(LongPollScheduler.ATTRIBUTE, scheduler); - reply = null; - metaConnectSuspended(request, session, timeout); - } else { - decBrowserId(browserId); - } - } else { - // There are multiple sessions from the same browser - Map advice = reply.getAdvice(true); - - if (browserId != null) - advice.put("multiple-clients", true); - - if (_multiSessionInterval > 0) { - advice.put(Message.RECONNECT_FIELD, Message.RECONNECT_RETRY_VALUE); - advice.put(Message.INTERVAL_FIELD, _multiSessionInterval); - } else { - advice.put(Message.RECONNECT_FIELD, Message.RECONNECT_NONE_VALUE); - reply.setSuccessful(false); - } - session.reAdvise(); - } - } - } finally { - if (reply != null && session.isConnected()) - session.startIntervalTimeout(getInterval()); - } - } else { - if (!isMetaConnectDeliveryOnly() && !session.isMetaConnectDeliveryOnly()) { - writer = sendQueue(request, response, session, writer); - } - } - } - - // If the reply has not been otherwise handled, send it - if (reply != null) { - if (connect && session != null && !session.isConnected()) - reply.getAdvice(true).put(Message.RECONNECT_FIELD, Message.RECONNECT_NONE_VALUE); - - reply = getBayeux().extendReply(session, session, reply); - - if (reply != null) { - getBayeux().freeze(reply); - writer = send(request, response, writer, reply); - } - } - } - - // Disassociate the reply - message.setAssociated(null); - } - if (writer != null) - complete(writer); - } catch (ParseException x) { - handleJSONParseException(request, response, x.getMessage(), x.getCause()); - } finally { - // If we started a batch, end it now - if (batch) { - boolean ended = session.endBatch(); - - // Flush session if not done by the batch, since some browser order \n").getBytes()).flushBuffer(); - } catch (IOException e) { - logger.trace("", e); - } - } - - -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/IFrameUtils.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/IFrameUtils.java deleted file mode 100644 index 629b2e8e5..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/IFrameUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import java.io.UnsupportedEncodingException; - -public class IFrameUtils { - - public static byte[] generateIFrame(String origin) { - StringBuilder b = new StringBuilder(); - b.append("\n").append( - "\n").append( - "\n").append( - " \n").append( - " \n").append( - " \n").append( - " \n").append( - "\n").append( - "\n").append( - "

Don't panic!

\n").append( - "

This is a SockJS hidden iframe. It's used for cross domain magic.

\n").append( - "\n").append( - ""); - try { - return b.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - return b.toString().getBytes(); - } - } - - public static byte[] generateHtmlFile(String callback) { - StringBuilder b = new StringBuilder(); - b.append("\n").append( - "\n").append( - " \n").append( - " \n").append( - "

Don't panic!

\n").append( - " "); - - try { - return b.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - return b.toString().getBytes(); - } - - } - - -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/JSONPTransport.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/JSONPTransport.java deleted file mode 100644 index 2b71fea7e..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/JSONPTransport.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class JSONPTransport extends TransportBasedListener { - private static final Logger logger = LoggerFactory.getLogger(JSONPTransport.class); - @Override - public void onSuspend(AtmosphereResourceEvent event) { - AtmosphereResponse response = event.getResource().getResponse(); - try { - response.write("o".getBytes()).flushBuffer(); - } catch (IOException e) { - logger.trace("", e); - } - } -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/JsonCodec.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/JsonCodec.java deleted file mode 100644 index 63944b24b..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/JsonCodec.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2011-2018 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ - -package org.atmosphere.sockjs; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.io.CharTypes; -import com.fasterxml.jackson.core.json.JsonWriteContext; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.module.SimpleModule; - -import java.io.IOException; - -/** - * SockJS requires a special JSON codec - it requires that many other characters, - * over and above what is required by the JSON spec are escaped. - * To satisfy this we escape any character that escapable with short escapes and - * any other non ASCII character we unicode escape it - * - * @author Tim Fox - */ -public class JsonCodec { - - private final static ObjectMapper mapper; - - static { - mapper = new ObjectMapper(); - - // By default, Jackson does not escape unicode characters in JSON strings - // This should be ok, since a valid JSON string can contain unescaped JSON - // characters. - // However, SockJS requires that many unicode chars are escaped. This may - // be due to browsers barfing over certain unescaped characters - // So... when encoding strings we make sure all unicode chars are escaped - - // This code adapted from http://wiki.fasterxml.com/JacksonSampleQuoteChars - SimpleModule simpleModule = new SimpleModule(); - - simpleModule.addSerializer(String.class, new JsonSerializer() { - final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); - final int[] ESCAPE_CODES = CharTypes.get7BitOutputEscapes(); - - private void writeUnicodeEscape(JsonGenerator gen, char c) throws IOException { - gen.writeRaw('\\'); - gen.writeRaw('u'); - gen.writeRaw(HEX_CHARS[(c >> 12) & 0xF]); - gen.writeRaw(HEX_CHARS[(c >> 8) & 0xF]); - gen.writeRaw(HEX_CHARS[(c >> 4) & 0xF]); - gen.writeRaw(HEX_CHARS[c & 0xF]); - } - - private void writeShortEscape(JsonGenerator gen, char c) throws IOException { - gen.writeRaw('\\'); - gen.writeRaw(c); - } - - @Override - public void serialize(String str, JsonGenerator gen, SerializerProvider provider) throws IOException { - int status = ((JsonWriteContext) gen.getOutputContext()).writeValue(); - switch (status) { - case JsonWriteContext.STATUS_OK_AFTER_COLON: - gen.writeRaw(':'); - break; - case JsonWriteContext.STATUS_OK_AFTER_COMMA: - gen.writeRaw(','); - break; - case JsonWriteContext.STATUS_EXPECT_NAME: - throw new JsonGenerationException("Can not write string value here"); - } - gen.writeRaw('"'); - for (char c : str.toCharArray()) { - if (c >= 0x80) writeUnicodeEscape(gen, c); // use generic escaping for all non US-ASCII characters - else { - // use escape table for first 128 characters - int code = (c < ESCAPE_CODES.length ? ESCAPE_CODES[c] : 0); - if (code == 0) gen.writeRaw(c); // no escaping - else if (code == -1) writeUnicodeEscape(gen, c); // generic escaping - else writeShortEscape(gen, (char) code); // short escaping (\n \t ...) - } - } - gen.writeRaw('"'); - } - }); - mapper.registerModule(simpleModule); - } - - public static String encode(Object obj) { - try { - return mapper.writeValueAsString(obj); - } catch (JsonProcessingException e) { - return null; - } - } - - public static Object decodeValue(String str, Class clazz) { - try { - return mapper.readValue(str, clazz); - } catch (IOException e) { - return null; - } - } -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/LongPollingTransport.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/LongPollingTransport.java deleted file mode 100644 index b6b328c85..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/LongPollingTransport.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class LongPollingTransport extends TransportBasedListener { - private static final Logger logger = LoggerFactory.getLogger(LongPollingTransport.class); - - @Override - public void onSuspend(AtmosphereResourceEvent event) { - AtmosphereResponse response = event.getResource().getResponse(); - response.setContentType("application/javascript"); - try { - response.write("o\r\n\r\n".getBytes(), true).flushBuffer(); - response.closeStreamOrWriter(); - } catch (IOException e) { - logger.trace("", e); - } - - } - -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SSETransport.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/SSETransport.java deleted file mode 100644 index 31f4c2ba3..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SSETransport.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class SSETransport extends TransportBasedListener { - private static final Logger logger = LoggerFactory.getLogger(SSETransport.class); - @Override - public void onSuspend(AtmosphereResourceEvent event) { - AtmosphereResponse response = event.getResource().getResponse(); - try { - response.write("o".getBytes()).flushBuffer(); - } catch (IOException e) { - logger.trace("", e); - } - } -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockJsAtmosphereInterceptor.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockJsAtmosphereInterceptor.java deleted file mode 100644 index 20978545f..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockJsAtmosphereInterceptor.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.atmosphere.cpr.Action; -import org.atmosphere.cpr.AsyncIOInterceptorAdapter; -import org.atmosphere.cpr.AsyncIOWriter; -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereFramework; -import org.atmosphere.cpr.AtmosphereHandler; -import org.atmosphere.cpr.AtmosphereInterceptor; -import org.atmosphere.cpr.AtmosphereInterceptorAdapter; -import org.atmosphere.cpr.AtmosphereInterceptorWriter; -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter; -import org.atmosphere.cpr.AtmosphereResourceImpl; -import org.atmosphere.cpr.AtmosphereResponse; -import org.atmosphere.cpr.HeaderConfig; -import org.atmosphere.handler.AbstractReflectorAtmosphereHandler; -import org.atmosphere.interceptor.HeartbeatInterceptor; -import org.atmosphere.util.IOUtils; -import org.atmosphere.util.StringEscapeUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; - -import java.io.IOException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.WeakHashMap; -import java.util.concurrent.atomic.AtomicReference; - -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.HTMLFILE; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.JSONP; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.LONG_POLLING; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.POLLING; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.SSE; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.STREAMING; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.UNDEFINED; -import static org.atmosphere.cpr.AtmosphereResource.TRANSPORT.WEBSOCKET; - -public class SockJsAtmosphereInterceptor extends AtmosphereInterceptorAdapter { - - public final static String SOCKS_JS_ORIGIN = SockJsAtmosphereInterceptor.class.getName() + ".origin"; - - private static final Logger logger = LoggerFactory.getLogger(SockJsAtmosphereInterceptor.class); - private boolean supportWebSocket = true; - private final AtomicReference baseURL = new AtomicReference(""); - private AtmosphereFramework framework; - private final Map sessions = Collections.synchronizedMap(new WeakHashMap()); - - public final static AtmosphereHandler ECHO_ATMOSPHEREHANDLER = new AbstractReflectorAtmosphereHandler() { - @Override - public void onRequest(AtmosphereResource resource) throws IOException { - String body = IOUtils.readEntirely(resource).toString(); - if (!body.isEmpty()) { - resource.getBroadcaster().broadcast(body); - } - } - }; - - @Override - public void configure(final AtmosphereConfig config) { - framework = config.framework(); - supportWebSocket = config.framework().getAsyncSupport().supportWebSocket(); - config.properties().put(HeaderConfig.JSONP_CALLBACK_NAME, "c"); - for (AtmosphereInterceptor i : framework.interceptors()) { - if (HeartbeatInterceptor.class.isAssignableFrom(i.getClass())) { - HeartbeatInterceptor.class.cast(i).paddingText("h".getBytes()).heartbeatFrequencyInSeconds(25); - } - } - - if (config.handlers().size() == 0) { - framework.addAtmosphereHandler("/*", ECHO_ATMOSPHEREHANDLER); - } - } - - @Override - public Action inspect(final AtmosphereResource r) { - final AtmosphereRequest request = r.getRequest(); - - if (request.getAttribute("sockjs.skipInterceptor") != null) { - return Action.CONTINUE; - } - - boolean info = request.getRequestURI().endsWith("/info"); - if (info) { - return info(r); - } - - boolean iframe = request.getRequestURI().endsWith("/iframe.html"); - if (iframe) { - return iframe(r); - } - - if (!baseURL.get().isEmpty() && request.getRequestURI().startsWith(baseURL.get())) { - super.inspect(r); - - // See https://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36 - // The URL received from the client should be similar to the following: - // /// - // The auxiliar params method will handle this URL processing - String[] params = params(request.getRequestURI().substring(baseURL.get().length()), 2); - final String sessionId = params[0]; - String transport = params[1]; - - SockjsSession s = sessions.get(sessionId); - configureTransport(AtmosphereResourceImpl.class.cast(r), transport, s != null); - boolean longPolling = org.atmosphere.util.Utils.resumableTransport(r.transport()); - - if (s == null) { - sessions.put(sessionId, new SockjsSession()); - if (!longPolling) { - installWriter(r, sessionId); - } - return Action.CONTINUE; - } else if (longPolling) { - installWriter(r, sessionId); - return Action.CONTINUE; - } - - return injectMessage(r); - } - return Action.CONTINUE; - } - - private Action iframe(AtmosphereResource r) { - final AtmosphereResponse response = r.getResponse(); - response.setContentType("text/html"); - String origin = framework.getAtmosphereConfig().getInitParameter(SOCKS_JS_ORIGIN); - if (origin == null) { - origin = "http://localhost:8080/lib/sockjs.js"; - } - try { - response.write(IFrameUtils.generateIFrame(origin)).flushBuffer(); - } catch (IOException e) { - logger.error("", e); - } - return Action.CANCELLED; - } - - protected Action info(AtmosphereResource r) { - final AtmosphereResponse response = r.getResponse(); - final AtmosphereRequest request = r.getRequest(); - - response.headers().put("Content-Type", "application/json; charset=UTF-8"); - ObjectNode json = new ObjectNode(JsonNodeFactory.instance); - json.put("websocket", supportWebSocket); - json.putArray("origins").add("*:*"); - json.put("entropy", new Random().nextInt()); - r.write(JsonCodec.encode(json)); - - if (baseURL.get().isEmpty()) { - baseURL.set(request.getRequestURI().substring(0, request.getRequestURI().indexOf("/info"))); - } - - return Action.CANCELLED; - } - - private static String[] params(String urlFragment, int pos) { - if (pos <= 0) { - throw new IllegalArgumentException("pos must be greater then zero"); - } - - String s = urlFragment; - int currPos = 0; - if (s.startsWith("/")) { - currPos++; - } - - List params = new ArrayList(); - int slashPos = -1; - String token = null; - while (params.size() < pos) { - slashPos = s.indexOf('/', currPos); - if (slashPos > 0) { - token = s.substring(currPos, slashPos); - currPos = slashPos + 1; - params.add(token); - } else { - break; - } - } - - if (params.size() < pos) { - throw new IllegalArgumentException( - String.format("the number of tokens in the url fragment passed as argument '%s' is less than the number required %d", urlFragment, pos)); - } - - return params.toArray(new String[params.size()]); - } - - private void configureTransport(AtmosphereResourceImpl r, String s, boolean hasSession) { - if ("websocket".equals(s)) { - r.transport(WEBSOCKET).addEventListener(new WebSocketTransport()); - } else if ("xhr".equals(s) || "xdr".equals(s)) { - r.transport(LONG_POLLING); - - if (!hasSession) { - r.addEventListener(new LongPollingTransport()); - } - } else if ("xhr_streaming".equals(s)) { - r.transport(STREAMING).addEventListener(new StreamingTransport()); - } else if ("jsonp".equals(s)) { - r.transport(JSONP); - - if (!hasSession) { - r.addEventListener(new JSONPTransport()); - } - } else if ("eventsource".equals(s)) { - r.transport(SSE).addEventListener(new SSETransport()); - } else if (s.indexOf("_send") != -1) { - r.transport(POLLING); - } else if ("htmlfile".equals(s)) { - r.transport(HTMLFILE).addEventListener(new HtmlFileTransport()); - } else if (s.indexOf("_send") != -1) { - } else { - r.transport(UNDEFINED).addEventListener(new StreamingTransport()); - } - } - - private void installWriter(final AtmosphereResource r, final String sessionId) { - final AtmosphereResource.TRANSPORT transport = r.transport(); - final AtmosphereResponse response = r.getResponse(); - - AsyncIOWriter writer = response.getAsyncIOWriter(); - if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) { - AtmosphereInterceptorWriter.class.cast(writer).interceptor(new AsyncIOInterceptorAdapter() { - @Override - public byte[] transformPayload(AtmosphereResponse response, byte[] responseDraft, byte[] data) throws IOException { - String charEncoding = response.getCharacterEncoding() == null ? "UTF-8" : response.getCharacterEncoding(); - String s = new String(responseDraft, charEncoding); - - // Ugly. - if (s.equalsIgnoreCase("h") || s.equals("c") || (s.equals("o\n") && r.transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET))) { - return s.getBytes(); - } - - if (!s.isEmpty()) { - try { - if (transport.equals(JSONP)) { - return ("a" + s).getBytes(charEncoding); - } else if (transport.equals(HTMLFILE)) { - StringBuilder sb = new StringBuilder(); - sb.append("\n"); - return (sb.toString()).getBytes(charEncoding); - } else { - return ("a[\"" + StringEscapeUtils.escapeJavaScript(s) + "\"]\n").getBytes(charEncoding); - - } - } catch (Exception e) { - logger.error("", e); - return "".getBytes(); - } - } - - return s.getBytes(); - } - }); - } else { - logger.warn("Unable to apply {}. Your AsyncIOWriter must implement {}", getClass().getName(), AtmosphereInterceptorWriter.class.getName()); - } - - r.addEventListener(new AtmosphereResourceEventListenerAdapter() { - @Override - public void onDisconnect(AtmosphereResourceEvent event) { - sessions.remove(sessionId); - } - }); - } - - private Action injectMessage(AtmosphereResource r) { - final AtmosphereResponse response = r.getResponse(); - final AtmosphereRequest request = r.getRequest(); - - try { - String body = IOUtils.readEntirely(r).toString(); - if (!body.isEmpty() && body.startsWith("d=")) { - body = URLDecoder.decode(body, "UTF-8"); - body = body.substring(2); - response.setStatus(200); - response.write("ok", true).flushBuffer(); - reInject(request, response, body); - } else { - String[] messages = parseMessageString(body); - for (String m : messages) { - if (m == null) continue; - reInject(request, response, m); - } - response.setStatus(204); - } - } catch (Exception e) { - logger.error("", e); - } - return Action.CANCELLED; - } - - private void reInject(AtmosphereRequest request, AtmosphereResponse response, String body) throws IOException, ServletException { - request.setAttribute("sockjs.skipInterceptor", Boolean.TRUE); - framework.doCometSupport(request.body(body), response); - request.setAttribute("sockjs.skipInterceptor", null); - } - - private String[] parseMessageString(String msgs) { - try { - String[] parts; - if (msgs.startsWith("[")) { - //JSON array - parts = (String[]) JsonCodec.decodeValue(msgs, String[].class); - } else { - //JSON string - String str = (String) JsonCodec.decodeValue(msgs, String.class); - parts = new String[]{str}; - } - return parts; - } catch (Exception e) { - return null; - } - } -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockjsSession.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockjsSession.java deleted file mode 100644 index 684083d1b..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/SockjsSession.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -public class SockjsSession { -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/StreamingTransport.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/StreamingTransport.java deleted file mode 100644 index 257c682ae..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/StreamingTransport.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class StreamingTransport extends TransportBasedListener { - private static final Logger logger = LoggerFactory.getLogger(StreamingTransport.class); - - private static final byte[] padding; - private static final String paddingText; - - static { - StringBuilder whitespace = new StringBuilder(); - for (int i = 0; i < 2048; i++) { - whitespace.append("h"); - } - whitespace.append("\n"); - paddingText = whitespace.toString(); - padding = paddingText.getBytes(); - } - - @Override - public void onPreSuspend(AtmosphereResourceEvent event) { - AtmosphereResponse response = event.getResource().getResponse(); - response.setContentType("application/javascript"); - try { - - response.write(padding, true).flushBuffer(); - response.write("o\n".getBytes(), true).flushBuffer(); - } catch (IOException e) { - logger.trace("", e); - } - } - -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/TransportBasedListener.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/TransportBasedListener.java deleted file mode 100644 index 7d102c9e8..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/TransportBasedListener.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResourceEventListenerAdapter; - -public class TransportBasedListener extends AtmosphereResourceEventListenerAdapter { - @Override - public void onClose(AtmosphereResourceEvent event) { - StringBuilder sb = new StringBuilder("c["); - // TODO: Code - sb.append(String.valueOf("500")).append(",\""); - sb.append("Closed").append("\"]"); - event.getResource().write(sb.toString()); - } -} diff --git a/sockjs/modules/src/main/java/org/atmosphere/sockjs/WebSocketTransport.java b/sockjs/modules/src/main/java/org/atmosphere/sockjs/WebSocketTransport.java deleted file mode 100644 index 9b69b503f..000000000 --- a/sockjs/modules/src/main/java/org/atmosphere/sockjs/WebSocketTransport.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.sockjs; - -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResponse; - -public class WebSocketTransport extends TransportBasedListener { - @Override - public void onPreSuspend(AtmosphereResourceEvent event) { - AtmosphereResponse response = event.getResource().getResponse(); - response.setContentType("text/plain"); - - response.write("o\n".getBytes()); - } -} diff --git a/sockjs/modules/src/main/resources/META-INF/services/org.atmosphere.cpr.AtmosphereFramework b/sockjs/modules/src/main/resources/META-INF/services/org.atmosphere.cpr.AtmosphereFramework deleted file mode 100644 index 6462ea3d3..000000000 --- a/sockjs/modules/src/main/resources/META-INF/services/org.atmosphere.cpr.AtmosphereFramework +++ /dev/null @@ -1,4 +0,0 @@ -INSTALL -org.atmosphere.sockjs.SockJsAtmosphereInterceptor -EXCLUDE -org.atmosphere.client.TrackMessageSizeInterceptor \ No newline at end of file diff --git a/spring/modules/pom.xml b/spring/modules/pom.xml index a1813a334..87b34b177 100644 --- a/spring/modules/pom.xml +++ b/spring/modules/pom.xml @@ -3,13 +3,13 @@ org.atmosphere atmosphere-extensions-project - 2.6.6-SNAPSHOT + 3.0.0-SNAPSHOT ../../pom.xml org.atmosphere atmosphere-spring jar - 2.6.6-SNAPSHOT + 3.0.0-SNAPSHOT atmosphere-spring https://github.com/Atmosphere/atmosphere @@ -17,7 +17,7 @@ org.atmosphere atmosphere-runtime - ${atmosphere3-version} + ${atmosphere-version} jakarta.servlet @@ -32,4 +32,8 @@ ${spring-version} + + + none + diff --git a/weblogic/modules/pom.xml b/weblogic/modules/pom.xml deleted file mode 100755 index 4b88a6b12..000000000 --- a/weblogic/modules/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - org.atmosphere - atmosphere-extensions-project - 2.6.6-SNAPSHOT - ../../pom.xml - - 4.0.0 - org.atmosphere - atmosphere-weblogic - bundle - 2.6.6-SNAPSHOT - atmosphere-weblogic - https://github.com/Atmosphere/atmosphere - - install - - - src/main/resources - - - - - src/test/resources - - - - - org.apache.felix - maven-bundle-plugin - ${felix-version} - true - - - * - - org.atmosphere.weblogic.* - - - - - - osgi-bundle - package - - bundle - - - - - - - - - org.atmosphere - atmosphere-runtime - ${atmosphere-version} - provided - - - javax.servlet - javax.servlet-api - ${servlet-version} - provided - - - diff --git a/weblogic/modules/src/main/java/org/atmosphere/weblogic/AtmosphereWebLogicServlet.java b/weblogic/modules/src/main/java/org/atmosphere/weblogic/AtmosphereWebLogicServlet.java deleted file mode 100644 index d67ff9795..000000000 --- a/weblogic/modules/src/main/java/org/atmosphere/weblogic/AtmosphereWebLogicServlet.java +++ /dev/null @@ -1,137 +0,0 @@ - /* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.weblogic; - - import org.atmosphere.cpr.Action; -import org.atmosphere.cpr.AsynchronousProcessor; -import org.atmosphere.cpr.AtmosphereFramework; -import org.atmosphere.cpr.AtmosphereRequestImpl; -import org.atmosphere.cpr.AtmosphereResponseImpl; -import org.atmosphere.cpr.AtmosphereServlet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import weblogic.servlet.http.AbstractAsyncServlet; -import weblogic.servlet.http.RequestResponseKey; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import java.io.IOException; - -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResponse; - -/** - * WebLogic Comet implementation. - */ -public class AtmosphereWebLogicServlet extends AbstractAsyncServlet { - - protected static final Logger logger = LoggerFactory.getLogger(AtmosphereServlet.class); - protected AtmosphereFramework framework; - - /** - * Create an Atmosphere Servlet. - */ - public AtmosphereWebLogicServlet() { - this(false); - } - - /** - * Create an Atmosphere Servlet. - * - * @param isFilter true if this instance is used as an {@link org.atmosphere.cpr.AtmosphereFilter} - */ - public AtmosphereWebLogicServlet(boolean isFilter) { - this(isFilter, true); - } - - /** - * Create an Atmosphere Servlet. - * - * @param isFilter true if this instance is used as an {@link org.atmosphere.cpr.AtmosphereFilter} - */ - public AtmosphereWebLogicServlet(boolean isFilter, boolean autoDetectHandlers) { - framework = new AtmosphereFramework(isFilter, autoDetectHandlers); - } - - @Override - public void destroy() { - framework.destroy(); - } - - public void init(final ServletConfig sc) throws ServletException { - super.init(sc); - framework.setAsyncSupport(new WebLogicCometSupport(framework.getAtmosphereConfig())); - framework.init(sc); - } - - public AtmosphereFramework framework() { - return framework; - } - - /** - * Weblogic specific comet based implementation. - * - * @param rrk - * @return true if suspended - * @throws java.io.IOException - * @throws javax.servlet.ServletException - */ - protected boolean doRequest(RequestResponseKey rrk) throws IOException, ServletException { - try { - AtmosphereRequest req = AtmosphereRequestImpl.wrap(rrk.getRequest()); - AtmosphereResponse resp = AtmosphereResponseImpl.wrap(rrk.getResponse()); - Action action = framework.doCometSupport(req , resp); - rrk.getRequest().getSession().setAttribute(WebLogicCometSupport.RRK + resp.uuid(), rrk); - if (action.type() == Action.TYPE.SUSPEND) { - if (action.timeout() == -1) { - rrk.setTimeout(Integer.MAX_VALUE); - } else { - rrk.setTimeout((int) action.timeout()); - } - } - return action.type() == Action.TYPE.SUSPEND; - } catch (IllegalStateException ex) { - logger.error("AtmosphereServlet.doRequest exception", ex); - throw ex; - } - } - - /** - * Weblogic specific comet based implementation. - * - * @param rrk - * @throws java.io.IOException - * @throws javax.servlet.ServletException - */ - protected void doResponse(RequestResponseKey rrk, Object context) - throws IOException, ServletException { - rrk.getResponse().flushBuffer(); - } - - /** - * Weblogic specific comet based implementation. - * - * @param rrk - * @throws java.io.IOException - * @throws javax.servlet.ServletException - */ - protected void doTimeout(RequestResponseKey rrk) throws IOException, ServletException { - ((AsynchronousProcessor) framework.getAsyncSupport()).timedout(AtmosphereRequestImpl.wrap(rrk.getRequest()), - AtmosphereResponseImpl.wrap(rrk.getResponse())); - } - - -} diff --git a/weblogic/modules/src/main/java/org/atmosphere/weblogic/WebLogicCometSupport.java b/weblogic/modules/src/main/java/org/atmosphere/weblogic/WebLogicCometSupport.java deleted file mode 100644 index 753652d1b..000000000 --- a/weblogic/modules/src/main/java/org/atmosphere/weblogic/WebLogicCometSupport.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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. - */ -/* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can obtain - * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html - * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. - * Sun designates this particular file as subject to the "Classpath" exception - * as provided by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the License - * Header, with the fields enclosed by brackets [] replaced by your own - * identifying information: "Portions Copyrighted [year] - * [name of copyright owner]" - * - * Contributor(s): - * - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - * - */ -package org.atmosphere.weblogic; - -import org.atmosphere.cpr.Action; -import org.atmosphere.cpr.ApplicationConfig; -import org.atmosphere.cpr.AsynchronousProcessor; -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResourceImpl; -import org.atmosphere.cpr.AtmosphereResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import weblogic.servlet.http.AbstractAsyncServlet; -import weblogic.servlet.http.RequestResponseKey; - -import javax.servlet.ServletException; -import java.io.IOException; - -/** - * Weblogic support. - * - * @author Jeanfrancois Arcand - */ -public class WebLogicCometSupport extends AsynchronousProcessor { - - private static final Logger logger = LoggerFactory.getLogger(WebLogicCometSupport.class); - - public static final String RRK = "RequestResponseKey-"; - - public WebLogicCometSupport(AtmosphereConfig config) { - super(config); - } - - /** - * {@inheritDoc} - */ - public Action service(AtmosphereRequest req, AtmosphereResponse res) - throws IOException, ServletException { - Action action = suspended(req, res); - if (action.type() == Action.TYPE.SUSPEND) { - logger.debug("Suspending response: {}", res); - } else if (action.type() == Action.TYPE.RESUME) { - logger.debug("Resuming response: {}", res); - - Action nextAction = resumed(req, res); - if (nextAction.type() == Action.TYPE.SUSPEND) { - logger.debug("Suspending after resuming response: {}", res); - } - } - return action; - } - - /** - * {@inheritDoc} - */ - @Override - public void action(AtmosphereResourceImpl actionEvent) { - super.action(actionEvent); - if (actionEvent.isInScope() && actionEvent.action().type() == Action.TYPE.RESUME) { - try { - RequestResponseKey rrk = (RequestResponseKey) actionEvent.getRequest().getSession().getAttribute(RRK + actionEvent.uuid()); - AbstractAsyncServlet.notify(rrk, null); - } catch (IOException ex) { - logger.debug("action failed", ex); - } - } - } - -} diff --git a/weblogic/modules/src/main/java/weblogic/servlet/http/AbstractAsyncServlet.java b/weblogic/modules/src/main/java/weblogic/servlet/http/AbstractAsyncServlet.java deleted file mode 100755 index 7272b14d7..000000000 --- a/weblogic/modules/src/main/java/weblogic/servlet/http/AbstractAsyncServlet.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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. - */ -/* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can obtain - * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html - * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. - * Sun designates this particular file as subject to the "Classpath" exception - * as provided by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the License - * Header, with the fields enclosed by brackets [] replaced by your own - * identifying information: "Portions Copyrighted [year] - * [name of copyright owner]" - * - * Contributor(s): - * - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - * - */ -package weblogic.servlet.http; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import java.io.IOException; - -/** - * Fake support for Weblogic. Weblogic jars aren't public and not available with - * any repository, so fake them. - * - * @author Jeanfrancois Arcand - */ -public abstract class AbstractAsyncServlet extends HttpServlet { - - protected abstract boolean doRequest(RequestResponseKey rrk) - throws IOException, ServletException; - - protected abstract void doResponse(RequestResponseKey rrk, Object o) - throws IOException, ServletException; - - protected abstract void doTimeout(RequestResponseKey rrk) - throws IOException, ServletException; - - public final static void notify(RequestResponseKey rrk, Object context) throws IOException { - return; - } - -} diff --git a/weblogic/modules/src/main/java/weblogic/servlet/http/RequestResponseKey.java b/weblogic/modules/src/main/java/weblogic/servlet/http/RequestResponseKey.java deleted file mode 100755 index 078f95bd3..000000000 --- a/weblogic/modules/src/main/java/weblogic/servlet/http/RequestResponseKey.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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. - */ -/* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2007-2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can obtain - * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html - * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. - * Sun designates this particular file as subject to the "Classpath" exception - * as provided by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the License - * Header, with the fields enclosed by brackets [] replaced by your own - * identifying information: "Portions Copyrighted [year] - * [name of copyright owner]" - * - * Contributor(s): - * - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - * - */ - -package weblogic.servlet.http; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Fake Weblogic class to allow compilation of support for that web container. - * - * @author Jeanfrancois Arcand - */ -public class RequestResponseKey { - public HttpServletRequest getRequest() { - throw new UnsupportedOperationException("Please remove the atmosphere-compat-weblogic from your classpath"); - } - - public HttpServletResponse getResponse() { - throw new UnsupportedOperationException("Please remove the atmosphere-compat-weblogic from your classpath"); - } - - public void setTimeout(int i) { - throw new UnsupportedOperationException("Please remove the atmosphere-compat-weblogic from your classpath"); - } -} diff --git a/xmpp/modules/pom.xml b/xmpp/modules/pom.xml deleted file mode 100755 index 45d63b1f3..000000000 --- a/xmpp/modules/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - org.atmosphere - atmosphere-extensions-project - 2.6.6-SNAPSHOT - ../../pom.xml - - 4.0.0 - org.atmosphere - atmosphere-xmpp - bundle - 2.6.6-SNAPSHOT - atmosphere-xmpp - https://github.com/Atmosphere/atmosphere - - install - - - org.apache.felix - maven-bundle-plugin - ${felix-version} - true - - - * - - org.atmosphere.plugin.xmpp.* - - - - - - osgi-bundle - package - - bundle - - - - - - - - - org.atmosphere - atmosphere-jersey - ${atmosphere-version} - provided - - - jivesoftware - smack - 3.1.0 - - - javax.servlet - javax.servlet-api - ${servlet-version} - provided - - - diff --git a/xmpp/modules/src/main/java/org/atmosphere/plugin/xmpp/XMPPBroadcaster.java b/xmpp/modules/src/main/java/org/atmosphere/plugin/xmpp/XMPPBroadcaster.java deleted file mode 100644 index 84374e78c..000000000 --- a/xmpp/modules/src/main/java/org/atmosphere/plugin/xmpp/XMPPBroadcaster.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2008-2022 Async-IO.org - * - * 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.atmosphere.plugin.xmpp; - - -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.Broadcaster; -import org.atmosphere.util.AbstractBroadcasterProxy; -import org.jivesoftware.smack.Chat; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.MessageListener; -import org.jivesoftware.smack.SASLAuthentication; -import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.packet.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; - -/** - * Simple {@link org.atmosphere.cpr.Broadcaster} implementation based on Smack, and XMPP library. - * - * @author Jeanfrancois Arcand - */ -public class XMPPBroadcaster extends AbstractBroadcasterProxy { - - private static final Logger logger = LoggerFactory.getLogger(XMPPBroadcaster.class); - - private static final String XMPP_AUTH = XMPPBroadcaster.class.getName() + ".authorization"; - private static final String XMPP_SERVER = XMPPBroadcaster.class.getName() + ".server"; - private static final String XMPP_DEBUG = XMPPBroadcaster.class.getName() + ".debug"; - - private String authToken; - private XMPPConnection xmppConnection; - private Chat channel; - - public XMPPBroadcaster() {} - - public Broadcaster initialize(String id, AtmosphereConfig config) { - return initialize(id, URI.create("http://gmail.com"), config); - } - - public Broadcaster initialize(String id, URI uri, AtmosphereConfig config) { - return initialize(id, uri, config); - } - - private synchronized void setUp() { - - try { - - if (config != null) { - if (config.getServletConfig().getInitParameter(XMPP_AUTH) != null) { - authToken = config.getServletConfig().getInitParameter(XMPP_AUTH); - } else { - throw new IllegalStateException("No authorization token specified. Please make sure your web.xml contains:" + - "\n \n" + - " org.atmosphere.plugin.xmpp.XMPPBroadcaster.authorization\n" + - " principal:password\n" + - " "); - } - - if (config.getServletConfig().getInitParameter(XMPP_SERVER) != null) { - uri = URI.create(config.getServletConfig().getInitParameter(XMPP_SERVER)); - } else if (uri == null) { - throw new NullPointerException("uri cannot be null"); - } - - if (config.getServletConfig().getInitParameter(XMPP_DEBUG) != null) { - XMPPConnection.DEBUG_ENABLED = true; - } - } - - ConnectionConfiguration config = null; - int port = -1; - try { - port = uri.getPort(); - } catch (Throwable t) { - ; - } - if (port == -1) { - config = new ConnectionConfiguration(uri.getHost()); - } else { - config = new ConnectionConfiguration(uri.getHost(), port); - - } - - xmppConnection = new XMPPConnection(config); - xmppConnection.connect(); - SASLAuthentication.supportSASLMechanism("PLAIN", 0); - String[] credentials = authToken.split(":"); - - xmppConnection.login(credentials[0], credentials[1], getID()); - - logger.info("Subscribing to: " + getID()); - channel = xmppConnection.getChatManager().createChat(getID(), new MessageListener() { - - public void processMessage(Chat chat, Message message) { - broadcastReceivedMessage(message.getBody()); - } - }); - - logger.info("Connected to: " + getID()); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } - - @Override - public void setID(String id) { - super.setID(id); - setUp(); - } - - /** - * {@inheritDoc} - */ - @Override - public void destroy() { - super.destroy(); - synchronized (xmppConnection) { - if (xmppConnection != null) { - xmppConnection.disconnect(); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public void incomingBroadcast() { - } - - /** - * {@inheritDoc} - */ - @Override - public void outgoingBroadcast(Object message) { - if (message instanceof String) { - try { - channel.sendMessage(message.toString()); - } catch (XMPPException e) { - logger.debug("failed to send message on channel", e); - } - } - } -} \ No newline at end of file