Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// 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 com.thoughtworks.selenium.webdriven;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.thoughtworks.selenium.CommandProcessor;
import com.thoughtworks.selenium.SeleniumException;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.grid.session.ActiveSession;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.NewSessionPayload;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.FormEncodedData;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.Routable;
import org.openqa.selenium.remote.server.ActiveSessionFactory;
import org.openqa.selenium.remote.server.ActiveSessionListener;
import org.openqa.selenium.remote.server.ActiveSessions;
import org.openqa.selenium.remote.server.NewSessionPipeline;
import org.openqa.selenium.remote.tracing.Tracer;
import org.openqa.selenium.safari.SafariOptions;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.logging.Level.WARNING;
import static org.openqa.selenium.remote.http.Contents.utf8String;
import static org.openqa.selenium.remote.http.HttpMethod.POST;
/**
* An implementation of the original selenium rc server endpoint, using a webdriver-backed selenium
* in order to get things working.
*/
public class WebDriverBackedSeleniumHandler implements Routable {
// Prepare the shared set of thingies
private static final Map PROCESSORS = new ConcurrentHashMap<>();
private static final Logger LOG = Logger.getLogger(WebDriverBackedSelenium.class.getName());
private NewSessionPipeline pipeline;
private ActiveSessions sessions;
private ActiveSessionListener listener;
public WebDriverBackedSeleniumHandler(Tracer tracer, ActiveSessions sessions) {
this.sessions = sessions == null ? new ActiveSessions(5, MINUTES) : sessions;
listener = new ActiveSessionListener() {
@Override
public void onStop(ActiveSession session) {
PROCESSORS.remove(session.getId());
}
};
this.sessions.addListener(listener);
this.pipeline = NewSessionPipeline.builder().add(new ActiveSessionFactory(tracer)).create();
}
@Override
public boolean matches(HttpRequest req) {
return req.getMethod() == POST &&
("/selenium-server/driver/".equals(req.getUri()) ||
"/selenium-server/driver".equals(req.getUri()));
}
@Override
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
Optional