!htj move RequestVal classes to javadsl.server.values
This commit is contained in:
parent
45a410b02a
commit
10ea40b2f8
23 changed files with 142 additions and 38 deletions
|
|
@ -10,7 +10,7 @@ import scala.concurrent.duration._
|
|||
import akka.stream.ActorMaterializer
|
||||
import akka.http.scaladsl.server
|
||||
import akka.http.javadsl.model.HttpRequest
|
||||
import akka.http.javadsl.server.{ Route, Directives }
|
||||
import akka.http.javadsl.server.{ AllDirectives, Route, Directives }
|
||||
import akka.http.impl.util.JavaMapping.Implicits._
|
||||
import akka.http.impl.server.RouteImplementation
|
||||
import akka.http.scaladsl.model.HttpResponse
|
||||
|
|
@ -19,7 +19,7 @@ import akka.actor.ActorSystem
|
|||
import akka.event.NoLogging
|
||||
import akka.http.impl.util._
|
||||
|
||||
abstract class RouteTest {
|
||||
abstract class RouteTest extends AllDirectives {
|
||||
implicit def system: ActorSystem
|
||||
implicit def materializer: ActorMaterializer
|
||||
implicit def executionContext: ExecutionContext = system.dispatcher
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ package akka.http.javadsl.server.examples.simple;
|
|||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.http.javadsl.server.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SimpleServerApp8 extends HttpApp {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package akka.http.javadsl.server;
|
|||
import akka.http.scaladsl.model.HttpRequest;
|
||||
import org.junit.Test;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
|
||||
public class HandlerBindingTest extends JUnitRouteTest {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ package akka.http.javadsl.server.examples.petstore;
|
|||
import akka.actor.ActorSystem;
|
||||
import akka.http.javadsl.marshallers.jackson.Jackson;
|
||||
import akka.http.javadsl.server.*;
|
||||
import akka.http.javadsl.server.values.PathMatcher;
|
||||
import akka.http.javadsl.server.values.PathMatchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ package akka.http.javadsl.server.examples.simple;
|
|||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.http.javadsl.server.*;
|
||||
import akka.http.javadsl.server.values.Parameter;
|
||||
import akka.http.javadsl.server.values.Parameters;
|
||||
import akka.http.javadsl.server.values.PathMatcher;
|
||||
import akka.http.javadsl.server.values.PathMatchers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
package akka.http.javadsl.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import akka.dispatch.Futures;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
|
||||
import akka.http.javadsl.marshallers.jackson.Jackson;
|
||||
import akka.http.javadsl.model.HttpRequest;
|
||||
import akka.http.javadsl.model.MediaTypes;
|
||||
import org.junit.Test;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
|
||||
public class CompleteTest extends JUnitRouteTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package akka.http.javadsl.server;
|
||||
|
||||
import akka.http.scaladsl.model.HttpRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.http.scaladsl.model.HttpRequest;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
|
||||
public class HandlerBindingTest extends JUnitRouteTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
package akka.http.javadsl.server.directives;
|
||||
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.http.javadsl.model.HttpRequest;
|
||||
import akka.http.javadsl.model.headers.AcceptEncoding;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server.directives;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.http.javadsl.model.*;
|
||||
import akka.http.javadsl.server.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
|
||||
public class ExecutionDirectivesTest extends JUnitRouteTest {
|
||||
@Test
|
||||
public void testCatchExceptionThrownFromHandler() {
|
||||
Parameter<Integer> a = Parameters.integer("a");
|
||||
Parameter<Integer> b = Parameters.integer("b");
|
||||
Handler2<Integer, Integer> divide =
|
||||
new Handler2<Integer, Integer>() {
|
||||
@Override
|
||||
public RouteResult handle(RequestContext ctx, Integer a, Integer b) {
|
||||
int result = a / b;
|
||||
return ctx.complete("The result is: " + result);
|
||||
}
|
||||
};
|
||||
|
||||
ExceptionHandler handleDivByZero =
|
||||
new ExceptionHandler() {
|
||||
@Override
|
||||
public Route handle(RuntimeException exception) {
|
||||
try {
|
||||
throw exception;
|
||||
} catch(ArithmeticException t) {
|
||||
return complete(
|
||||
HttpResponse.create()
|
||||
.withStatus(400)
|
||||
.withEntity("Congratulations you provoked a division by zero!"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TestRoute route =
|
||||
testRoute(
|
||||
handleExceptions(handleDivByZero,
|
||||
path("divide").route(
|
||||
handleWith(a, b, divide)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
route.run(HttpRequest.GET("/divide?a=10&b=5"))
|
||||
.assertEntity("The result is: 2");
|
||||
|
||||
route.run(HttpRequest.GET("/divide?a=10&b=0"))
|
||||
.assertStatusCode(400)
|
||||
.assertEntity("Congratulations you provoked a division by zero!");
|
||||
}
|
||||
}
|
||||
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
package akka.http.javadsl.server.directives;
|
||||
|
||||
import akka.http.javadsl.server.values.PathMatcher;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import akka.http.javadsl.server.*;
|
||||
import akka.http.javadsl.server.values.*;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
import akka.http.scaladsl.model.HttpRequest;
|
||||
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
|
||||
public class PathDirectivesTest extends JUnitRouteTest {
|
||||
@Test
|
||||
public void testPathPrefixAndPath() {
|
||||
|
|
@ -87,7 +87,7 @@ public class PathDirectivesTest extends JUnitRouteTest {
|
|||
public void testSingleSlash() {
|
||||
TestRoute route =
|
||||
testRoute(
|
||||
pathSingleSlash().route(complete("Ok"))
|
||||
pathSingleSlash().route(complete("Ok"))
|
||||
);
|
||||
|
||||
route.run(HttpRequest.GET("/"))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server.directives;
|
||||
package akka.http.javadsl.server.values;
|
||||
|
||||
import org.junit.Test;
|
||||
import scala.Option;
|
||||
|
|
@ -12,10 +12,8 @@ import akka.http.javadsl.server.*;
|
|||
import akka.http.javadsl.model.HttpRequest;
|
||||
import akka.http.javadsl.model.headers.Authorization;
|
||||
import akka.http.javadsl.testkit.*;
|
||||
import akka.http.javadsl.server.*;
|
||||
import static akka.http.javadsl.server.Directives.*;
|
||||
|
||||
public class AuthenticationDirectivesTest extends JUnitRouteTest {
|
||||
public class HttpBasicAuthenticationTest extends JUnitRouteTest {
|
||||
HttpBasicAuthenticator<String> authenticatedUser =
|
||||
new HttpBasicAuthenticator<String>("test-realm") {
|
||||
@Override
|
||||
|
|
@ -14,7 +14,7 @@ package akka.http.javadsl.server;
|
|||
*
|
||||
* See https://issues.scala-lang.org/browse/SI-9013
|
||||
*/
|
||||
abstract class AbstractDirective implements Directive {
|
||||
public abstract class AbstractDirective implements Directive {
|
||||
@Override
|
||||
public Route route(Route first, Route... others) {
|
||||
return createRoute(first, others);
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package akka.http.impl.server
|
||||
|
||||
import akka.http.javadsl.server.values.Parameter
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.reflect.ClassTag
|
||||
import akka.http.javadsl.server.Parameter
|
||||
import akka.http.scaladsl.server.directives.{ ParameterDirectives, BasicDirectives }
|
||||
import akka.http.scaladsl.server.Directive1
|
||||
import akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
|
||||
|
|
@ -17,7 +18,6 @@ import akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
|
|||
private[http] class ParameterImpl[T: ClassTag](val underlying: ExecutionContext ⇒ ParamMagnet { type Out = Directive1[T] })
|
||||
extends StandaloneExtractionImpl[T] with Parameter[T] {
|
||||
|
||||
//def extract(ctx: RequestContext): Future[T] =
|
||||
def directive: Directive1[T] =
|
||||
BasicDirectives.extractExecutionContext.flatMap { implicit ec ⇒
|
||||
ParameterDirectives.parameter(underlying(ec))
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
package akka.http.impl.server
|
||||
|
||||
import akka.http.javadsl.server.values.PathMatcher
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
import akka.http.javadsl.server.PathMatcher
|
||||
import akka.http.scaladsl.server.{ PathMatcher ⇒ ScalaPathMatcher }
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package akka.http.impl.server
|
||||
|
||||
import akka.http.javadsl.server.values.{ PathMatcher, BasicUserCredentials }
|
||||
|
||||
import scala.language.implicitConversions
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.immutable
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
package akka.http.impl.server
|
||||
|
||||
import java.io.File
|
||||
import akka.http.javadsl.server.values.{ PathMatcher, HttpBasicAuthenticator }
|
||||
|
||||
import scala.language.existentials
|
||||
import scala.collection.immutable
|
||||
import akka.http.javadsl.model.{ DateTime, ContentType, HttpMethod }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server
|
||||
|
||||
trait ExceptionHandler {
|
||||
def handle(exception: RuntimeException): Route
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package akka.http.javadsl.server
|
||||
|
||||
import akka.http.javadsl.server.values.{ PathMatcher, HttpBasicAuthenticator }
|
||||
|
||||
/**
|
||||
* Represents a value that can be extracted from a request.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server
|
||||
package directives
|
||||
|
||||
import akka.http.impl.server.RouteStructure
|
||||
|
||||
import scala.annotation.varargs
|
||||
|
||||
abstract class ExecutionDirectives extends CodingDirectives {
|
||||
/**
|
||||
* Handles exceptions in the inner routes using the specified handler.
|
||||
*/
|
||||
@varargs
|
||||
def handleExceptions(handler: ExceptionHandler, innerRoutes: Route*): Route =
|
||||
RouteStructure.HandleExceptions(handler, innerRoutes.toVector)
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ package akka.http.javadsl.server
|
|||
package directives
|
||||
|
||||
import akka.http.impl.server.RouteStructure
|
||||
import akka.http.javadsl.server.values.{ PathMatchers, PathMatcher }
|
||||
|
||||
import scala.annotation.varargs
|
||||
import scala.collection.immutable
|
||||
|
|
|
|||
|
|
@ -2,15 +2,14 @@
|
|||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server
|
||||
package akka.http.javadsl.server.values
|
||||
|
||||
import akka.http.impl.server.{ ExtractionImplBase, ExtractionImpl, RouteStructure }
|
||||
import akka.http.impl.server.{ ExtractionImplBase, RouteStructure }
|
||||
import akka.http.javadsl.server.{ AbstractDirective, RequestVal, Route }
|
||||
import akka.http.scaladsl.util.FastFuture
|
||||
|
||||
import scala.annotation.varargs
|
||||
import scala.concurrent.Future
|
||||
import scala.reflect
|
||||
import reflect.ClassTag
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
/**
|
||||
* Represents existing or missing HTTP Basic authentication credentials.
|
||||
|
|
@ -2,17 +2,17 @@
|
|||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server
|
||||
package akka.http.javadsl.server.values
|
||||
|
||||
import java.{ lang ⇒ jl }
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import akka.http.impl.server.ParameterImpl
|
||||
import akka.http.javadsl.server.RequestVal
|
||||
import akka.http.scaladsl.server.Directive1
|
||||
import akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
|
||||
import akka.http.scaladsl.common.ToNameReceptacleEnhancements
|
||||
import akka.http.impl.server.ParameterImpl
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
/**
|
||||
* A RequestVal representing a query parameter of type T.
|
||||
|
|
@ -24,7 +24,7 @@ trait Parameter[T] extends RequestVal[T]
|
|||
* FIXME: add tests, see #16437
|
||||
*/
|
||||
object Parameters {
|
||||
import ToNameReceptacleEnhancements._
|
||||
import akka.http.scaladsl.common.ToNameReceptacleEnhancements._
|
||||
|
||||
/**
|
||||
* A string query parameter.
|
||||
|
|
@ -2,13 +2,16 @@
|
|||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.javadsl.server
|
||||
package akka.http.javadsl.server.values
|
||||
|
||||
import java.{ lang ⇒ jl, util ⇒ ju }
|
||||
import scala.reflect.ClassTag
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
import akka.http.impl.server.PathMatcherImpl
|
||||
import akka.http.scaladsl.server.{ PathMatchers ⇒ ScalaPathMatchers, PathMatcher0, PathMatcher1 }
|
||||
import akka.http.javadsl.server.RequestVal
|
||||
import akka.http.scaladsl.server.{ PathMatcher0, PathMatcher1, PathMatchers ⇒ ScalaPathMatchers }
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
/**
|
||||
* A PathMatcher is used to match the (yet unmatched) URI path of incoming requests.
|
||||
Loading…
Add table
Add a link
Reference in a new issue