19441: Use Optional instead of Option in http core javadsl
This commit is contained in:
parent
7a39063f2e
commit
57c1dfde8a
54 changed files with 302 additions and 248 deletions
|
|
@ -4,13 +4,14 @@
|
||||||
|
|
||||||
package docs.http.javadsl;
|
package docs.http.javadsl;
|
||||||
|
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.util.ByteString;
|
import akka.util.ByteString;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
//#import-model
|
//#import-model
|
||||||
import akka.http.javadsl.model.*;
|
import akka.http.javadsl.model.*;
|
||||||
import akka.http.javadsl.model.headers.*;
|
import akka.http.javadsl.model.headers.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
//#import-model
|
//#import-model
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -79,12 +80,12 @@ public class ModelDocTest {
|
||||||
//#headers
|
//#headers
|
||||||
|
|
||||||
// a method that extracts basic HTTP credentials from a request
|
// a method that extracts basic HTTP credentials from a request
|
||||||
private Option<BasicHttpCredentials> getCredentialsOfRequest(HttpRequest request) {
|
private Optional<BasicHttpCredentials> getCredentialsOfRequest(HttpRequest request) {
|
||||||
Option<Authorization> auth = request.getHeader(Authorization.class);
|
Optional<Authorization> auth = request.getHeader(Authorization.class);
|
||||||
if (auth.isDefined() && auth.get().credentials() instanceof BasicHttpCredentials)
|
if (auth.isPresent() && auth.get().credentials() instanceof BasicHttpCredentials)
|
||||||
return Option.some((BasicHttpCredentials) auth.get().credentials());
|
return Optional.of((BasicHttpCredentials) auth.get().credentials());
|
||||||
else
|
else
|
||||||
return Option.none();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
//#headers
|
//#headers
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ public class HttpServerExampleDocTest {
|
||||||
.withEntity(ContentTypes.TEXT_HTML_UTF8,
|
.withEntity(ContentTypes.TEXT_HTML_UTF8,
|
||||||
"<html><body>Hello world!</body></html>");
|
"<html><body>Hello world!</body></html>");
|
||||||
else if (uri.path().equals("/hello")) {
|
else if (uri.path().equals("/hello")) {
|
||||||
String name = Util.getOrElse(uri.query().get("name"), "Mister X");
|
String name = uri.query().get("name").orElse("Mister X");
|
||||||
|
|
||||||
return
|
return
|
||||||
HttpResponse.create()
|
HttpResponse.create()
|
||||||
|
|
|
||||||
|
|
@ -209,11 +209,11 @@ public class MigrationsJava {
|
||||||
|
|
||||||
Uri uri = null;
|
Uri uri = null;
|
||||||
//#raw-query
|
//#raw-query
|
||||||
final akka.japi.Option<String> theRawQueryString = uri.rawQueryString();
|
final Optional<String> theRawQueryString = uri.rawQueryString();
|
||||||
//#raw-query
|
//#raw-query
|
||||||
|
|
||||||
//#query-param
|
//#query-param
|
||||||
final akka.japi.Option<String> aQueryParam = uri.query().get("a");
|
final Optional<String> aQueryParam = uri.query().get("a");
|
||||||
//#query-param
|
//#query-param
|
||||||
|
|
||||||
//#file-source-sink
|
//#file-source-sink
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ The ``RequestVal`` builder is made up of 2 steps, initially you need to pick whi
|
||||||
match if the header is not present in the request). This is done using one of the below depicted methods::
|
match if the header is not present in the request). This is done using one of the below depicted methods::
|
||||||
|
|
||||||
RequestVal<T> instance()
|
RequestVal<T> instance()
|
||||||
RequestVal<<Option<T>> optionalInstance()
|
RequestVal<<Optional<T>> optionalInstance()
|
||||||
|
|
||||||
RequestVal<String> value()
|
RequestVal<String> value()
|
||||||
RequestVal<Option<String>> optionalValue()
|
RequestVal<Optional<String>> optionalValue()
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ Illegal stream elements
|
||||||
|
|
||||||
In accordance to the Reactive Streams specification (`Rule 2.13 <https://github.com/reactive-streams/reactive-streams-jvm#2.13>`_)
|
In accordance to the Reactive Streams specification (`Rule 2.13 <https://github.com/reactive-streams/reactive-streams-jvm#2.13>`_)
|
||||||
Akka Streams do not allow ``null`` to be passed through the stream as an element. In case you want to model the concept
|
Akka Streams do not allow ``null`` to be passed through the stream as an element. In case you want to model the concept
|
||||||
of absence of a value we recommend using ``akka.japi.Option`` (for Java 6 and 7) or ``java.util.Optional`` which is available since Java 8.
|
of absence of a value we recommend using ``java.util.Optional`` which is available since Java 8.
|
||||||
|
|
||||||
.. _back-pressure-explained-java:
|
.. _back-pressure-explained-java:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ package akka.http.impl.util;
|
||||||
|
|
||||||
import akka.http.impl.model.JavaUri;
|
import akka.http.impl.model.JavaUri;
|
||||||
import akka.http.javadsl.model.Uri;
|
import akka.http.javadsl.model.Uri;
|
||||||
import akka.japi.Option;
|
import scala.compat.java8.OptionConverters;
|
||||||
import scala.None$;
|
import scala.None$;
|
||||||
import scala.collection.immutable.Map$;
|
import scala.collection.immutable.Map$;
|
||||||
import scala.collection.immutable.Seq;
|
import scala.collection.immutable.Seq;
|
||||||
|
|
@ -14,6 +14,7 @@ import akka.stream.scaladsl.Source;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains internal helper methods.
|
* Contains internal helper methods.
|
||||||
|
|
@ -22,8 +23,8 @@ public abstract class Util {
|
||||||
@SuppressWarnings("unchecked") // no support for covariance of option in Java
|
@SuppressWarnings("unchecked") // no support for covariance of option in Java
|
||||||
// needed to provide covariant conversions that the Java interfaces don't provide automatically.
|
// needed to provide covariant conversions that the Java interfaces don't provide automatically.
|
||||||
// The alternative would be having to cast around everywhere instead of doing it here in a central place.
|
// The alternative would be having to cast around everywhere instead of doing it here in a central place.
|
||||||
public static <U, T extends U> Option<U> convertOption(scala.Option<T> o) {
|
public static <U, T extends U> Optional<U> convertOption(scala.Option<T> o) {
|
||||||
return (Option<U>)(Object) akka.japi.Option.fromScalaOption(o);
|
return (Optional<U>)(Object) OptionConverters.toJava(o);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked") // no support for covariance of Publisher in Java
|
@SuppressWarnings("unchecked") // no support for covariance of Publisher in Java
|
||||||
// needed to provide covariant conversions that the Java interfaces don't provide automatically.
|
// needed to provide covariant conversions that the Java interfaces don't provide automatically.
|
||||||
|
|
@ -40,8 +41,8 @@ public abstract class Util {
|
||||||
return emptyMap.$plus$plus(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala());
|
return emptyMap.$plus$plus(scala.collection.JavaConverters.mapAsScalaMapConverter(map).asScala());
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked") // contains an upcast
|
@SuppressWarnings("unchecked") // contains an upcast
|
||||||
public static <T, U extends T> scala.Option<U> convertOptionToScala(Option<T> o) {
|
public static <T, U extends T> scala.Option<U> convertOptionalToScala(Optional<T> o) {
|
||||||
return ((Option<U>) o).asScala();
|
return OptionConverters.toScala((Optional<U>) o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final scala.collection.immutable.Map<String, String> emptyMap =
|
public static final scala.collection.immutable.Map<String, String> emptyMap =
|
||||||
|
|
@ -66,23 +67,14 @@ public abstract class Util {
|
||||||
return ((JavaUri) uri).uri();
|
return ((JavaUri) uri).uri();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <J, V extends J> akka.japi.Option<J> lookupInRegistry(ObjectRegistry<Object, V> registry, int key) {
|
public static <J, V extends J> Optional<J> lookupInRegistry(ObjectRegistry<Object, V> registry, int key) {
|
||||||
return Util.<J, V>convertOption(registry.getForKey(key));
|
return Util.<J, V>convertOption(registry.getForKey(key));
|
||||||
}
|
}
|
||||||
public static <J, V extends J> akka.japi.Option<J> lookupInRegistry(ObjectRegistry<String, V> registry, String key) {
|
public static <J, V extends J> Optional<J> lookupInRegistry(ObjectRegistry<String, V> registry, String key) {
|
||||||
return Util.<String, J, V>lookupInRegistry(registry, key);
|
return Util.<String, J, V>lookupInRegistry(registry, key);
|
||||||
}
|
}
|
||||||
public static <K, J, V extends J> akka.japi.Option<J> lookupInRegistry(ObjectRegistry<K, V> registry, K key) {
|
public static <K, J, V extends J> Optional<J> lookupInRegistry(ObjectRegistry<K, V> registry, K key) {
|
||||||
return Util.<J, V>convertOption(registry.getForKey(key));
|
return Util.<J, V>convertOption(registry.getForKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporary replacement for akka.japi.Option.getOrElse until it gets released there.
|
|
||||||
*
|
|
||||||
* FIXME: remove in favor of a proper japi.Option.getOrElse
|
|
||||||
*/
|
|
||||||
public static <B, A extends B> B getOrElse(Option<A> option, B defaultValue) {
|
|
||||||
if (option.isDefined()) return option.get();
|
|
||||||
else return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,42 +7,44 @@ package akka.http.javadsl;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLParameters;
|
import javax.net.ssl.SSLParameters;
|
||||||
|
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.japi.Util;
|
import akka.japi.Util;
|
||||||
import akka.stream.io.ClientAuth;
|
import akka.stream.io.ClientAuth;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters;
|
||||||
|
|
||||||
public abstract class HttpsContext {
|
public abstract class HttpsContext {
|
||||||
|
|
||||||
public abstract SSLContext getSslContext();
|
public abstract SSLContext getSslContext();
|
||||||
|
|
||||||
public abstract Option<Collection<String>> getEnabledCipherSuites();
|
public abstract Optional<Collection<String>> getEnabledCipherSuites();
|
||||||
|
|
||||||
public abstract Option<Collection<String>> getEnabledProtocols();
|
public abstract Optional<Collection<String>> getEnabledProtocols();
|
||||||
|
|
||||||
public abstract Option<ClientAuth> getClientAuth();
|
public abstract Optional<ClientAuth> getClientAuth();
|
||||||
|
|
||||||
public abstract Option<SSLParameters> getSslParameters();
|
public abstract Optional<SSLParameters> getSslParameters();
|
||||||
|
|
||||||
//#http-context-creation
|
//#http-context-creation
|
||||||
public static HttpsContext create(SSLContext sslContext,
|
public static HttpsContext create(SSLContext sslContext,
|
||||||
Option<Collection<String>> enabledCipherSuites,
|
Optional<Collection<String>> enabledCipherSuites,
|
||||||
Option<Collection<String>> enabledProtocols,
|
Optional<Collection<String>> enabledProtocols,
|
||||||
Option<ClientAuth> clientAuth,
|
Optional<ClientAuth> clientAuth,
|
||||||
Option<SSLParameters> sslParameters)
|
Optional<SSLParameters> sslParameters)
|
||||||
//#http-context-creation
|
//#http-context-creation
|
||||||
{
|
{
|
||||||
final scala.Option<scala.collection.immutable.Seq<String>> ecs;
|
final scala.Option<scala.collection.immutable.Seq<String>> ecs;
|
||||||
if (enabledCipherSuites.isDefined()) ecs = scala.Option.apply(Util.immutableSeq(enabledCipherSuites.get()));
|
if (enabledCipherSuites.isPresent()) ecs = scala.Option.apply(Util.immutableSeq(enabledCipherSuites.get()));
|
||||||
else ecs = scala.Option.empty();
|
else ecs = scala.Option.empty();
|
||||||
final scala.Option<scala.collection.immutable.Seq<String>> ep;
|
final scala.Option<scala.collection.immutable.Seq<String>> ep;
|
||||||
if(enabledProtocols.isDefined()) ep = scala.Option.apply(Util.immutableSeq(enabledProtocols.get()));
|
if(enabledProtocols.isPresent()) ep = scala.Option.apply(Util.immutableSeq(enabledProtocols.get()));
|
||||||
else ep = scala.Option.empty();
|
else ep = scala.Option.empty();
|
||||||
return new akka.http.scaladsl.HttpsContext(sslContext,
|
return new akka.http.scaladsl.HttpsContext(sslContext,
|
||||||
ecs,
|
ecs,
|
||||||
ep,
|
ep,
|
||||||
clientAuth.asScala(),
|
OptionConverters.toScala(clientAuth),
|
||||||
sslParameters.asScala());
|
OptionConverters.toScala(sslParameters));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,22 @@
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.scaladsl.model.ContentRange$;
|
import akka.http.scaladsl.model.ContentRange$;
|
||||||
import akka.japi.Option;
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
import scala.compat.java8.OptionConverters;
|
||||||
|
|
||||||
public abstract class ContentRange {
|
public abstract class ContentRange {
|
||||||
public abstract boolean isByteContentRange();
|
public abstract boolean isByteContentRange();
|
||||||
public abstract boolean isSatisfiable();
|
public abstract boolean isSatisfiable();
|
||||||
public abstract boolean isOther();
|
public abstract boolean isOther();
|
||||||
|
|
||||||
public abstract Option<Long> getSatisfiableFirst();
|
public abstract OptionalLong getSatisfiableFirst();
|
||||||
public abstract Option<Long> getSatisfiableLast();
|
public abstract OptionalLong getSatisfiableLast();
|
||||||
|
|
||||||
public abstract Option<String> getOtherValue();
|
public abstract Optional<String> getOtherValue();
|
||||||
|
|
||||||
public abstract Option<Long> getInstanceLength();
|
public abstract OptionalLong getInstanceLength();
|
||||||
|
|
||||||
public static ContentRange create(long first, long last) {
|
public static ContentRange create(long first, long last) {
|
||||||
return ContentRange$.MODULE$.apply(first, last);
|
return ContentRange$.MODULE$.apply(first, last);
|
||||||
|
|
@ -26,8 +29,8 @@ public abstract class ContentRange {
|
||||||
return ContentRange$.MODULE$.apply(first, last, instanceLength);
|
return ContentRange$.MODULE$.apply(first, last, instanceLength);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static ContentRange create(long first, long last, Option<Long> instanceLength) {
|
public static ContentRange create(long first, long last, OptionalLong instanceLength) {
|
||||||
return ContentRange$.MODULE$.apply(first, last, ((Option<Object>) (Object) instanceLength).asScala());
|
return ContentRange$.MODULE$.apply(first, last, OptionConverters.toScala(instanceLength));
|
||||||
}
|
}
|
||||||
public static ContentRange createUnsatisfiable(long length) {
|
public static ContentRange createUnsatisfiable(long length) {
|
||||||
return new akka.http.scaladsl.model.ContentRange.Unsatisfiable(length);
|
return new akka.http.scaladsl.model.ContentRange.Unsatisfiable(length);
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable, fast and efficient Date + Time implementation without any dependencies.
|
* Immutable, fast and efficient Date + Time implementation without any dependencies.
|
||||||
* Does not support TimeZones, all DateTime values are always GMT based.
|
* Does not support TimeZones, all DateTime values are always GMT based.
|
||||||
|
|
@ -101,7 +102,7 @@ public abstract class DateTime {
|
||||||
* Returns a new DateTime instance parsed from IsoDateTimeString as Some(dateTime). Returns None if
|
* Returns a new DateTime instance parsed from IsoDateTimeString as Some(dateTime). Returns None if
|
||||||
* parsing has failed.
|
* parsing has failed.
|
||||||
*/
|
*/
|
||||||
public static Option<DateTime> fromIsoDateTimeString(String isoDateTimeString) {
|
public static Optional<DateTime> fromIsoDateTimeString(String isoDateTimeString) {
|
||||||
return Util.<DateTime, akka.http.scaladsl.model.DateTime>convertOption(akka.http.scaladsl.model.DateTime.fromIsoDateTimeString(isoDateTimeString));
|
return Util.<DateTime, akka.http.scaladsl.model.DateTime>convertOption(akka.http.scaladsl.model.DateTime.fromIsoDateTimeString(isoDateTimeString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.http.scaladsl.model.HttpCharsets$;
|
import akka.http.scaladsl.model.HttpCharsets$;
|
||||||
import akka.japi.Option;
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains a set of predefined charsets.
|
* Contains a set of predefined charsets.
|
||||||
|
|
@ -31,7 +32,7 @@ public final class HttpCharsets {
|
||||||
/**
|
/**
|
||||||
* Returns Some(charset) if the charset with the given name was found and None otherwise.
|
* Returns Some(charset) if the charset with the given name was found and None otherwise.
|
||||||
*/
|
*/
|
||||||
public static Option<HttpCharset> lookup(String name) {
|
public static Optional<HttpCharset> lookup(String name) {
|
||||||
return Util.<HttpCharset, akka.http.scaladsl.model.HttpCharset>lookupInRegistry(HttpCharsets$.MODULE$, name);
|
return Util.<HttpCharset, akka.http.scaladsl.model.HttpCharset>lookupInRegistry(HttpCharsets$.MODULE$, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.http.scaladsl.model.HttpEntity$;
|
import akka.http.scaladsl.model.HttpEntity$;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.stream.Materializer;
|
import akka.stream.Materializer;
|
||||||
import akka.stream.javadsl.Source;
|
import akka.stream.javadsl.Source;
|
||||||
import akka.util.ByteString;
|
import akka.util.ByteString;
|
||||||
import scala.concurrent.Future;
|
import scala.concurrent.Future;
|
||||||
|
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the entity of an Http message. An entity consists of the content-type of the data
|
* Represents the entity of an Http message. An entity consists of the content-type of the data
|
||||||
* and the actual data itself. Some subtypes of HttpEntity also define the content-length of the
|
* and the actual data itself. Some subtypes of HttpEntity also define the content-length of the
|
||||||
|
|
@ -77,7 +78,7 @@ public interface HttpEntity {
|
||||||
/**
|
/**
|
||||||
* Returns Some(contentLength) if the length is defined and none otherwise.
|
* Returns Some(contentLength) if the length is defined and none otherwise.
|
||||||
*/
|
*/
|
||||||
Option<Long> getContentLengthOption();
|
OptionalLong getContentLengthOption();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a stream of data bytes this entity consists of.
|
* Returns a stream of data bytes this entity consists of.
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.util.ByteString;
|
import akka.util.ByteString;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base type for an Http message (request or response).
|
* The base type for an Http message (request or response).
|
||||||
|
|
@ -37,13 +37,13 @@ public interface HttpMessage {
|
||||||
* Try to find the first header with the given name (case-insensitive) and return
|
* Try to find the first header with the given name (case-insensitive) and return
|
||||||
* Some(header), otherwise this method returns None.
|
* Some(header), otherwise this method returns None.
|
||||||
*/
|
*/
|
||||||
Option<HttpHeader> getHeader(String headerName);
|
Optional<HttpHeader> getHeader(String headerName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to find the first header of the given class and return
|
* Try to find the first header of the given class and return
|
||||||
* Some(header), otherwise this method returns None.
|
* Some(header), otherwise this method returns None.
|
||||||
*/
|
*/
|
||||||
<T extends HttpHeader> Option<T> getHeader(Class<T> headerClass);
|
<T extends HttpHeader> Optional<T> getHeader(Class<T> headerClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entity of this message.
|
* The entity of this message.
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.http.scaladsl.model.HttpMethods$;
|
import akka.http.scaladsl.model.HttpMethods$;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains static constants for predefined method types.
|
* Contains static constants for predefined method types.
|
||||||
*/
|
*/
|
||||||
|
|
@ -34,7 +35,7 @@ public final class HttpMethods {
|
||||||
/**
|
/**
|
||||||
* Looks up a predefined HTTP method with the given name.
|
* Looks up a predefined HTTP method with the given name.
|
||||||
*/
|
*/
|
||||||
public static Option<HttpMethod> lookup(String name) {
|
public static Optional<HttpMethod> lookup(String name) {
|
||||||
return Util.<HttpMethod, akka.http.scaladsl.model.HttpMethod>lookupInRegistry(HttpMethods$.MODULE$, name);
|
return Util.<HttpMethod, akka.http.scaladsl.model.HttpMethod>lookupInRegistry(HttpMethods$.MODULE$, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.http.scaladsl.model.MediaTypes$;
|
import akka.http.scaladsl.model.MediaTypes$;
|
||||||
import akka.japi.Option;
|
|
||||||
import scala.collection.immutable.List;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the set of predefined media-types.
|
* Contains the set of predefined media-types.
|
||||||
|
|
@ -197,7 +197,7 @@ public abstract class MediaTypes {
|
||||||
/**
|
/**
|
||||||
* Looks up a media-type with the given main-type and sub-type.
|
* Looks up a media-type with the given main-type and sub-type.
|
||||||
*/
|
*/
|
||||||
public static Option<MediaType> lookup(String mainType, String subType) {
|
public static Optional<MediaType> lookup(String mainType, String subType) {
|
||||||
return Util.<scala.Tuple2<String, String>, MediaType, akka.http.scaladsl.model.MediaType>lookupInRegistry(MediaTypes$.MODULE$, new scala.Tuple2<String, String>(mainType, subType));
|
return Util.<scala.Tuple2<String, String>, MediaType, akka.http.scaladsl.model.MediaType>lookupInRegistry(MediaTypes$.MODULE$, new scala.Tuple2<String, String>(mainType, subType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import scala.concurrent.Future;
|
import scala.concurrent.Future;
|
||||||
import akka.http.javadsl.model.headers.ContentDisposition;
|
import akka.http.javadsl.model.headers.ContentDisposition;
|
||||||
import akka.http.javadsl.model.headers.ContentDispositionType;
|
import akka.http.javadsl.model.headers.ContentDispositionType;
|
||||||
import akka.http.javadsl.model.headers.RangeUnit;
|
import akka.http.javadsl.model.headers.RangeUnit;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.stream.Materializer;
|
import akka.stream.Materializer;
|
||||||
import akka.stream.javadsl.Source;
|
import akka.stream.javadsl.Source;
|
||||||
|
|
||||||
|
|
@ -52,11 +53,11 @@ public interface Multipart {
|
||||||
|
|
||||||
Iterable<HttpHeader> getHeaders();
|
Iterable<HttpHeader> getHeaders();
|
||||||
|
|
||||||
Option<ContentDisposition> getContentDispositionHeader();
|
Optional<ContentDisposition> getContentDispositionHeader();
|
||||||
|
|
||||||
Map<String, String> getDispositionParams();
|
Map<String, String> getDispositionParams();
|
||||||
|
|
||||||
Option<ContentDispositionType> getDispositionType();
|
Optional<ContentDispositionType> getDispositionType();
|
||||||
|
|
||||||
Future<? extends Multipart.BodyPart.Strict> toStrict(long timeoutMillis, Materializer materializer);
|
Future<? extends Multipart.BodyPart.Strict> toStrict(long timeoutMillis, Materializer materializer);
|
||||||
|
|
||||||
|
|
@ -106,7 +107,7 @@ public interface Multipart {
|
||||||
String getName();
|
String getName();
|
||||||
Map<String, String> getAdditionalDispositionParams();
|
Map<String, String> getAdditionalDispositionParams();
|
||||||
Iterable<HttpHeader> getAdditionalHeaders();
|
Iterable<HttpHeader> getAdditionalHeaders();
|
||||||
Option<String> getFilename();
|
Optional<String> getFilename();
|
||||||
|
|
||||||
Future<Multipart.FormData.BodyPart.Strict> toStrict(long timeoutMillis, Materializer materializer);
|
Future<Multipart.FormData.BodyPart.Strict> toStrict(long timeoutMillis, Materializer materializer);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.model.JavaQuery;
|
import akka.http.impl.model.JavaQuery;
|
||||||
import akka.http.scaladsl.model.*;
|
import akka.http.scaladsl.model.*;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.japi.Pair;
|
import akka.japi.Pair;
|
||||||
import akka.parboiled2.CharPredicate;
|
import akka.parboiled2.CharPredicate;
|
||||||
import akka.parboiled2.ParserInput$;
|
import akka.parboiled2.ParserInput$;
|
||||||
|
|
@ -14,12 +13,13 @@ import akka.parboiled2.ParserInput$;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class Query {
|
public abstract class Query {
|
||||||
/**
|
/**
|
||||||
* Returns the value of the first parameter with the given key if it exists.
|
* Returns the value of the first parameter with the given key if it exists.
|
||||||
*/
|
*/
|
||||||
public abstract Option<String> get(String key);
|
public abstract Optional<String> get(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the first parameter with the given key or the provided default value.
|
* Returns the value of the first parameter with the given key or the provided default value.
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model;
|
package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.japi.Option;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Optional;
|
||||||
|
import scala.compat.java8.OptionConverters;
|
||||||
|
|
||||||
public abstract class RemoteAddress {
|
public abstract class RemoteAddress {
|
||||||
public abstract boolean isUnknown();
|
public abstract boolean isUnknown();
|
||||||
|
|
||||||
public abstract Option<InetAddress> getAddress();
|
public abstract Optional<InetAddress> getAddress();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a port if defined or 0 otherwise.
|
* Returns a port if defined or 0 otherwise.
|
||||||
|
|
@ -21,7 +21,7 @@ public abstract class RemoteAddress {
|
||||||
|
|
||||||
public static final RemoteAddress UNKNOWN = akka.http.scaladsl.model.RemoteAddress.Unknown$.MODULE$;
|
public static final RemoteAddress UNKNOWN = akka.http.scaladsl.model.RemoteAddress.Unknown$.MODULE$;
|
||||||
public static RemoteAddress create(InetAddress address) {
|
public static RemoteAddress create(InetAddress address) {
|
||||||
return akka.http.scaladsl.model.RemoteAddress.apply(address, Option.none().asScala());
|
return akka.http.scaladsl.model.RemoteAddress.apply(address, OptionConverters.toScala(Optional.empty()));
|
||||||
}
|
}
|
||||||
public static RemoteAddress create(InetSocketAddress address) {
|
public static RemoteAddress create(InetSocketAddress address) {
|
||||||
return akka.http.scaladsl.model.RemoteAddress.apply(address);
|
return akka.http.scaladsl.model.RemoteAddress.apply(address);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.http.scaladsl.model.StatusCodes$;
|
import akka.http.scaladsl.model.StatusCodes$;
|
||||||
import akka.japi.Option;
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the set of predefined status-codes along with static methods to access and create custom
|
* Contains the set of predefined status-codes along with static methods to access and create custom
|
||||||
|
|
@ -109,7 +110,7 @@ public final class StatusCodes {
|
||||||
/**
|
/**
|
||||||
* Looks up a status-code by numeric code and returns Some(code). Returns None otherwise.
|
* Looks up a status-code by numeric code and returns Some(code). Returns None otherwise.
|
||||||
*/
|
*/
|
||||||
public static Option<StatusCode> lookup(int intValue) {
|
public static Optional<StatusCode> lookup(int intValue) {
|
||||||
return Util.<StatusCode, akka.http.scaladsl.model.StatusCode>lookupInRegistry(StatusCodes$.MODULE$, intValue);
|
return Util.<StatusCode, akka.http.scaladsl.model.StatusCode>lookupInRegistry(StatusCodes$.MODULE$, intValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@ package akka.http.javadsl.model;
|
||||||
|
|
||||||
import akka.http.impl.model.JavaUri;
|
import akka.http.impl.model.JavaUri;
|
||||||
import akka.http.scaladsl.model.UriJavaAccessor;
|
import akka.http.scaladsl.model.UriJavaAccessor;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.japi.Pair;
|
import akka.japi.Pair;
|
||||||
import akka.parboiled2.ParserInput$;
|
import akka.parboiled2.ParserInput$;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Uri. Use the `withX` methods to create modified copies of a given instance.
|
* Represents an Uri. Use the `withX` methods to create modified copies of a given instance.
|
||||||
|
|
@ -66,12 +66,12 @@ public abstract class Uri {
|
||||||
/**
|
/**
|
||||||
* Returns a decoded String representation of the query of this Uri.
|
* Returns a decoded String representation of the query of this Uri.
|
||||||
*/
|
*/
|
||||||
public abstract Option<String> queryString(Charset charset);
|
public abstract Optional<String> queryString(Charset charset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an undecoded String representation of the query of this Uri.
|
* Returns an undecoded String representation of the query of this Uri.
|
||||||
*/
|
*/
|
||||||
public abstract Option<String> rawQueryString();
|
public abstract Optional<String> rawQueryString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parsed Query instance of this Uri.
|
* Returns the parsed Query instance of this Uri.
|
||||||
|
|
@ -86,7 +86,7 @@ public abstract class Uri {
|
||||||
/**
|
/**
|
||||||
* Returns the fragment part of this Uri.
|
* Returns the fragment part of this Uri.
|
||||||
*/
|
*/
|
||||||
public abstract Option<String> fragment();
|
public abstract Optional<String> fragment();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of this instance with a new scheme.
|
* Returns a copy of this instance with a new scheme.
|
||||||
|
|
@ -146,7 +146,7 @@ public abstract class Uri {
|
||||||
/**
|
/**
|
||||||
* Returns a copy of this instance with a new optional fragment.
|
* Returns a copy of this instance with a new optional fragment.
|
||||||
*/
|
*/
|
||||||
public abstract Uri fragment(Option<String> fragment);
|
public abstract Uri fragment(Optional<String> fragment);
|
||||||
|
|
||||||
public static final akka.http.scaladsl.model.Uri.ParsingMode STRICT = UriJavaAccessor.pmStrict();
|
public static final akka.http.scaladsl.model.Uri.ParsingMode STRICT = UriJavaAccessor.pmStrict();
|
||||||
public static final akka.http.scaladsl.model.Uri.ParsingMode RELAXED = UriJavaAccessor.pmRelaxed();
|
public static final akka.http.scaladsl.model.Uri.ParsingMode RELAXED = UriJavaAccessor.pmRelaxed();
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,18 @@
|
||||||
package akka.http.javadsl.model.headers;
|
package akka.http.javadsl.model.headers;
|
||||||
|
|
||||||
import akka.http.scaladsl.model.headers.ByteRange$;
|
import akka.http.scaladsl.model.headers.ByteRange$;
|
||||||
import akka.japi.Option;
|
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
public abstract class ByteRange {
|
public abstract class ByteRange {
|
||||||
public abstract boolean isSlice();
|
public abstract boolean isSlice();
|
||||||
public abstract boolean isFromOffset();
|
public abstract boolean isFromOffset();
|
||||||
public abstract boolean isSuffix();
|
public abstract boolean isSuffix();
|
||||||
|
|
||||||
public abstract Option<Long> getSliceFirst();
|
public abstract OptionalLong getSliceFirst();
|
||||||
public abstract Option<Long> getSliceLast();
|
public abstract OptionalLong getSliceLast();
|
||||||
public abstract Option<Long> getOffset();
|
public abstract OptionalLong getOffset();
|
||||||
public abstract Option<Long> getSuffixLength();
|
public abstract OptionalLong getSuffixLength();
|
||||||
|
|
||||||
public static ByteRange createSlice(long first, long last) {
|
public static ByteRange createSlice(long first, long last) {
|
||||||
return ByteRange$.MODULE$.apply(first, last);
|
return ByteRange$.MODULE$.apply(first, last);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model.headers;
|
package akka.http.javadsl.model.headers;
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
public final class CacheDirectives {
|
public final class CacheDirectives {
|
||||||
private CacheDirectives() {}
|
private CacheDirectives() {}
|
||||||
|
|
||||||
|
|
@ -11,10 +16,10 @@ public final class CacheDirectives {
|
||||||
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusage(deltaSeconds);
|
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusage(deltaSeconds);
|
||||||
}
|
}
|
||||||
public static CacheDirective MAX_STALE() {
|
public static CacheDirective MAX_STALE() {
|
||||||
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusstale(akka.japi.Option.none().asScala());
|
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusstale(OptionConverters.toScala(Optional.empty()));
|
||||||
}
|
}
|
||||||
public static CacheDirective MAX_STALE(long deltaSeconds) {
|
public static CacheDirective MAX_STALE(long deltaSeconds) {
|
||||||
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusstale(akka.japi.Option.some((Object) deltaSeconds).asScala());
|
return new akka.http.scaladsl.model.headers.CacheDirectives.max$minusstale(OptionConverters.toScala(OptionalLong.of(deltaSeconds)));
|
||||||
}
|
}
|
||||||
public static CacheDirective MIN_FRESH(long deltaSeconds) {
|
public static CacheDirective MIN_FRESH(long deltaSeconds) {
|
||||||
return new akka.http.scaladsl.model.headers.CacheDirectives.min$minusfresh(deltaSeconds);
|
return new akka.http.scaladsl.model.headers.CacheDirectives.min$minusfresh(deltaSeconds);
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,23 @@ package akka.http.javadsl.model.headers;
|
||||||
|
|
||||||
import akka.http.javadsl.model.DateTime;
|
import akka.http.javadsl.model.DateTime;
|
||||||
import akka.http.impl.util.Util;
|
import akka.http.impl.util.Util;
|
||||||
import akka.japi.Option;
|
import scala.compat.java8.OptionConverters;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
public abstract class HttpCookie {
|
public abstract class HttpCookie {
|
||||||
public abstract String name();
|
public abstract String name();
|
||||||
public abstract String value();
|
public abstract String value();
|
||||||
public abstract HttpCookiePair pair();
|
public abstract HttpCookiePair pair();
|
||||||
|
|
||||||
public abstract Option<DateTime> getExpires();
|
public abstract Optional<DateTime> getExpires();
|
||||||
public abstract Option<Long> getMaxAge();
|
public abstract OptionalLong getMaxAge();
|
||||||
public abstract Option<String> getDomain();
|
public abstract Optional<String> getDomain();
|
||||||
public abstract Option<String> getPath();
|
public abstract Optional<String> getPath();
|
||||||
public abstract boolean secure();
|
public abstract boolean secure();
|
||||||
public abstract boolean httpOnly();
|
public abstract boolean httpOnly();
|
||||||
public abstract Option<String> getExtension();
|
public abstract Optional<String> getExtension();
|
||||||
|
|
||||||
public static HttpCookie create(String name, String value) {
|
public static HttpCookie create(String name, String value) {
|
||||||
return new akka.http.scaladsl.model.headers.HttpCookie(
|
return new akka.http.scaladsl.model.headers.HttpCookie(
|
||||||
|
|
@ -28,11 +31,11 @@ public abstract class HttpCookie {
|
||||||
false, false,
|
false, false,
|
||||||
Util.<String>scalaNone());
|
Util.<String>scalaNone());
|
||||||
}
|
}
|
||||||
public static HttpCookie create(String name, String value, Option<String> domain, Option<String> path) {
|
public static HttpCookie create(String name, String value, Optional<String> domain, Optional<String> path) {
|
||||||
return new akka.http.scaladsl.model.headers.HttpCookie(
|
return new akka.http.scaladsl.model.headers.HttpCookie(
|
||||||
name, value,
|
name, value,
|
||||||
Util.<akka.http.scaladsl.model.DateTime>scalaNone(), Util.scalaNone(),
|
Util.<akka.http.scaladsl.model.DateTime>scalaNone(), Util.scalaNone(),
|
||||||
domain.asScala(), path.asScala(),
|
OptionConverters.toScala(domain), OptionConverters.toScala(path),
|
||||||
false, false,
|
false, false,
|
||||||
Util.<String>scalaNone());
|
Util.<String>scalaNone());
|
||||||
}
|
}
|
||||||
|
|
@ -40,22 +43,22 @@ public abstract class HttpCookie {
|
||||||
public static HttpCookie create(
|
public static HttpCookie create(
|
||||||
String name,
|
String name,
|
||||||
String value,
|
String value,
|
||||||
Option<DateTime> expires,
|
Optional<DateTime> expires,
|
||||||
Option<Long> maxAge,
|
OptionalLong maxAge,
|
||||||
Option<String> domain,
|
Optional<String> domain,
|
||||||
Option<String> path,
|
Optional<String> path,
|
||||||
boolean secure,
|
boolean secure,
|
||||||
boolean httpOnly,
|
boolean httpOnly,
|
||||||
Option<String> extension) {
|
Optional<String> extension) {
|
||||||
return new akka.http.scaladsl.model.headers.HttpCookie(
|
return new akka.http.scaladsl.model.headers.HttpCookie(
|
||||||
name, value,
|
name, value,
|
||||||
Util.<DateTime, akka.http.scaladsl.model.DateTime>convertOptionToScala(expires),
|
Util.<DateTime, akka.http.scaladsl.model.DateTime>convertOptionalToScala(expires),
|
||||||
((Option<Object>) (Object) maxAge).asScala(),
|
OptionConverters.toScala(maxAge),
|
||||||
domain.asScala(),
|
OptionConverters.toScala(domain),
|
||||||
path.asScala(),
|
OptionConverters.toScala(path),
|
||||||
secure,
|
secure,
|
||||||
httpOnly,
|
httpOnly,
|
||||||
extension.asScala());
|
OptionConverters.toScala(extension));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package akka.http
|
package akka.http
|
||||||
|
|
||||||
import java.lang.{ Iterable ⇒ JIterable }
|
import java.lang.{ Iterable ⇒ JIterable }
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import akka.event.LoggingAdapter
|
import akka.event.LoggingAdapter
|
||||||
|
|
@ -13,6 +14,7 @@ import akka.http.scaladsl.HttpsContext
|
||||||
import com.typesafe.config.Config
|
import com.typesafe.config.Config
|
||||||
|
|
||||||
import scala.concurrent.duration.Duration
|
import scala.concurrent.duration.Duration
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
final case class HostConnectionPoolSetup(host: String, port: Int, setup: ConnectionPoolSetup)
|
final case class HostConnectionPoolSetup(host: String, port: Int, setup: ConnectionPoolSetup)
|
||||||
|
|
||||||
|
|
@ -24,9 +26,9 @@ final case class ConnectionPoolSetup(
|
||||||
object ConnectionPoolSetup {
|
object ConnectionPoolSetup {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def create(settings: ConnectionPoolSettings,
|
def create(settings: ConnectionPoolSettings,
|
||||||
httpsContext: akka.japi.Option[akka.http.javadsl.HttpsContext],
|
httpsContext: Optional[akka.http.javadsl.HttpsContext],
|
||||||
log: LoggingAdapter): ConnectionPoolSetup =
|
log: LoggingAdapter): ConnectionPoolSetup =
|
||||||
ConnectionPoolSetup(settings, httpsContext.map(_.asInstanceOf[HttpsContext]), log)
|
ConnectionPoolSetup(settings, httpsContext.asScala.map(_.asInstanceOf[HttpsContext]), log)
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class ConnectionPoolSettings(
|
final case class ConnectionPoolSettings(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package akka.http.impl.model
|
package akka.http.impl.model
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
import java.{ util ⇒ ju }
|
import java.{ util ⇒ ju }
|
||||||
import akka.http.impl.model.parser.CharacterClasses
|
import akka.http.impl.model.parser.CharacterClasses
|
||||||
import akka.http.impl.util.StringRendering
|
import akka.http.impl.util.StringRendering
|
||||||
|
|
@ -11,15 +12,16 @@ import akka.http.javadsl.model.HttpCharset
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.scaladsl.model.UriRendering
|
import akka.http.scaladsl.model.UriRendering
|
||||||
import akka.http.scaladsl.{ model ⇒ sm }
|
import akka.http.scaladsl.{ model ⇒ sm }
|
||||||
import akka.japi.{ Pair, Option }
|
import akka.japi.Pair
|
||||||
import akka.parboiled2.CharPredicate
|
import akka.parboiled2.CharPredicate
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/** INTERNAL API */
|
/** INTERNAL API */
|
||||||
case class JavaQuery(query: sm.Uri.Query) extends jm.Query {
|
case class JavaQuery(query: sm.Uri.Query) extends jm.Query {
|
||||||
override def get(key: String): Option[String] = query.get(key)
|
override def get(key: String): Optional[String] = query.get(key).asJava
|
||||||
override def toMap: ju.Map[String, String] = query.toMap.asJava
|
override def toMap: ju.Map[String, String] = query.toMap.asJava
|
||||||
override def toList: ju.List[Pair[String, String]] = query.map(_.asJava).asJava
|
override def toList: ju.List[Pair[String, String]] = query.map(_.asJava).asJava
|
||||||
override def getOrElse(key: String, _default: String): String = query.getOrElse(key, _default)
|
override def getOrElse(key: String, _default: String): String = query.getOrElse(key, _default)
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,13 @@
|
||||||
package akka.http.impl.model
|
package akka.http.impl.model
|
||||||
|
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
|
import java.util.Optional
|
||||||
import java.{ lang ⇒ jl }
|
import java.{ lang ⇒ jl }
|
||||||
import akka.http.scaladsl.model.Uri.ParsingMode
|
import akka.http.scaladsl.model.Uri.ParsingMode
|
||||||
import akka.japi.Option
|
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.scaladsl.{ model ⇒ sm }
|
import akka.http.scaladsl.{ model ⇒ sm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/** INTERNAL API */
|
/** INTERNAL API */
|
||||||
case class JavaUri(uri: sm.Uri) extends jm.Uri {
|
case class JavaUri(uri: sm.Uri) extends jm.Uri {
|
||||||
|
|
@ -36,12 +37,12 @@ case class JavaUri(uri: sm.Uri) extends jm.Uri {
|
||||||
gatherSegments(uri.path).asJava
|
gatherSegments(uri.path).asJava
|
||||||
}
|
}
|
||||||
|
|
||||||
def rawQueryString: Option[String] = uri.rawQueryString
|
def rawQueryString: Optional[String] = uri.rawQueryString.asJava
|
||||||
def queryString(charset: Charset): Option[String] = uri.queryString(charset)
|
def queryString(charset: Charset): Optional[String] = uri.queryString(charset).asJava
|
||||||
def query: jm.Query = uri.query().asJava
|
def query: jm.Query = uri.query().asJava
|
||||||
def query(charset: Charset, mode: ParsingMode): jm.Query = uri.query(charset, mode).asJava
|
def query(charset: Charset, mode: ParsingMode): jm.Query = uri.query(charset, mode).asJava
|
||||||
|
|
||||||
def fragment: Option[String] = uri.fragment
|
def fragment: Optional[String] = uri.fragment.asJava
|
||||||
|
|
||||||
// Modification methods
|
// Modification methods
|
||||||
|
|
||||||
|
|
@ -69,7 +70,7 @@ case class JavaUri(uri: sm.Uri) extends jm.Uri {
|
||||||
u.withPath(newPath)
|
u.withPath(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
def fragment(fragment: Option[String]): jm.Uri = t(_.copy(fragment = fragment))
|
def fragment(fragment: Optional[String]): jm.Uri = t(_.copy(fragment = fragment.asScala))
|
||||||
def fragment(fragment: String): jm.Uri = t(_.withFragment(fragment))
|
def fragment(fragment: String): jm.Uri = t(_.withFragment(fragment))
|
||||||
|
|
||||||
override def toString: String = uri.toString
|
override def toString: String = uri.toString
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package akka.http.impl.util
|
package akka.http.impl.util
|
||||||
|
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.Optional
|
||||||
import java.{ util ⇒ ju, lang ⇒ jl }
|
import java.{ util ⇒ ju, lang ⇒ jl }
|
||||||
import akka.japi.Pair
|
import akka.japi.Pair
|
||||||
import akka.stream.javadsl
|
import akka.stream.javadsl
|
||||||
|
|
@ -17,6 +18,8 @@ import akka.http.impl.model.{ JavaQuery, JavaUri }
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.scaladsl.{ model ⇒ sm }
|
import akka.http.scaladsl.{ model ⇒ sm }
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
|
|
||||||
/** INTERNAL API */
|
/** INTERNAL API */
|
||||||
|
|
@ -101,10 +104,10 @@ private[http] object JavaMapping {
|
||||||
def toScala(javaObject: ju.Map[K, V]): immutable.Map[K, V] = javaObject.asScala.toMap
|
def toScala(javaObject: ju.Map[K, V]): immutable.Map[K, V] = javaObject.asScala.toMap
|
||||||
def toJava(scalaObject: immutable.Map[K, V]): ju.Map[K, V] = scalaObject.asJava
|
def toJava(scalaObject: immutable.Map[K, V]): ju.Map[K, V] = scalaObject.asJava
|
||||||
}
|
}
|
||||||
implicit def option[_J, _S](implicit mapping: JavaMapping[_J, _S]): JavaMapping[akka.japi.Option[_J], Option[_S]] =
|
implicit def option[_J, _S](implicit mapping: JavaMapping[_J, _S]): JavaMapping[Optional[_J], Option[_S]] =
|
||||||
new JavaMapping[akka.japi.Option[_J], Option[_S]] {
|
new JavaMapping[Optional[_J], Option[_S]] {
|
||||||
def toScala(javaObject: japi.Option[_J]): Option[_S] = javaObject.asScala.map(mapping.toScala)
|
def toScala(javaObject: Optional[_J]): Option[_S] = javaObject.asScala.map(mapping.toScala)
|
||||||
def toJava(scalaObject: Option[_S]): japi.Option[_J] = japi.Option.fromScalaOption(scalaObject.map(mapping.toJava))
|
def toJava(scalaObject: Option[_S]): Optional[_J] = scalaObject.map(mapping.toJava).asJava
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit def flowMapping[JIn, SIn, JOut, SOut, M](implicit inMapping: JavaMapping[JIn, SIn], outMapping: JavaMapping[JOut, SOut]): JavaMapping[javadsl.Flow[JIn, JOut, M], scaladsl.Flow[SIn, SOut, M]] =
|
implicit def flowMapping[JIn, SIn, JOut, SOut, M](implicit inMapping: JavaMapping[JIn, SIn], outMapping: JavaMapping[JOut, SOut]): JavaMapping[javadsl.Flow[JIn, JOut, M], scaladsl.Flow[SIn, SOut, M]] =
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package akka.http.javadsl
|
package akka.http.javadsl
|
||||||
|
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
|
import java.util.Optional
|
||||||
import akka.http.impl.util.JavaMapping
|
import akka.http.impl.util.JavaMapping
|
||||||
import akka.http.javadsl.model.ws._
|
import akka.http.javadsl.model.ws._
|
||||||
import akka.stream
|
import akka.stream
|
||||||
|
|
@ -14,7 +15,7 @@ import scala.language.implicitConversions
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
import akka.stream.scaladsl.Keep
|
import akka.stream.scaladsl.Keep
|
||||||
import akka.japi.{ Pair, Option, Function }
|
import akka.japi.{ Pair, Function }
|
||||||
import akka.actor.{ ExtendedActorSystem, ActorSystem, ExtensionIdProvider, ExtensionId }
|
import akka.actor.{ ExtendedActorSystem, ActorSystem, ExtensionIdProvider, ExtensionId }
|
||||||
import akka.event.LoggingAdapter
|
import akka.event.LoggingAdapter
|
||||||
import akka.stream.Materializer
|
import akka.stream.Materializer
|
||||||
|
|
@ -25,6 +26,8 @@ import akka.http.scaladsl.{ model ⇒ sm }
|
||||||
import akka.http.javadsl.model._
|
import akka.http.javadsl.model._
|
||||||
import akka.http._
|
import akka.http._
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
object Http extends ExtensionId[Http] with ExtensionIdProvider {
|
object Http extends ExtensionId[Http] with ExtensionIdProvider {
|
||||||
override def get(system: ActorSystem): Http = super.get(system)
|
override def get(system: ActorSystem): Http = super.get(system)
|
||||||
def lookup() = Http
|
def lookup() = Http
|
||||||
|
|
@ -36,8 +39,8 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
|
|
||||||
private lazy val delegate = akka.http.scaladsl.Http(system)
|
private lazy val delegate = akka.http.scaladsl.Http(system)
|
||||||
|
|
||||||
private implicit def convertHttpsContext(hctx: Option[HttpsContext]) =
|
private implicit def convertHttpsContext(hctx: Optional[HttpsContext]): Option[akka.http.scaladsl.HttpsContext] =
|
||||||
hctx.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext])
|
hctx.asScala.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server layer stage using the configured default [[ServerSettings]]. The returned [[BidiFlow]] isn't
|
* Constructs a server layer stage using the configured default [[ServerSettings]]. The returned [[BidiFlow]] isn't
|
||||||
|
|
@ -60,7 +63,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* this layer produces if the `akka.http.server.remote-address-header` configuration option is enabled.
|
* this layer produces if the `akka.http.server.remote-address-header` configuration option is enabled.
|
||||||
*/
|
*/
|
||||||
def serverLayer(settings: ServerSettings,
|
def serverLayer(settings: ServerSettings,
|
||||||
remoteAddress: Option[InetSocketAddress],
|
remoteAddress: Optional[InetSocketAddress],
|
||||||
materializer: Materializer): BidiFlow[HttpResponse, SslTlsOutbound, SslTlsInbound, HttpRequest, Unit] =
|
materializer: Materializer): BidiFlow[HttpResponse, SslTlsOutbound, SslTlsInbound, HttpRequest, Unit] =
|
||||||
adaptServerLayer(delegate.serverLayer(settings, remoteAddress.asScala)(materializer))
|
adaptServerLayer(delegate.serverLayer(settings, remoteAddress.asScala)(materializer))
|
||||||
|
|
||||||
|
|
@ -70,7 +73,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* this layer produces if the `akka.http.server.remote-address-header` configuration option is enabled.
|
* this layer produces if the `akka.http.server.remote-address-header` configuration option is enabled.
|
||||||
*/
|
*/
|
||||||
def serverLayer(settings: ServerSettings,
|
def serverLayer(settings: ServerSettings,
|
||||||
remoteAddress: Option[InetSocketAddress],
|
remoteAddress: Optional[InetSocketAddress],
|
||||||
log: LoggingAdapter,
|
log: LoggingAdapter,
|
||||||
materializer: Materializer): BidiFlow[HttpResponse, SslTlsOutbound, SslTlsInbound, HttpRequest, Unit] =
|
materializer: Materializer): BidiFlow[HttpResponse, SslTlsOutbound, SslTlsInbound, HttpRequest, Unit] =
|
||||||
adaptServerLayer(delegate.serverLayer(settings, remoteAddress.asScala, log)(materializer))
|
adaptServerLayer(delegate.serverLayer(settings, remoteAddress.asScala, log)(materializer))
|
||||||
|
|
@ -102,7 +105,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def bind(interface: String, port: Int,
|
def bind(interface: String, port: Int,
|
||||||
settings: ServerSettings,
|
settings: ServerSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter,
|
log: LoggingAdapter,
|
||||||
materializer: Materializer): Source[IncomingConnection, Future[ServerBinding]] =
|
materializer: Materializer): Source[IncomingConnection, Future[ServerBinding]] =
|
||||||
new Source(delegate.bind(interface, port, settings, httpsContext, log)(materializer)
|
new Source(delegate.bind(interface, port, settings, httpsContext, log)(materializer)
|
||||||
|
|
@ -133,7 +136,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
def bindAndHandle(handler: Flow[HttpRequest, HttpResponse, _],
|
def bindAndHandle(handler: Flow[HttpRequest, HttpResponse, _],
|
||||||
interface: String, port: Int,
|
interface: String, port: Int,
|
||||||
settings: ServerSettings,
|
settings: ServerSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter,
|
log: LoggingAdapter,
|
||||||
materializer: Materializer): Future[ServerBinding] =
|
materializer: Materializer): Future[ServerBinding] =
|
||||||
delegate.bindAndHandle(handler.asInstanceOf[Flow[sm.HttpRequest, sm.HttpResponse, _]].asScala,
|
delegate.bindAndHandle(handler.asInstanceOf[Flow[sm.HttpRequest, sm.HttpResponse, _]].asScala,
|
||||||
|
|
@ -163,7 +166,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
def bindAndHandleSync(handler: Function[HttpRequest, HttpResponse],
|
def bindAndHandleSync(handler: Function[HttpRequest, HttpResponse],
|
||||||
interface: String, port: Int,
|
interface: String, port: Int,
|
||||||
settings: ServerSettings,
|
settings: ServerSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter,
|
log: LoggingAdapter,
|
||||||
materializer: Materializer): Future[ServerBinding] =
|
materializer: Materializer): Future[ServerBinding] =
|
||||||
delegate.bindAndHandleSync(handler.apply(_).asScala,
|
delegate.bindAndHandleSync(handler.apply(_).asScala,
|
||||||
|
|
@ -192,7 +195,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def bindAndHandleAsync(handler: Function[HttpRequest, Future[HttpResponse]],
|
def bindAndHandleAsync(handler: Function[HttpRequest, Future[HttpResponse]],
|
||||||
interface: String, port: Int,
|
interface: String, port: Int,
|
||||||
settings: ServerSettings, httpsContext: Option[HttpsContext],
|
settings: ServerSettings, httpsContext: Optional[HttpsContext],
|
||||||
parallelism: Int, log: LoggingAdapter,
|
parallelism: Int, log: LoggingAdapter,
|
||||||
materializer: Materializer): Future[ServerBinding] =
|
materializer: Materializer): Future[ServerBinding] =
|
||||||
delegate.bindAndHandleAsync(handler.apply(_).asInstanceOf[Future[sm.HttpResponse]],
|
delegate.bindAndHandleAsync(handler.apply(_).asInstanceOf[Future[sm.HttpResponse]],
|
||||||
|
|
@ -259,7 +262,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* Every materialization of the produced flow will attempt to establish a new outgoing connection.
|
* Every materialization of the produced flow will attempt to establish a new outgoing connection.
|
||||||
*/
|
*/
|
||||||
def outgoingConnection(host: String, port: Int,
|
def outgoingConnection(host: String, port: Int,
|
||||||
localAddress: Option[InetSocketAddress],
|
localAddress: Optional[InetSocketAddress],
|
||||||
settings: ClientConnectionSettings,
|
settings: ClientConnectionSettings,
|
||||||
log: LoggingAdapter): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] =
|
log: LoggingAdapter): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] =
|
||||||
Flow.fromGraph {
|
Flow.fromGraph {
|
||||||
|
|
@ -275,14 +278,14 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* for encryption on the connection.
|
* for encryption on the connection.
|
||||||
*/
|
*/
|
||||||
def outgoingConnectionTls(host: String, port: Int,
|
def outgoingConnectionTls(host: String, port: Int,
|
||||||
localAddress: Option[InetSocketAddress],
|
localAddress: Optional[InetSocketAddress],
|
||||||
settings: ClientConnectionSettings,
|
settings: ClientConnectionSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] =
|
log: LoggingAdapter): Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] =
|
||||||
Flow.fromGraph {
|
Flow.fromGraph {
|
||||||
akka.stream.scaladsl.Flow[HttpRequest].map(_.asScala)
|
akka.stream.scaladsl.Flow[HttpRequest].map(_.asScala)
|
||||||
.viaMat(delegate.outgoingConnectionTls(host, port, localAddress.asScala, settings,
|
.viaMat(delegate.outgoingConnectionTls(host, port, localAddress.asScala, settings,
|
||||||
httpsContext.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log))(Keep.right)
|
httpsContext.asScala.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log))(Keep.right)
|
||||||
.mapMaterializedValue(_.map(new OutgoingConnection(_))(ec))
|
.mapMaterializedValue(_.map(new OutgoingConnection(_))(ec))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,10 +339,10 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def newHostConnectionPoolTls[T](host: String, port: Int,
|
def newHostConnectionPoolTls[T](host: String, port: Int,
|
||||||
settings: ConnectionPoolSettings,
|
settings: ConnectionPoolSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], HostConnectionPool] =
|
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], HostConnectionPool] =
|
||||||
adaptTupleFlow(delegate.newHostConnectionPoolTls[T](host, port, settings,
|
adaptTupleFlow(delegate.newHostConnectionPoolTls[T](host, port, settings,
|
||||||
httpsContext.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log)(materializer))
|
httpsContext.asScala.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log)(materializer))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a new connection pool to the given host and configuration and returns a [[Flow]] which dispatches
|
* Starts a new connection pool to the given host and configuration and returns a [[Flow]] which dispatches
|
||||||
|
|
@ -414,10 +417,10 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def cachedHostConnectionPoolTls[T](host: String, port: Int,
|
def cachedHostConnectionPoolTls[T](host: String, port: Int,
|
||||||
settings: ConnectionPoolSettings,
|
settings: ConnectionPoolSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], HostConnectionPool] =
|
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], HostConnectionPool] =
|
||||||
adaptTupleFlow(delegate.cachedHostConnectionPoolTls[T](host, port, settings,
|
adaptTupleFlow(delegate.cachedHostConnectionPoolTls[T](host, port, settings,
|
||||||
httpsContext.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log)(materializer))
|
httpsContext.asScala.map(_.asInstanceOf[akka.http.scaladsl.HttpsContext]), log)(materializer))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a [[Flow]] which dispatches incoming HTTP requests to the per-ActorSystem pool of outgoing
|
* Returns a [[Flow]] which dispatches incoming HTTP requests to the per-ActorSystem pool of outgoing
|
||||||
|
|
@ -470,7 +473,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* object of type `T` from the application which is emitted together with the corresponding response.
|
* object of type `T` from the application which is emitted together with the corresponding response.
|
||||||
*/
|
*/
|
||||||
def superPool[T](settings: ConnectionPoolSettings,
|
def superPool[T](settings: ConnectionPoolSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], Unit] =
|
log: LoggingAdapter, materializer: Materializer): Flow[Pair[HttpRequest, T], Pair[Try[HttpResponse], T], Unit] =
|
||||||
adaptTupleFlow(delegate.superPool[T](settings, httpsContext, log)(materializer))
|
adaptTupleFlow(delegate.superPool[T](settings, httpsContext, log)(materializer))
|
||||||
|
|
||||||
|
|
@ -496,7 +499,7 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def singleRequest(request: HttpRequest,
|
def singleRequest(request: HttpRequest,
|
||||||
settings: ConnectionPoolSettings,
|
settings: ConnectionPoolSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter, materializer: Materializer): Future[HttpResponse] =
|
log: LoggingAdapter, materializer: Materializer): Future[HttpResponse] =
|
||||||
delegate.singleRequest(request.asScala, settings, httpsContext, log)(materializer)
|
delegate.singleRequest(request.asScala, settings, httpsContext, log)(materializer)
|
||||||
|
|
||||||
|
|
@ -545,12 +548,12 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
* The layer is not reusable and must only be materialized once.
|
* The layer is not reusable and must only be materialized once.
|
||||||
*/
|
*/
|
||||||
def websocketClientFlow(request: WebsocketRequest,
|
def websocketClientFlow(request: WebsocketRequest,
|
||||||
localAddress: Option[InetSocketAddress],
|
localAddress: Optional[InetSocketAddress],
|
||||||
settings: ClientConnectionSettings,
|
settings: ClientConnectionSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter): Flow[Message, Message, Future[WebsocketUpgradeResponse]] =
|
log: LoggingAdapter): Flow[Message, Message, Future[WebsocketUpgradeResponse]] =
|
||||||
adaptWsFlow {
|
adaptWsFlow {
|
||||||
delegate.websocketClientFlow(request.asScala, localAddress, settings, httpsContext, log)
|
delegate.websocketClientFlow(request.asScala, localAddress.asScala, settings, httpsContext, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -572,16 +575,16 @@ class Http(system: ExtendedActorSystem) extends akka.actor.Extension {
|
||||||
*/
|
*/
|
||||||
def singleWebsocketRequest[T](request: WebsocketRequest,
|
def singleWebsocketRequest[T](request: WebsocketRequest,
|
||||||
clientFlow: Flow[Message, Message, T],
|
clientFlow: Flow[Message, Message, T],
|
||||||
localAddress: Option[InetSocketAddress],
|
localAddress: Optional[InetSocketAddress],
|
||||||
settings: ClientConnectionSettings,
|
settings: ClientConnectionSettings,
|
||||||
httpsContext: Option[HttpsContext],
|
httpsContext: Optional[HttpsContext],
|
||||||
log: LoggingAdapter,
|
log: LoggingAdapter,
|
||||||
materializer: Materializer): Pair[Future[WebsocketUpgradeResponse], T] =
|
materializer: Materializer): Pair[Future[WebsocketUpgradeResponse], T] =
|
||||||
adaptWsResultTuple {
|
adaptWsResultTuple {
|
||||||
delegate.singleWebsocketRequest(
|
delegate.singleWebsocketRequest(
|
||||||
request.asScala,
|
request.asScala,
|
||||||
adaptWsFlow[T](clientFlow),
|
adaptWsFlow[T](clientFlow),
|
||||||
localAddress,
|
localAddress.asScala,
|
||||||
settings,
|
settings,
|
||||||
httpsContext,
|
httpsContext,
|
||||||
log)(materializer)
|
log)(materializer)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package akka.http.javadsl.model
|
package akka.http.javadsl.model
|
||||||
|
|
||||||
import akka.japi.Option
|
import java.util.Optional
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Http content-type. A content-type consists of a media-type and an optional charset.
|
* Represents an Http content-type. A content-type consists of a media-type and an optional charset.
|
||||||
|
|
@ -41,5 +41,5 @@ trait ContentType {
|
||||||
/**
|
/**
|
||||||
* Returns the charset if this ContentType is non-binary.
|
* Returns the charset if this ContentType is non-binary.
|
||||||
*/
|
*/
|
||||||
def getCharsetOption: Option[HttpCharset]
|
def getCharsetOption: Optional[HttpCharset]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model.ws
|
package akka.http.javadsl.model.ws
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.http.javadsl.model.HttpResponse
|
import akka.http.javadsl.model.HttpResponse
|
||||||
import akka.http.scaladsl
|
import akka.http.scaladsl
|
||||||
import akka.http.scaladsl.model.ws.{ InvalidUpgradeResponse, ValidUpgrade }
|
import akka.http.scaladsl.model.ws.{ InvalidUpgradeResponse, ValidUpgrade }
|
||||||
import akka.japi.Option
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an upgrade response for a Websocket upgrade request. Can either be valid, in which
|
* Represents an upgrade response for a Websocket upgrade request. Can either be valid, in which
|
||||||
|
|
@ -26,7 +27,7 @@ trait WebsocketUpgradeResponse {
|
||||||
* If valid, returns `Some(subprotocol)` (if any was requested), or `None` if none was
|
* If valid, returns `Some(subprotocol)` (if any was requested), or `None` if none was
|
||||||
* chosen or offered.
|
* chosen or offered.
|
||||||
*/
|
*/
|
||||||
def chosenSubprotocol: Option[String]
|
def chosenSubprotocol: Optional[String]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If invalid, the reason why the server's upgrade response could not be accepted.
|
* If invalid, the reason why the server's upgrade response could not be accepted.
|
||||||
|
|
@ -42,7 +43,7 @@ object WebsocketUpgradeResponse {
|
||||||
new WebsocketUpgradeResponse {
|
new WebsocketUpgradeResponse {
|
||||||
def isValid: Boolean = true
|
def isValid: Boolean = true
|
||||||
def response: HttpResponse = resp
|
def response: HttpResponse = resp
|
||||||
def chosenSubprotocol: Option[String] = chosen.asJava
|
def chosenSubprotocol: Optional[String] = chosen.asJava
|
||||||
def invalidationReason: String =
|
def invalidationReason: String =
|
||||||
throw new UnsupportedOperationException("invalidationReason must not be called for valid response")
|
throw new UnsupportedOperationException("invalidationReason must not be called for valid response")
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +51,7 @@ object WebsocketUpgradeResponse {
|
||||||
new WebsocketUpgradeResponse {
|
new WebsocketUpgradeResponse {
|
||||||
def isValid: Boolean = false
|
def isValid: Boolean = false
|
||||||
def response: HttpResponse = resp
|
def response: HttpResponse = resp
|
||||||
def chosenSubprotocol: Option[String] = throw new UnsupportedOperationException("chosenSubprotocol must not be called for valid response")
|
def chosenSubprotocol: Optional[String] = throw new UnsupportedOperationException("chosenSubprotocol must not be called for valid response")
|
||||||
def invalidationReason: String = cause
|
def invalidationReason: String = cause
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ package akka.http.scaladsl
|
||||||
|
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.{ Collection ⇒ JCollection }
|
import java.util.{ Collection ⇒ JCollection, Optional }
|
||||||
import javax.net.ssl._
|
import javax.net.ssl._
|
||||||
|
|
||||||
import akka.actor._
|
import akka.actor._
|
||||||
|
|
@ -21,7 +21,6 @@ import akka.http.scaladsl.model._
|
||||||
import akka.http.scaladsl.model.headers.Host
|
import akka.http.scaladsl.model.headers.Host
|
||||||
import akka.http.scaladsl.model.ws.{ WebsocketUpgradeResponse, WebsocketRequest, Message }
|
import akka.http.scaladsl.model.ws.{ WebsocketUpgradeResponse, WebsocketRequest, Message }
|
||||||
import akka.http.scaladsl.util.FastFuture
|
import akka.http.scaladsl.util.FastFuture
|
||||||
import akka.japi
|
|
||||||
import akka.stream.Materializer
|
import akka.stream.Materializer
|
||||||
import akka.stream.io._
|
import akka.stream.io._
|
||||||
import akka.stream.scaladsl._
|
import akka.stream.scaladsl._
|
||||||
|
|
@ -35,6 +34,8 @@ import scala.concurrent.{ ExecutionContext, Future, Promise, TimeoutException }
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
class HttpExt(private val config: Config)(implicit val system: ActorSystem) extends akka.actor.Extension
|
class HttpExt(private val config: Config)(implicit val system: ActorSystem) extends akka.actor.Extension
|
||||||
with DefaultSSLContextCreation {
|
with DefaultSSLContextCreation {
|
||||||
|
|
||||||
|
|
@ -723,16 +724,16 @@ final case class HttpsContext(sslContext: SSLContext,
|
||||||
override def getSslContext: SSLContext = sslContext
|
override def getSslContext: SSLContext = sslContext
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getEnabledCipherSuites: japi.Option[JCollection[String]] = enabledCipherSuites.map(_.asJavaCollection)
|
override def getEnabledCipherSuites: Optional[JCollection[String]] = enabledCipherSuites.map(_.asJavaCollection).asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getEnabledProtocols: japi.Option[JCollection[String]] = enabledProtocols.map(_.asJavaCollection)
|
override def getEnabledProtocols: Optional[JCollection[String]] = enabledProtocols.map(_.asJavaCollection).asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getClientAuth: japi.Option[ClientAuth] = clientAuth
|
override def getClientAuth: Optional[ClientAuth] = clientAuth.asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSslParameters: japi.Option[SSLParameters] = sslParameters
|
override def getSslParameters: Optional[SSLParameters] = sslParameters.asJava
|
||||||
}
|
}
|
||||||
|
|
||||||
trait DefaultSSLContextCreation {
|
trait DefaultSSLContextCreation {
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,20 @@
|
||||||
|
|
||||||
package akka.http.scaladsl.model
|
package akka.http.scaladsl.model
|
||||||
|
|
||||||
|
import java.util.{ OptionalLong, Optional }
|
||||||
import java.{ lang ⇒ jl }
|
import java.{ lang ⇒ jl }
|
||||||
import akka.http.impl.util.{ Rendering, ValueRenderable }
|
import akka.http.impl.util.{ Rendering, ValueRenderable }
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
sealed trait ContentRange extends jm.ContentRange with ValueRenderable {
|
sealed trait ContentRange extends jm.ContentRange with ValueRenderable {
|
||||||
// default implementations to override
|
// default implementations to override
|
||||||
def isSatisfiable: Boolean = false
|
def isSatisfiable: Boolean = false
|
||||||
def isOther: Boolean = false
|
def isOther: Boolean = false
|
||||||
def getSatisfiableFirst: akka.japi.Option[jl.Long] = akka.japi.Option.none
|
def getSatisfiableFirst: OptionalLong = OptionalLong.empty()
|
||||||
def getSatisfiableLast: akka.japi.Option[jl.Long] = akka.japi.Option.none
|
def getSatisfiableLast: OptionalLong = OptionalLong.empty()
|
||||||
def getOtherValue: akka.japi.Option[String] = akka.japi.Option.none
|
def getOtherValue: Optional[String] = Optional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait ByteContentRange extends ContentRange {
|
sealed trait ByteContentRange extends ContentRange {
|
||||||
|
|
@ -24,7 +26,7 @@ sealed trait ByteContentRange extends ContentRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def isByteContentRange: Boolean = true
|
def isByteContentRange: Boolean = true
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getInstanceLength: akka.japi.Option[jl.Long] = instanceLength.asJava
|
def getInstanceLength: OptionalLong = instanceLength.asPrimitive
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc7233#section-4.2
|
// http://tools.ietf.org/html/rfc7233#section-4.2
|
||||||
|
|
@ -48,9 +50,9 @@ object ContentRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def isSatisfiable: Boolean = true
|
override def isSatisfiable: Boolean = true
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSatisfiableFirst: akka.japi.Option[jl.Long] = akka.japi.Option.some(first)
|
override def getSatisfiableFirst: OptionalLong = OptionalLong.of(first)
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSatisfiableLast: akka.japi.Option[jl.Long] = akka.japi.Option.some(last)
|
override def getSatisfiableLast: OptionalLong = OptionalLong.of(last)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,8 +72,8 @@ object ContentRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def isByteContentRange = false
|
def isByteContentRange = false
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getInstanceLength: akka.japi.Option[jl.Long] = akka.japi.Option.none
|
def getInstanceLength: OptionalLong = OptionalLong.empty()
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getOtherValue: akka.japi.Option[String] = akka.japi.Option.some(value)
|
override def getOtherValue: Optional[String] = Optional.of(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ package akka.http.scaladsl.model
|
||||||
|
|
||||||
import language.implicitConversions
|
import language.implicitConversions
|
||||||
import akka.http.impl.util._
|
import akka.http.impl.util._
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
import java.util.Optional
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ sealed trait ContentType extends jm.ContentType with ValueRenderable {
|
||||||
private[http] def render[R <: Rendering](r: R): r.type = r ~~ mediaType
|
private[http] def render[R <: Rendering](r: R): r.type = r ~~ mediaType
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getCharsetOption: JOption[jm.HttpCharset] = charsetOption.asJava
|
def getCharsetOption: Optional[jm.HttpCharset] = charsetOption.asJava
|
||||||
}
|
}
|
||||||
|
|
||||||
object ContentType {
|
object ContentType {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
package akka.http.scaladsl.model
|
package akka.http.scaladsl.model
|
||||||
|
|
||||||
|
import java.util.OptionalLong
|
||||||
|
|
||||||
import language.implicitConversions
|
import language.implicitConversions
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.{ Iterable ⇒ JIterable, Long ⇒ JLong }
|
import java.lang.{ Iterable ⇒ JIterable, Long ⇒ JLong }
|
||||||
|
|
@ -21,6 +23,8 @@ import akka.http.scaladsl.util.FastFuture
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models the entity (aka "body" or "content) of an HTTP message.
|
* Models the entity (aka "body" or "content) of an HTTP message.
|
||||||
*/
|
*/
|
||||||
|
|
@ -82,8 +86,7 @@ sealed trait HttpEntity extends jm.HttpEntity {
|
||||||
stream.javadsl.Source.fromGraph(dataBytes.asInstanceOf[Source[ByteString, AnyRef]])
|
stream.javadsl.Source.fromGraph(dataBytes.asInstanceOf[Source[ByteString, AnyRef]])
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getContentLengthOption: japi.Option[JLong] =
|
override def getContentLengthOption: OptionalLong = contentLengthOption.asPrimitive
|
||||||
japi.Option.fromScalaOption(contentLengthOption.asInstanceOf[Option[JLong]]) // Scala autoboxing
|
|
||||||
|
|
||||||
// default implementations, should be overridden
|
// default implementations, should be overridden
|
||||||
override def isCloseDelimited: Boolean = false
|
override def isCloseDelimited: Boolean = false
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package akka.http.scaladsl.model
|
package akka.http.scaladsl.model
|
||||||
|
|
||||||
import java.lang.{ Iterable ⇒ JIterable }
|
import java.lang.{ Iterable ⇒ JIterable }
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import scala.concurrent.duration.FiniteDuration
|
import scala.concurrent.duration.FiniteDuration
|
||||||
import scala.concurrent.{ Future, ExecutionContext }
|
import scala.concurrent.{ Future, ExecutionContext }
|
||||||
|
|
@ -18,6 +19,8 @@ import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.scaladsl.util.FastFuture._
|
import akka.http.scaladsl.util.FastFuture._
|
||||||
import headers._
|
import headers._
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common base class of HttpRequest and HttpResponse.
|
* Common base class of HttpRequest and HttpResponse.
|
||||||
*/
|
*/
|
||||||
|
|
@ -110,11 +113,11 @@ sealed trait HttpMessage extends jm.HttpMessage {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getHeaders: JIterable[jm.HttpHeader] = (headers: immutable.Seq[jm.HttpHeader]).asJava
|
def getHeaders: JIterable[jm.HttpHeader] = (headers: immutable.Seq[jm.HttpHeader]).asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getHeader[T <: jm.HttpHeader](headerClass: Class[T]): akka.japi.Option[T] = header(ClassTag(headerClass))
|
def getHeader[T <: jm.HttpHeader](headerClass: Class[T]): Optional[T] = header(ClassTag(headerClass)).asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getHeader(headerName: String): akka.japi.Option[jm.HttpHeader] = {
|
def getHeader(headerName: String): Optional[jm.HttpHeader] = {
|
||||||
val lowerCased = headerName.toRootLowerCase
|
val lowerCased = headerName.toRootLowerCase
|
||||||
headers.find(_.is(lowerCased))
|
Util.convertOption(headers.find(_.is(lowerCased))) // Upcast because of invariance
|
||||||
}
|
}
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def addHeaders(headers: JIterable[jm.HttpHeader]): Self = mapHeaders(_ ++ headers.asScala.asInstanceOf[Iterable[HttpHeader]])
|
def addHeaders(headers: JIterable[jm.HttpHeader]): Self = mapHeaders(_ ++ headers.asScala.asInstanceOf[Iterable[HttpHeader]])
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,15 @@
|
||||||
package akka.http.scaladsl.model
|
package akka.http.scaladsl.model
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.Optional
|
||||||
|
import akka.http.impl.util.Util
|
||||||
|
|
||||||
import scala.collection.immutable.VectorBuilder
|
import scala.collection.immutable.VectorBuilder
|
||||||
import scala.concurrent.duration.FiniteDuration
|
import scala.concurrent.duration.FiniteDuration
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import scala.util.{ Failure, Success, Try }
|
import scala.util.{ Failure, Success, Try }
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
import akka.event.{ NoLogging, LoggingAdapter }
|
import akka.event.{ NoLogging, LoggingAdapter }
|
||||||
import akka.stream.impl.ConstantFun
|
import akka.stream.impl.ConstantFun
|
||||||
import akka.stream.Materializer
|
import akka.stream.Materializer
|
||||||
|
|
@ -23,6 +25,8 @@ import akka.http.impl.engine.rendering.BodyPartRenderer
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import FastFuture._
|
import FastFuture._
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The model of multipart content for media-types `multipart/\*` (general multipart content),
|
* The model of multipart content for media-types `multipart/\*` (general multipart content),
|
||||||
* `multipart/form-data` and `multipart/byteranges`.
|
* `multipart/form-data` and `multipart/byteranges`.
|
||||||
|
|
@ -157,14 +161,13 @@ object Multipart {
|
||||||
def getHeaders: java.lang.Iterable[jm.HttpHeader] = (headers: immutable.Seq[jm.HttpHeader]).asJava
|
def getHeaders: java.lang.Iterable[jm.HttpHeader] = (headers: immutable.Seq[jm.HttpHeader]).asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getContentDispositionHeader: JOption[jm.headers.ContentDisposition] =
|
def getContentDispositionHeader: Optional[jm.headers.ContentDisposition] = Util.convertOption(contentDispositionHeader)
|
||||||
JOption.fromScalaOption(contentDispositionHeader)
|
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getDispositionParams: java.util.Map[String, String] = dispositionParams.asJava
|
def getDispositionParams: java.util.Map[String, String] = dispositionParams.asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getDispositionType: JOption[jm.headers.ContentDispositionType] = JOption.fromScalaOption(dispositionType)
|
def getDispositionType: Optional[jm.headers.ContentDispositionType] = Util.convertOption(dispositionType)
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def toStrict(timeoutMillis: Long, materializer: Materializer): Future[_ <: jm.Multipart.BodyPart.Strict] =
|
def toStrict(timeoutMillis: Long, materializer: Materializer): Future[_ <: jm.Multipart.BodyPart.Strict] =
|
||||||
|
|
@ -409,7 +412,7 @@ object Multipart {
|
||||||
(additionalHeaders: immutable.Seq[jm.HttpHeader]).asJava
|
(additionalHeaders: immutable.Seq[jm.HttpHeader]).asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getFilename: JOption[String] = JOption.fromScalaOption(filename)
|
def getFilename: Optional[String] = filename.asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def toStrict(timeoutMillis: Long, materializer: Materializer): Future[jm.Multipart.FormData.BodyPart.Strict] =
|
override def toStrict(timeoutMillis: Long, materializer: Materializer): Future[jm.Multipart.FormData.BodyPart.Strict] =
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
package akka.http.scaladsl.model
|
package akka.http.scaladsl.model
|
||||||
|
|
||||||
import java.net.{ InetSocketAddress, UnknownHostException, InetAddress }
|
import java.net.{ InetSocketAddress, UnknownHostException, InetAddress }
|
||||||
|
import java.util.Optional
|
||||||
import akka.http.impl.util._
|
import akka.http.impl.util._
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
|
@ -15,7 +16,7 @@ sealed abstract class RemoteAddress extends jm.RemoteAddress with ValueRenderabl
|
||||||
def isUnknown: Boolean
|
def isUnknown: Boolean
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getAddress: akka.japi.Option[InetAddress] = toOption.asJava
|
def getAddress: Optional[InetAddress] = toOption.asJava
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getPort: Int = toIP.flatMap(_.port).getOrElse(0)
|
def getPort: Int = toIP.flatMap(_.port).getOrElse(0)
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,20 @@
|
||||||
|
|
||||||
package akka.http.scaladsl.model.headers
|
package akka.http.scaladsl.model.headers
|
||||||
|
|
||||||
import java.{ lang ⇒ jl }
|
import java.util.OptionalLong
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
import akka.http.impl.util.{ Rendering, ValueRenderable }
|
import akka.http.impl.util.{ Rendering, ValueRenderable }
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
|
|
||||||
sealed abstract class ByteRange extends jm.headers.ByteRange with ValueRenderable {
|
sealed abstract class ByteRange extends jm.headers.ByteRange with ValueRenderable {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getSliceFirst: JOption[jl.Long] = JOption.none
|
def getSliceFirst: OptionalLong = OptionalLong.empty
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getSliceLast: JOption[jl.Long] = JOption.none
|
def getSliceLast: OptionalLong = OptionalLong.empty
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getOffset: JOption[jl.Long] = JOption.none
|
def getOffset: OptionalLong = OptionalLong.empty
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getSuffixLength: JOption[jl.Long] = JOption.none
|
def getSuffixLength: OptionalLong = OptionalLong.empty
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def isSlice: Boolean = false
|
def isSlice: Boolean = false
|
||||||
|
|
@ -41,9 +41,9 @@ object ByteRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def isSlice: Boolean = true
|
override def isSlice: Boolean = true
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSliceFirst: JOption[jl.Long] = JOption.some(first)
|
override def getSliceFirst: OptionalLong = OptionalLong.of(first)
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSliceLast: JOption[jl.Long] = JOption.some(last)
|
override def getSliceLast: OptionalLong = OptionalLong.of(last)
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class FromOffset(offset: Long) extends ByteRange {
|
final case class FromOffset(offset: Long) extends ByteRange {
|
||||||
|
|
@ -53,7 +53,7 @@ object ByteRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def isFromOffset: Boolean = true
|
override def isFromOffset: Boolean = true
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getOffset: JOption[jl.Long] = JOption.some(offset)
|
override def getOffset: OptionalLong = OptionalLong.of(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class Suffix(length: Long) extends ByteRange {
|
final case class Suffix(length: Long) extends ByteRange {
|
||||||
|
|
@ -63,6 +63,6 @@ object ByteRange {
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def isSuffix: Boolean = true
|
override def isSuffix: Boolean = true
|
||||||
/** Java API */
|
/** Java API */
|
||||||
override def getSuffixLength: JOption[jl.Long] = JOption.some(length)
|
override def getSuffixLength: OptionalLong = OptionalLong.of(length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,11 +7,12 @@ package akka.http.scaladsl.model.headers
|
||||||
import akka.http.impl.model.parser.CharacterClasses
|
import akka.http.impl.model.parser.CharacterClasses
|
||||||
import akka.http.javadsl.model.headers
|
import akka.http.javadsl.model.headers
|
||||||
import akka.parboiled2.CharPredicate
|
import akka.parboiled2.CharPredicate
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
import java.util.{ Optional, OptionalLong }
|
||||||
import akka.http.scaladsl.model.DateTime
|
import akka.http.scaladsl.model.DateTime
|
||||||
import akka.http.impl.util._
|
import akka.http.impl.util._
|
||||||
import akka.http.javadsl.{ model ⇒ jm }
|
import akka.http.javadsl.{ model ⇒ jm }
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
// see http://tools.ietf.org/html/rfc6265
|
// see http://tools.ietf.org/html/rfc6265
|
||||||
// sealed abstract to prevent generation of default apply method in companion
|
// sealed abstract to prevent generation of default apply method in companion
|
||||||
|
|
@ -59,7 +60,7 @@ final case class HttpCookie(
|
||||||
httpOnly: Boolean = false,
|
httpOnly: Boolean = false,
|
||||||
extension: Option[String] = None) extends jm.headers.HttpCookie with ToStringRenderable {
|
extension: Option[String] = None) extends jm.headers.HttpCookie with ToStringRenderable {
|
||||||
|
|
||||||
/** Returns the name/value pair for this cookie, to be used in [[Cookiie]] headers. */
|
/** Returns the name/value pair for this cookie, to be used in [[Cookie]] headers. */
|
||||||
def pair: HttpCookiePair = HttpCookiePair(name, value)
|
def pair: HttpCookiePair = HttpCookiePair(name, value)
|
||||||
|
|
||||||
// TODO: suppress running these requires for cookies created from our header parser
|
// TODO: suppress running these requires for cookies created from our header parser
|
||||||
|
|
@ -84,15 +85,15 @@ final case class HttpCookie(
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getExtension: JOption[String] = extension.asJava
|
def getExtension: Optional[String] = extension.asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getPath: JOption[String] = path.asJava
|
def getPath: Optional[String] = path.asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getDomain: JOption[String] = domain.asJava
|
def getDomain: Optional[String] = domain.asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getMaxAge: JOption[java.lang.Long] = maxAge.asJava
|
def getMaxAge: OptionalLong = maxAge.asPrimitive
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def getExpires: JOption[jm.DateTime] = expires.asJava
|
def getExpires: Optional[jm.DateTime] = expires.map(_.asJava).asJava
|
||||||
/** Java API */
|
/** Java API */
|
||||||
def withExpires(dateTime: jm.DateTime): headers.HttpCookie = copy(expires = Some(dateTime.asScala))
|
def withExpires(dateTime: jm.DateTime): headers.HttpCookie = copy(expires = Some(dateTime.asScala))
|
||||||
/** Java API */
|
/** Java API */
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public class JavaApiTestCases {
|
||||||
if (request.method() == HttpMethods.GET) {
|
if (request.method() == HttpMethods.GET) {
|
||||||
Uri uri = request.getUri();
|
Uri uri = request.getUri();
|
||||||
if (uri.path().equals("/hello")) {
|
if (uri.path().equals("/hello")) {
|
||||||
String name = Util.getOrElse(uri.query().get("name"), "Mister X");
|
String name = uri.query().get("name").orElse("Mister X");
|
||||||
|
|
||||||
return
|
return
|
||||||
HttpResponse.create()
|
HttpResponse.create()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model
|
package akka.http.javadsl.model
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.japi.Pair
|
import akka.japi.Pair
|
||||||
|
|
||||||
import org.scalatest.{ FreeSpec, MustMatchers }
|
import org.scalatest.{ FreeSpec, MustMatchers }
|
||||||
|
|
@ -53,10 +55,10 @@ class JavaApiSpec extends FreeSpec with MustMatchers {
|
||||||
}
|
}
|
||||||
"access single parameter" in {
|
"access single parameter" in {
|
||||||
val query = Uri.create("/abc?name=blub").query()
|
val query = Uri.create("/abc?name=blub").query()
|
||||||
query.get("name") must be(akka.japi.Option.some("blub"))
|
query.get("name") must be(Optional.of("blub"))
|
||||||
query.get("age") must be(akka.japi.Option.none)
|
query.get("age") must be(Optional.empty())
|
||||||
|
|
||||||
Uri.create("/abc?name=blub&name=blib").query.get("name") must be(akka.japi.Option.some("blub"))
|
Uri.create("/abc?name=blub&name=blib").query.get("name") must be(Optional.of("blub"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@
|
||||||
|
|
||||||
package akka.http.javadsl.model
|
package akka.http.javadsl.model
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext
|
import java.util.Optional
|
||||||
|
import javax.net.ssl.{ SSLParameters, SSLContext }
|
||||||
|
|
||||||
import akka.http.javadsl.model.headers.Cookie
|
import akka.http.javadsl.model.headers.Cookie
|
||||||
import akka.http.scaladsl.model
|
import akka.http.scaladsl.model
|
||||||
import akka.http.scaladsl.model.headers.BasicHttpCredentials
|
import akka.http.scaladsl.model.headers.BasicHttpCredentials
|
||||||
|
import akka.stream.io.ClientAuth
|
||||||
import org.scalatest.{ FreeSpec, MustMatchers }
|
import org.scalatest.{ FreeSpec, MustMatchers }
|
||||||
|
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
|
|
@ -59,12 +61,11 @@ class JavaApiTestCaseSpecs extends FreeSpec with MustMatchers {
|
||||||
Uri.create("/order").query(JavaApiTestCases.addSessionId(orderId)) must be(Uri.create("/order?orderId=123&session=abcdefghijkl"))
|
Uri.create("/order").query(JavaApiTestCases.addSessionId(orderId)) must be(Uri.create("/order?orderId=123&session=abcdefghijkl"))
|
||||||
}
|
}
|
||||||
"create HttpsContext" in {
|
"create HttpsContext" in {
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
akka.http.javadsl.HttpsContext.create(SSLContext.getDefault,
|
akka.http.javadsl.HttpsContext.create(SSLContext.getDefault,
|
||||||
JOption.none,
|
Optional.empty[java.util.Collection[String]],
|
||||||
JOption.none,
|
Optional.empty[java.util.Collection[String]],
|
||||||
JOption.none,
|
Optional.empty[ClientAuth],
|
||||||
JOption.none) mustNot be(null)
|
Optional.empty[SSLParameters]) mustNot be(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,10 +10,11 @@ import akka.http.javadsl.model.MediaTypes;
|
||||||
import akka.http.javadsl.server.RequestVal;
|
import akka.http.javadsl.server.RequestVal;
|
||||||
import akka.http.javadsl.testkit.JUnitRouteTest;
|
import akka.http.javadsl.testkit.JUnitRouteTest;
|
||||||
import akka.http.javadsl.testkit.TestRoute;
|
import akka.http.javadsl.testkit.TestRoute;
|
||||||
import akka.japi.Option;
|
|
||||||
import akka.japi.Pair;
|
import akka.japi.Pair;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class FormFieldsTest extends JUnitRouteTest {
|
public class FormFieldsTest extends JUnitRouteTest {
|
||||||
static FormField<String> stringParam = FormFields.stringValue("stringParam");
|
static FormField<String> stringParam = FormFields.stringValue("stringParam");
|
||||||
static FormField<Byte> byteParam = FormFields.byteValue("byteParam");
|
static FormField<Byte> byteParam = FormFields.byteValue("byteParam");
|
||||||
|
|
@ -29,7 +30,7 @@ public class FormFieldsTest extends JUnitRouteTest {
|
||||||
static FormField<Long> hexLongParam = FormFields.hexLongValue("hexLongParam");
|
static FormField<Long> hexLongParam = FormFields.hexLongValue("hexLongParam");
|
||||||
|
|
||||||
static RequestVal<String> nameWithDefault = FormFields.stringValue("nameWithDefault").withDefault("John Doe");
|
static RequestVal<String> nameWithDefault = FormFields.stringValue("nameWithDefault").withDefault("John Doe");
|
||||||
static RequestVal<Option<Integer>> optionalIntParam = FormFields.intValue("optionalIntParam").optional();
|
static RequestVal<Optional<Integer>> optionalIntParam = FormFields.intValue("optionalIntParam").optional();
|
||||||
|
|
||||||
private Pair<String, String> param(String name, String value) {
|
private Pair<String, String> param(String name, String value) {
|
||||||
return Pair.create(name, value);
|
return Pair.create(name, value);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import akka.http.javadsl.server.RequestVal;
|
||||||
import akka.http.javadsl.server.RouteResult;
|
import akka.http.javadsl.server.RouteResult;
|
||||||
import akka.http.javadsl.testkit.JUnitRouteTest;
|
import akka.http.javadsl.testkit.JUnitRouteTest;
|
||||||
import akka.http.javadsl.testkit.TestRoute;
|
import akka.http.javadsl.testkit.TestRoute;
|
||||||
import akka.japi.Option;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -31,7 +30,7 @@ public class ParametersTest extends JUnitRouteTest {
|
||||||
static Parameter<Long> hexLongParam = Parameters.hexLongValue("hexLongParam");
|
static Parameter<Long> hexLongParam = Parameters.hexLongValue("hexLongParam");
|
||||||
|
|
||||||
static RequestVal<String> nameWithDefault = Parameters.stringValue("nameWithDefault").withDefault("John Doe");
|
static RequestVal<String> nameWithDefault = Parameters.stringValue("nameWithDefault").withDefault("John Doe");
|
||||||
static RequestVal<Option<Integer>> optionalIntParam = Parameters.intValue("optionalIntParam").optional();
|
static RequestVal<Optional<Integer>> optionalIntParam = Parameters.intValue("optionalIntParam").optional();
|
||||||
|
|
||||||
static RequestVal<Map<String, String>> paramMap = Parameters.asMap();
|
static RequestVal<Map<String, String>> paramMap = Parameters.asMap();
|
||||||
static RequestVal<Map<String, Collection<String>>> paramMultiMap = Parameters.asMultiMap();
|
static RequestVal<Map<String, Collection<String>>> paramMultiMap = Parameters.asMultiMap();
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,27 @@
|
||||||
|
|
||||||
package akka.http.impl.server
|
package akka.http.impl.server
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.http.javadsl.model.headers.HttpCookie
|
import akka.http.javadsl.model.headers.HttpCookie
|
||||||
import akka.http.javadsl.server.values.Cookie
|
import akka.http.javadsl.server.values.Cookie
|
||||||
import akka.http.javadsl.server.{ Directive, Directives, RequestVal }
|
import akka.http.javadsl.server.{ Directive, Directives, RequestVal }
|
||||||
import akka.http.scaladsl.server.Directive1
|
import akka.http.scaladsl.server.Directive1
|
||||||
import akka.http.scaladsl.server.directives.CookieDirectives._
|
import akka.http.scaladsl.server.directives.CookieDirectives._
|
||||||
import akka.japi.Option
|
|
||||||
import akka.http.impl.util.JavaMapping.Implicits._
|
import akka.http.impl.util.JavaMapping.Implicits._
|
||||||
|
|
||||||
case class CookieImpl(name: String, domain: Option[String] = None, path: Option[String] = None) extends Cookie {
|
case class CookieImpl(name: String, domain: Optional[String] = Optional.empty[String], path: Optional[String] = Optional.empty[String]) extends Cookie {
|
||||||
def withDomain(domain: String): Cookie = copy(domain = Option.some(domain))
|
def withDomain(domain: String): Cookie = copy(domain = Optional.of(domain))
|
||||||
def withPath(path: String): Cookie = copy(path = Option.some(path))
|
def withPath(path: String): Cookie = copy(path = Optional.of(path))
|
||||||
|
|
||||||
val value: RequestVal[String] =
|
val value: RequestVal[String] =
|
||||||
new StandaloneExtractionImpl[String] {
|
new StandaloneExtractionImpl[String] {
|
||||||
def directive: Directive1[String] = cookie(name).map(_.value)
|
def directive: Directive1[String] = cookie(name).map(_.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
def optionalValue(): RequestVal[Option[String]] =
|
def optionalValue(): RequestVal[Optional[String]] =
|
||||||
new StandaloneExtractionImpl[Option[String]] {
|
new StandaloneExtractionImpl[Optional[String]] {
|
||||||
def directive: Directive1[Option[String]] = optionalCookie(name).map(_.map(_.value).asJava)
|
def directive: Directive1[Optional[String]] = optionalCookie(name).map(_.map(_.value).asJava)
|
||||||
}
|
}
|
||||||
|
|
||||||
def set(value: String): Directive =
|
def set(value: String): Directive =
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,19 @@
|
||||||
|
|
||||||
package akka.http.impl.server
|
package akka.http.impl.server
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.http.javadsl.server.RequestVal
|
import akka.http.javadsl.server.RequestVal
|
||||||
import akka.http.javadsl.server.values.FormField
|
import akka.http.javadsl.server.values.FormField
|
||||||
import akka.http.scaladsl.common.{ StrictForm, NameUnmarshallerReceptacle, NameReceptacle }
|
import akka.http.scaladsl.common.{ StrictForm, NameUnmarshallerReceptacle, NameReceptacle }
|
||||||
import akka.http.scaladsl.unmarshalling._
|
import akka.http.scaladsl.unmarshalling._
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
|
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
import akka.http.scaladsl.server.directives.FormFieldDirectives._
|
import akka.http.scaladsl.server.directives.FormFieldDirectives._
|
||||||
import akka.http.scaladsl.server.{ Directives, Directive1 }
|
import akka.http.scaladsl.server.{ Directives, Directive1 }
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
*/
|
*/
|
||||||
|
|
@ -27,19 +30,19 @@ private[http] class FormFieldImpl[T, U](receptacle: NameReceptacle[T])(
|
||||||
formField(receptacle).map(conv)
|
formField(receptacle).map(conv)
|
||||||
}
|
}
|
||||||
|
|
||||||
def optional: RequestVal[JOption[U]] =
|
def optional: RequestVal[Optional[U]] =
|
||||||
new StandaloneExtractionImpl[JOption[U]] {
|
new StandaloneExtractionImpl[Optional[U]] {
|
||||||
def directive: Directive1[JOption[U]] = optionalDirective
|
def directive: Directive1[Optional[U]] = optionalDirective
|
||||||
}
|
}
|
||||||
|
|
||||||
private def optionalDirective: Directive1[JOption[U]] =
|
private def optionalDirective: Directive1[Optional[U]] =
|
||||||
extractMaterializer.flatMap { implicit fm ⇒
|
extractMaterializer.flatMap { implicit fm ⇒
|
||||||
formField(receptacle.?).map(v ⇒ JOption.fromScalaOption(v.map(conv)))
|
formField(receptacle.?).map(v ⇒ v.map(conv).asJava)
|
||||||
}
|
}
|
||||||
|
|
||||||
def withDefault(defaultValue: U): RequestVal[U] =
|
def withDefault(defaultValue: U): RequestVal[U] =
|
||||||
new StandaloneExtractionImpl[U] {
|
new StandaloneExtractionImpl[U] {
|
||||||
def directive: Directive1[U] = optionalDirective.map(_.getOrElse(defaultValue))
|
def directive: Directive1[U] = optionalDirective.map(_.orElse(defaultValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
object FormFieldImpl {
|
object FormFieldImpl {
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,20 @@
|
||||||
|
|
||||||
package akka.http.impl.server
|
package akka.http.impl.server
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.http.javadsl.server.RequestVal
|
import akka.http.javadsl.server.RequestVal
|
||||||
import akka.http.javadsl.server.values.Parameter
|
import akka.http.javadsl.server.values.Parameter
|
||||||
import akka.http.scaladsl.common.{ NameUnmarshallerReceptacle, NameReceptacle }
|
import akka.http.scaladsl.common.{ NameUnmarshallerReceptacle, NameReceptacle }
|
||||||
import akka.http.scaladsl.server.Directives._
|
import akka.http.scaladsl.server.Directives._
|
||||||
import akka.http.scaladsl.unmarshalling._
|
import akka.http.scaladsl.unmarshalling._
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
|
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
import akka.http.scaladsl.server.directives.ParameterDirectives
|
import akka.http.scaladsl.server.directives.ParameterDirectives
|
||||||
import akka.http.scaladsl.server.Directive1
|
import akka.http.scaladsl.server.Directive1
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
*/
|
*/
|
||||||
|
|
@ -25,19 +28,19 @@ private[http] class ParameterImpl[T, U](receptacle: NameReceptacle[T])(
|
||||||
import ParameterDirectives._
|
import ParameterDirectives._
|
||||||
def directive: Directive1[U] = parameter(receptacle).map(conv)
|
def directive: Directive1[U] = parameter(receptacle).map(conv)
|
||||||
|
|
||||||
def optional: RequestVal[JOption[U]] =
|
def optional: RequestVal[Optional[U]] =
|
||||||
new StandaloneExtractionImpl[JOption[U]] {
|
new StandaloneExtractionImpl[Optional[U]] {
|
||||||
def directive: Directive1[JOption[U]] = optionalDirective
|
def directive: Directive1[Optional[U]] = optionalDirective
|
||||||
}
|
}
|
||||||
|
|
||||||
private def optionalDirective: Directive1[JOption[U]] =
|
private def optionalDirective: Directive1[Optional[U]] =
|
||||||
extractMaterializer.flatMap { implicit fm ⇒
|
extractMaterializer.flatMap { implicit fm ⇒
|
||||||
parameter(receptacle.?).map(v ⇒ JOption.fromScalaOption(v.map(conv)))
|
parameter(receptacle.?).map(v ⇒ v.map(conv).asJava)
|
||||||
}
|
}
|
||||||
|
|
||||||
def withDefault(defaultValue: U): RequestVal[U] =
|
def withDefault(defaultValue: U): RequestVal[U] =
|
||||||
new StandaloneExtractionImpl[U] {
|
new StandaloneExtractionImpl[U] {
|
||||||
def directive: Directive1[U] = optionalDirective.map(_.getOrElse(defaultValue))
|
def directive: Directive1[U] = optionalDirective.map(_.orElse(defaultValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private[http] object ParameterImpl {
|
private[http] object ParameterImpl {
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,19 @@
|
||||||
|
|
||||||
package akka.http.impl.server
|
package akka.http.impl.server
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.http.javadsl.server.values.PathMatcher
|
import akka.http.javadsl.server.values.PathMatcher
|
||||||
import akka.japi.Option
|
|
||||||
|
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
import akka.http.scaladsl.server.{ PathMatcher ⇒ ScalaPathMatcher }
|
import akka.http.scaladsl.server.{ PathMatcher ⇒ ScalaPathMatcher }
|
||||||
|
|
||||||
|
import scala.compat.java8.OptionConverters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
*/
|
*/
|
||||||
private[http] class PathMatcherImpl[T: ClassTag](val matcher: ScalaPathMatcher[Tuple1[T]])
|
private[http] class PathMatcherImpl[T: ClassTag](val matcher: ScalaPathMatcher[Tuple1[T]])
|
||||||
extends ExtractionImpl[T] with PathMatcher[T] {
|
extends ExtractionImpl[T] with PathMatcher[T] {
|
||||||
def optional: PathMatcher[Option[T]] = new PathMatcherImpl[Option[T]](matcher.?.map(Option.fromScalaOption))
|
def optional: PathMatcher[Optional[T]] = new PathMatcherImpl[Optional[T]](matcher.?.map(OptionConverters.toJava))
|
||||||
}
|
}
|
||||||
|
|
@ -6,27 +6,27 @@ package akka.http.javadsl.server.values
|
||||||
|
|
||||||
import akka.http.impl.server.{ RouteStructure, CookieImpl }
|
import akka.http.impl.server.{ RouteStructure, CookieImpl }
|
||||||
import akka.http.javadsl.server.{ Directive, RequestVal, Route }
|
import akka.http.javadsl.server.{ Directive, RequestVal, Route }
|
||||||
import akka.japi.Option
|
import java.util.Optional
|
||||||
|
|
||||||
import scala.annotation.varargs
|
import scala.annotation.varargs
|
||||||
import scala.collection.immutable
|
import scala.compat.java8.OptionConverters._
|
||||||
|
|
||||||
abstract class Cookie {
|
abstract class Cookie {
|
||||||
def name(): String
|
def name(): String
|
||||||
def domain(): Option[String]
|
def domain(): Optional[String]
|
||||||
def path(): Option[String]
|
def path(): Optional[String]
|
||||||
|
|
||||||
def withDomain(domain: String): Cookie
|
def withDomain(domain: String): Cookie
|
||||||
def withPath(path: String): Cookie
|
def withPath(path: String): Cookie
|
||||||
|
|
||||||
def value(): RequestVal[String]
|
def value(): RequestVal[String]
|
||||||
def optionalValue(): RequestVal[Option[String]]
|
def optionalValue(): RequestVal[Optional[String]]
|
||||||
|
|
||||||
def set(value: String): Directive
|
def set(value: String): Directive
|
||||||
|
|
||||||
@varargs
|
@varargs
|
||||||
def delete(innerRoute: Route, moreInnerRoutes: Route*): Route =
|
def delete(innerRoute: Route, moreInnerRoutes: Route*): Route =
|
||||||
RouteStructure.DeleteCookie(name(), domain(), path())(innerRoute, moreInnerRoutes.toList)
|
RouteStructure.DeleteCookie(name(), domain().asScala, path().asScala)(innerRoute, moreInnerRoutes.toList)
|
||||||
}
|
}
|
||||||
object Cookies {
|
object Cookies {
|
||||||
def create(name: String): Cookie = new CookieImpl(name)
|
def create(name: String): Cookie = new CookieImpl(name)
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,17 @@
|
||||||
package akka.http.javadsl.server
|
package akka.http.javadsl.server
|
||||||
package values
|
package values
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
import java.{ lang ⇒ jl }
|
import java.{ lang ⇒ jl }
|
||||||
|
|
||||||
import akka.http.impl.server.{ FormFieldImpl, Util }
|
import akka.http.impl.server.{ FormFieldImpl, Util }
|
||||||
import akka.http.scaladsl.unmarshalling._
|
import akka.http.scaladsl.unmarshalling._
|
||||||
import akka.japi.function.Function
|
import akka.japi.function.Function
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
|
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
|
||||||
trait FormField[T] extends RequestVal[T] {
|
trait FormField[T] extends RequestVal[T] {
|
||||||
def optional: RequestVal[JOption[T]]
|
def optional: RequestVal[Optional[T]]
|
||||||
def withDefault(defaultValue: T): RequestVal[T]
|
def withDefault(defaultValue: T): RequestVal[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
package akka.http.javadsl.server.values
|
package akka.http.javadsl.server.values
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleEntry
|
import java.util.AbstractMap.SimpleEntry
|
||||||
import java.util.{ Collection ⇒ JCollection, Map ⇒ JMap }
|
import java.util.{ Collection ⇒ JCollection, Map ⇒ JMap, Optional }
|
||||||
import java.{ lang ⇒ jl }
|
import java.{ lang ⇒ jl }
|
||||||
|
|
||||||
import akka.http.impl.server.{ ParameterImpl, StandaloneExtractionImpl, Util }
|
import akka.http.impl.server.{ ParameterImpl, StandaloneExtractionImpl, Util }
|
||||||
|
|
@ -13,7 +13,6 @@ import akka.http.javadsl.server.RequestVal
|
||||||
import akka.http.scaladsl.server.directives.ParameterDirectives
|
import akka.http.scaladsl.server.directives.ParameterDirectives
|
||||||
import akka.http.scaladsl.unmarshalling.Unmarshaller
|
import akka.http.scaladsl.unmarshalling.Unmarshaller
|
||||||
import akka.japi.function.Function
|
import akka.japi.function.Function
|
||||||
import akka.japi.{ Option ⇒ JOption }
|
|
||||||
|
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
|
||||||
|
|
@ -21,7 +20,7 @@ import scala.reflect.ClassTag
|
||||||
* A RequestVal representing a query parameter of type T.
|
* A RequestVal representing a query parameter of type T.
|
||||||
*/
|
*/
|
||||||
trait Parameter[T] extends RequestVal[T] {
|
trait Parameter[T] extends RequestVal[T] {
|
||||||
def optional: RequestVal[JOption[T]]
|
def optional: RequestVal[Optional[T]]
|
||||||
def withDefault(defaultValue: T): RequestVal[T]
|
def withDefault(defaultValue: T): RequestVal[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
package akka.http.javadsl.server.values
|
package akka.http.javadsl.server.values
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import java.{ lang ⇒ jl, util ⇒ ju }
|
import java.{ lang ⇒ jl, util ⇒ ju }
|
||||||
|
|
||||||
import akka.http.impl.server.PathMatcherImpl
|
import akka.http.impl.server.PathMatcherImpl
|
||||||
import akka.http.javadsl.server.RequestVal
|
import akka.http.javadsl.server.RequestVal
|
||||||
import akka.http.scaladsl.server.{ PathMatcher0, PathMatcher1, PathMatchers ⇒ ScalaPathMatchers, PathMatcher ⇒ ScalaPathMatcher }
|
import akka.http.scaladsl.server.{ PathMatcher0, PathMatcher1, PathMatchers ⇒ ScalaPathMatchers, PathMatcher ⇒ ScalaPathMatcher }
|
||||||
import akka.japi.Option
|
|
||||||
import akka.japi.function.Function
|
import akka.japi.function.Function
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
@ -26,7 +26,7 @@ import scala.util.matching.Regex
|
||||||
* "consumes" a part of the path which is recorded in [[RequestContext.unmatchedPath]].
|
* "consumes" a part of the path which is recorded in [[RequestContext.unmatchedPath]].
|
||||||
*/
|
*/
|
||||||
trait PathMatcher[T] extends RequestVal[T] {
|
trait PathMatcher[T] extends RequestVal[T] {
|
||||||
def optional: PathMatcher[Option[T]]
|
def optional: PathMatcher[Optional[T]]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package akka.stream.io
|
||||||
|
|
||||||
import java.lang.{ Integer ⇒ jInteger }
|
import java.lang.{ Integer ⇒ jInteger }
|
||||||
import java.security.Principal
|
import java.security.Principal
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
import akka.japi
|
import akka.japi
|
||||||
import akka.stream._
|
import akka.stream._
|
||||||
|
|
@ -14,6 +15,7 @@ import javax.net.ssl._
|
||||||
import scala.annotation.varargs
|
import scala.annotation.varargs
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import java.security.cert.Certificate
|
import java.security.cert.Certificate
|
||||||
|
import scala.compat.java8.OptionConverters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stream cipher support based upon JSSE.
|
* Stream cipher support based upon JSSE.
|
||||||
|
|
@ -106,8 +108,8 @@ object SslTls {
|
||||||
* The SSLEngine may use this information e.g. when an endpoint identification algorithm was
|
* The SSLEngine may use this information e.g. when an endpoint identification algorithm was
|
||||||
* configured using [[SSLParameters.setEndpointIdentificationAlgorithm]].
|
* configured using [[SSLParameters.setEndpointIdentificationAlgorithm]].
|
||||||
*/
|
*/
|
||||||
def create(sslContext: SSLContext, firstSession: NegotiateNewSession, role: Role, hostInfo: japi.Option[japi.Pair[String, jInteger]], closing: Closing): JavaFlow =
|
def create(sslContext: SSLContext, firstSession: NegotiateNewSession, role: Role, hostInfo: Optional[japi.Pair[String, jInteger]], closing: Closing): JavaFlow =
|
||||||
new javadsl.BidiFlow(apply(sslContext, firstSession, role, closing, hostInfo.asScala.map(e ⇒ (e.first, e.second))))
|
new javadsl.BidiFlow(apply(sslContext, firstSession, role, closing, OptionConverters.toScala(hostInfo).map(e ⇒ (e.first, e.second))))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API.
|
* INTERNAL API.
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ object Sink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `Sink` that materializes into a `Future` of the optional first value received.
|
* A `Sink` that materializes into a `Future` of the optional first value received.
|
||||||
* If the stream completes before signaling at least a single element, the value of the Future will be an empty [[akka.japi.Option]].
|
* If the stream completes before signaling at least a single element, the value of the Future will be an empty [[java.util.Optional]].
|
||||||
* If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.
|
* If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.
|
||||||
*
|
*
|
||||||
* See also [[head]].
|
* See also [[head]].
|
||||||
|
|
@ -124,7 +124,7 @@ object Sink {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `Sink` that materializes into a `Future` of the optional last value received.
|
* A `Sink` that materializes into a `Future` of the optional last value received.
|
||||||
* If the stream completes before signaling at least a single element, the value of the Future will be an empty [[akka.japi.Option]].
|
* If the stream completes before signaling at least a single element, the value of the Future will be an empty [[java.util.Optional]].
|
||||||
* If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.
|
* If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.
|
||||||
*
|
*
|
||||||
* See also [[head]].
|
* See also [[head]].
|
||||||
|
|
|
||||||
|
|
@ -156,10 +156,11 @@ object Dependencies {
|
||||||
// akka stream & http
|
// akka stream & http
|
||||||
|
|
||||||
lazy val httpCore = l ++= Seq(
|
lazy val httpCore = l ++= Seq(
|
||||||
|
java8Compat,
|
||||||
Test.sprayJson, // for WS Autobahn test metadata
|
Test.sprayJson, // for WS Autobahn test metadata
|
||||||
Test.junitIntf, Test.junit, Test.scalatest.value)
|
Test.junitIntf, Test.junit, Test.scalatest.value)
|
||||||
|
|
||||||
lazy val http = l ++= Seq()
|
lazy val http = l ++= Seq(java8Compat)
|
||||||
|
|
||||||
// special, since it also includes a compiler plugin
|
// special, since it also includes a compiler plugin
|
||||||
lazy val parsing = Seq(
|
lazy val parsing = Seq(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue