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;
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue