19441: Use Optional instead of Option in http core javadsl

This commit is contained in:
Endre Sándor Varga 2016-01-15 13:03:27 +01:00
parent 7a39063f2e
commit 57c1dfde8a
54 changed files with 302 additions and 248 deletions

View file

@ -4,13 +4,14 @@
package docs.http.javadsl;
import akka.japi.Option;
import akka.util.ByteString;
import org.junit.Test;
//#import-model
import akka.http.javadsl.model.*;
import akka.http.javadsl.model.headers.*;
import java.util.Optional;
//#import-model
@SuppressWarnings("unused")
@ -79,12 +80,12 @@ public class ModelDocTest {
//#headers
// a method that extracts basic HTTP credentials from a request
private Option<BasicHttpCredentials> getCredentialsOfRequest(HttpRequest request) {
Option<Authorization> auth = request.getHeader(Authorization.class);
if (auth.isDefined() && auth.get().credentials() instanceof BasicHttpCredentials)
return Option.some((BasicHttpCredentials) auth.get().credentials());
private Optional<BasicHttpCredentials> getCredentialsOfRequest(HttpRequest request) {
Optional<Authorization> auth = request.getHeader(Authorization.class);
if (auth.isPresent() && auth.get().credentials() instanceof BasicHttpCredentials)
return Optional.of((BasicHttpCredentials) auth.get().credentials());
else
return Option.none();
return Optional.empty();
}
//#headers
}

View file

@ -202,7 +202,7 @@ public class HttpServerExampleDocTest {
.withEntity(ContentTypes.TEXT_HTML_UTF8,
"<html><body>Hello world!</body></html>");
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
HttpResponse.create()

View file

@ -209,11 +209,11 @@ public class MigrationsJava {
Uri uri = null;
//#raw-query
final akka.japi.Option<String> theRawQueryString = uri.rawQueryString();
final Optional<String> theRawQueryString = uri.rawQueryString();
//#raw-query
//#query-param
final akka.japi.Option<String> aQueryParam = uri.query().get("a");
final Optional<String> aQueryParam = uri.query().get("a");
//#query-param
//#file-source-sink

View file

@ -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::
RequestVal<T> instance()
RequestVal<<Option<T>> optionalInstance()
RequestVal<<Optional<T>> optionalInstance()
RequestVal<String> value()
RequestVal<Option<String>> optionalValue()
RequestVal<Optional<String>> optionalValue()
Examples
--------

View file

@ -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>`_)
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: