Skip to content

Commit

Permalink
[grid] Provide a method to just get the session uri from a session map
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jan 16, 2020
1 parent b4bbfd3 commit 7db852f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.grid.sessionmap;

import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.UncheckedIOException;
import java.util.Objects;

class GetSessionUri implements HttpHandler {
private final SessionMap sessionMap;
private final SessionId sessionId;

public GetSessionUri(SessionMap sessionMap, SessionId sessionId) {
this.sessionMap = Objects.requireNonNull(sessionMap);
this.sessionId = Objects.requireNonNull(sessionId);
}

@Override
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
return new HttpResponse()
.setContent(Contents.asJson(sessionMap.getUri(sessionId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ public abstract class SessionMap implements Routable, HttpHandler {

public abstract void remove(SessionId id);

public URI getUri(SessionId id) throws NoSuchSessionException {
return get(id).getUri();
}

public SessionMap(Tracer tracer) {
this.tracer = Objects.requireNonNull(tracer);

Json json = new Json();
routes = combine(
Route.get("/se/grid/session/{sessionId}/uri")
.to(params -> new GetSessionUri(this, new SessionId(params.get("sessionId")))),
post("/se/grid/session").to(() -> new AddToSessionMap(tracer, json, this)),
Route.get("/se/grid/session/{sessionId}")
.to(params -> new GetFromSessionMap(tracer, json, this, new SessionId(params.get("sessionId")))),
Expand Down

0 comments on commit 7db852f

Please sign in to comment.