|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.remote.server; |
| 19 | + |
| 20 | +import org.openqa.selenium.remote.service.DriverService; |
| 21 | + |
| 22 | +import java.util.Optional; |
| 23 | +import java.util.logging.Logger; |
| 24 | +import java.util.stream.Stream; |
| 25 | + |
| 26 | +/** |
| 27 | + * Used to represent the {@link NewSessionPipeline} that is typically used in the |
| 28 | + * {@link SeleniumServer}}. |
| 29 | + */ |
| 30 | +public class DefaultPipeline { |
| 31 | + |
| 32 | + private static final Logger LOG = Logger.getLogger(DefaultPipeline.class.getName()); |
| 33 | + |
| 34 | + private DefaultPipeline() { |
| 35 | + // Utility class |
| 36 | + } |
| 37 | + |
| 38 | + public static NewSessionPipeline.Builder createPipelineWithDefaultFallbacks() { |
| 39 | + // Set up the pipeline to inject |
| 40 | + SessionFactory fallback = Stream.of( |
| 41 | + "org.openqa.selenium.chrome.ChromeDriverService", |
| 42 | + "org.openqa.selenium.firefox.GeckoDriverService", |
| 43 | + "org.openqa.selenium.edge.EdgeDriverService", |
| 44 | + "org.openqa.selenium.ie.InternetExplorerDriverService", |
| 45 | + "org.openqa.selenium.safari.SafariDriverService") |
| 46 | + .filter(name -> { |
| 47 | + try { |
| 48 | + Class.forName(name).asSubclass(DriverService.class); |
| 49 | + return true; |
| 50 | + } catch (ReflectiveOperationException e) { |
| 51 | + return false; |
| 52 | + } |
| 53 | + }) |
| 54 | + .findFirst() |
| 55 | + .map(serviceName -> { |
| 56 | + SessionFactory factory = new ServicedSession.Factory(serviceName); |
| 57 | + return (SessionFactory) (dialects, caps) -> { |
| 58 | + LOG.info("Using default factory: " + serviceName); |
| 59 | + return factory.apply(dialects, caps); |
| 60 | + }; |
| 61 | + }) |
| 62 | + .orElse((dialects, caps) -> Optional.empty()); |
| 63 | + |
| 64 | + return NewSessionPipeline.builder() |
| 65 | + .add(new ActiveSessionFactory()) |
| 66 | + .fallback(fallback); |
| 67 | + } |
| 68 | +} |
0 commit comments