Skip to content

Commit

Permalink
Merge pull request #56 from PedroBatista/play3.0_with_atmosphere3
Browse files Browse the repository at this point in the history
Update working with Play3.0 & Atmosphere 3
  • Loading branch information
jfarcand committed Apr 2, 2024
2 parents 2dfa6a5 + 731e56c commit c81e6f2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 45 deletions.
11 changes: 7 additions & 4 deletions module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
<artifactId>atmosphere-runtime</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play_2.12</artifactId>
<groupId>org.playframework</groupId>
<artifactId>play_3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0-M2</version>
</dependency>



<!-- Test -->
<dependency>
<groupId>com.ning</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.atmosphere.play;

import akka.actor.ActorSystem;
import akka.stream.Materializer;
import akka.stream.OverflowStrategy;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.stream.Materializer;
import org.apache.pekko.stream.OverflowStrategy;
import org.apache.commons.lang3.StringUtils;
import org.atmosphere.config.service.Singleton;
import org.atmosphere.cpr.AtmosphereConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.atmosphere.play;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.util.ByteString;
import org.apache.pekko.actor.AbstractActor;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.Props;
import org.apache.pekko.util.ByteString;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResponseImpl;
Expand Down Expand Up @@ -55,7 +55,16 @@ public void preStart() {
try {
playWebSocket = new PlayWebSocket(actorRef, atmosphereConfig);
webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(atmosphereConfig.framework());
AtmosphereRequest atmosphereRequest = AtmosphereUtils.request(new Http.RequestImpl(requestHeader), additionalAttributes);

Http.Request javaRequest = new Http.RequestBuilder()
.method(requestHeader.method())
.uri(requestHeader.uri())
.headers(requestHeader.headers().asJava())
//.bodyRaw(requestHeader.body().asRaw().asBytes().toArray())
.build();


AtmosphereRequest atmosphereRequest = AtmosphereUtils.request(javaRequest, additionalAttributes);
webSocketProcessor.open(playWebSocket, atmosphereRequest, AtmosphereResponseImpl.newInstance(atmosphereConfig, atmosphereRequest, playWebSocket));
} catch (Throwable throwable) {
LOG.error("Failed to start the actor ", throwable);
Expand Down
12 changes: 6 additions & 6 deletions module/src/main/java/org/atmosphere/play/PlayAsyncIOWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.atmosphere.play;

import akka.NotUsed;
import akka.actor.ActorRef;
import akka.actor.Status;
import akka.stream.OverflowStrategy;
import akka.stream.javadsl.Source;
import akka.util.ByteString;
import org.apache.pekko.NotUsed;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.Status;
import org.apache.pekko.stream.OverflowStrategy;
import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.util.ByteString;
import org.atmosphere.cpr.AsyncIOWriter;
import org.atmosphere.cpr.AsynchronousProcessor;
import org.atmosphere.cpr.AtmosphereInterceptorWriter;
Expand Down
4 changes: 2 additions & 2 deletions module/src/main/java/org/atmosphere/play/PlayWebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.atmosphere.play;

import akka.actor.ActorRef;
import akka.actor.Status;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.Status;
import org.atmosphere.cpr.AtmosphereConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@
*/
package org.atmosphere.play

import javax.inject.Inject
import play.api.http._
import play.api.OptionalDevContext
import play.api.http.*
import play.api.inject.Injector
import play.api.mvc.{BodyParser, Handler, RequestHeader}
import play.api.routing.Router
import play.core.j._
import play.api.mvc.*
import play.core.j.*
import play.mvc.Http
import play.mvc.Http.RequestBody

import javax.inject.{Inject, Provider}
import scala.concurrent.ExecutionContext.Implicits.global


class AtmosphereHttpRequestHandler@Inject()( webCommands: _root_.play.core.WebCommands,
optDevContext: _root_.play.api.OptionalDevContext,
router: _root_.javax.inject.Provider[_root_.play.api.routing.Router],
errorHandler: _root_.play.api.http.HttpErrorHandler,
configuration: _root_.play.api.http.HttpConfiguration,
filters: _root_.play.api.http.HttpFilters,
handlerComponents: _root_.play.core.j.JavaHandlerComponents,
injector: _root_.play.api.inject.Injector
) extends JavaCompatibleHttpRequestHandler( webCommands,
optDevContext,
router,
errorHandler,
configuration,
filters,
handlerComponents) {

class AtmosphereHttpRequestHandler @Inject()(components: JavaHandlerComponents,
router: Router,
errorHandler: HttpErrorHandler,
configuration: HttpConfiguration,
filters: HttpFilters,
injector: Injector)

extends JavaCompatibleHttpRequestHandler(router, errorHandler, configuration, filters, components) {


override def routeRequest(request: RequestHeader) = {
dispatch(request) match {
Expand Down Expand Up @@ -64,13 +72,15 @@ class AtmosphereHttpRequestHandler @Inject()(components: JavaHandlerComponents,
upgradeHeader: Option[String],
connectionHeaders: Seq[String]): Option[Handler] = {
if (AtmosphereCoordinator.instance.matchPath(request.path)) {
val controller: AtmosphereController = Option(injector.instanceOf(controllerClass)).getOrElse(controllerClass.newInstance)
//val controller: AtmosphereController = Option(components.instanceOf(controllerClass)).getOrElse(controllerClass.newInstance)
val controller: AtmosphereController = Option(injector.instanceOf(controllerClass)).getOrElse(controllerClass.getDeclaredConstructor().newInstance())
// Netty fail to decode headers separated by a ','
val javaAction =
if (isWsSupported(upgradeHeader, connectionHeaders))
controller.webSocket(request.asJava)
else
new JavaAction(components) {
// new JavaAction(components) {
new JavaAction(handlerComponents) {
val annotations = new JavaActionAnnotations(controllerClass, controllerClass.getMethod("http", classOf[Http.RequestHeader]), new ActionCompositionConfiguration())
val parser = javaBodyParserToScala(injector.instanceOf(annotations.parser))
def invocation(req : play.mvc.Http.Request) = controller.http(req)
Expand All @@ -94,4 +104,7 @@ class AtmosphereHttpRequestHandler @Inject()(components: JavaHandlerComponents,
}
}

}

}


31 changes: 22 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play_2.12</artifactId>
<version>2.8.15</version>
<groupId>org.playframework</groupId>
<artifactId>play_3</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-actor_3</artifactId>
<version>1.0.3-M1</version>
</dependency>
<dependency>
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-actor-typed_3</artifactId>
<version>1.0.3-M1</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-play</artifactId>
Expand All @@ -71,11 +81,11 @@
<artifactId>logback-core</artifactId>
<version>1.3.12</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<optional>true</optional>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0-M2</version>
</dependency>

<!-- Test -->
Expand Down Expand Up @@ -252,7 +262,10 @@
<distMgmtSnapshotsUrl>http://oss.sonatype.org/content/repositories/snapshots</distMgmtSnapshotsUrl>
<surefire.redirectTestOutputToFile>false</surefire.redirectTestOutputToFile>
<source.property>1.8</source.property>
<target.property>1.8</target.property>
<atmosphere.version>2.7.6</atmosphere.version>
<target.property>11</target.property>
<atmosphere.version>3.0.5</atmosphere.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>

0 comments on commit c81e6f2

Please sign in to comment.