Skip to content

Commit

Permalink
Move Apache- and Selenium-related classes to this project's package
Browse files Browse the repository at this point in the history
  • Loading branch information
hollingsworthd committed Jul 30, 2016
1 parent f92d7b8 commit bb0f0cc
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 214 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.openqa.selenium.remote.server.JBrowserDriverProvider
com.machinepublishers.jbrowserdriver.SeleniumProvider
3 changes: 1 addition & 2 deletions src/com/machinepublishers/jbrowserdriver/CookieStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.JbdCookieSpecProvider;
import org.apache.http.message.BasicHeader;

class CookieStore extends CookieHandler implements org.apache.http.client.CookieStore, Serializable {

private static final CookieSpec spec = new JbdCookieSpecProvider().create(null);
private static final CookieSpec spec = new LaxCookieSpecProvider().create(null);
private final org.apache.http.client.CookieStore store = new BasicCookieStore();

/**
Expand Down
208 changes: 208 additions & 0 deletions src/com/machinepublishers/jbrowserdriver/LaxCookieSpecProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* jBrowserDriver (TM)
* Copyright (C) 2014-2016 Machine Publishers, LLC and the jBrowserDriver contributors
* https://github.com/MachinePublishers/jBrowserDriver
*
* Licensed 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.
*/

/*
* Note: this is a modified and renamed version of
* org.apache.http.imple.cookie.DefaultCookieSpecProvider
* which is Copyright 1999-2015 The Apache Software Foundation [http://www.apache.org/]
* and licensed 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.machinepublishers.jbrowserdriver;

import java.lang.reflect.Constructor;

import org.apache.http.conn.util.PublicSuffixMatcherLoader;
import org.apache.http.cookie.CommonCookieAttributeHandler;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.impl.cookie.BasicCommentHandler;
import org.apache.http.impl.cookie.BasicDomainHandler;
import org.apache.http.impl.cookie.BasicExpiresHandler;
import org.apache.http.impl.cookie.BasicMaxAgeHandler;
import org.apache.http.impl.cookie.BasicPathHandler;
import org.apache.http.impl.cookie.BasicSecureHandler;
import org.apache.http.impl.cookie.DefaultCookieSpec;
import org.apache.http.impl.cookie.NetscapeDraftSpec;
import org.apache.http.impl.cookie.PublicSuffixDomainFilter;
import org.apache.http.impl.cookie.RFC2109DomainHandler;
import org.apache.http.impl.cookie.RFC2109Spec;
import org.apache.http.impl.cookie.RFC2109VersionHandler;
import org.apache.http.impl.cookie.RFC2965CommentUrlAttributeHandler;
import org.apache.http.impl.cookie.RFC2965DiscardAttributeHandler;
import org.apache.http.impl.cookie.RFC2965DomainAttributeHandler;
import org.apache.http.impl.cookie.RFC2965PortAttributeHandler;
import org.apache.http.impl.cookie.RFC2965Spec;
import org.apache.http.impl.cookie.RFC2965VersionAttributeHandler;
import org.apache.http.protocol.HttpContext;

class LaxCookieSpecProvider implements CookieSpecProvider {
private static final String[] DATE_PATTERNS = new String[] {
"EEE, MMM dd HH:mm:ss yy zzz", "EEE MMM dd HH:mm:ss yy zzz", "EEE, MMM dd HH:mm:ss yy",
"EEE MMM dd HH:mm:ss yy", "MMM dd HH:mm:ss yy zzz", "MMM dd HH:mm:ss yy",

"EEE, dd MMM yy HH:mm:ss zzz", "EEE dd MMM yy HH:mm:ss zzz", "EEE, dd MMM yy HH:mm:ss",
"EEE dd MMM yy HH:mm:ss", "dd MMM yy HH:mm:ss zzz", "dd MMM yy HH:mm:ss",

"EEE, MMM-dd-yy HH:mm:ss zzz", "EEE MMM-dd-yy HH:mm:ss zzz", "EEE, MMM-dd-yy HH:mm:ss",
"EEE MMM-dd-yy HH:mm:ss", "MMM-dd-yy HH:mm:ss zzz", "MMM-dd-yy HH:mm:ss",

"EEE MMM dd yy HH:mm:ss zzz", "EEE MMM dd yy HH:mm:ss",
"MMM dd yy HH:mm:ss zzz", "MMM dd yy HH:mm:ss",

"EEE, dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss zzz", "EEE, dd-MMM-yy HH:mm:ss",
"EEE dd-MMM-yy HH:mm:ss", "dd-MMM-yy HH:mm:ss zzz", "dd-MMM-yy HH:mm:ss",

"yy-MM-dd'T'HH:mm:ssz", "yy-MM-dd'T'HH:mm:ss", "yy-MM-dd HH:mm:ssz",
"yy-MM-dd HH:mm:ss", "yy-MM-dd",
};
private volatile CookieSpec cookieSpec;

@Override
public CookieSpec create(final HttpContext context) {
if (cookieSpec == null) {
synchronized (this) {
if (cookieSpec == null) {
try {
Constructor constructor = RFC2965Spec.class.getDeclaredConstructor(boolean.class, CommonCookieAttributeHandler[].class);
constructor.setAccessible(true);
final RFC2965Spec strict = (RFC2965Spec) constructor.newInstance(false,
(Object) new CommonCookieAttributeHandler[] {
new RFC2965VersionAttributeHandler(),
new BasicPathHandler() {
@Override
public void validate(
final Cookie cookie,
final CookieOrigin origin) throws MalformedCookieException {
// No validation
}
},
new PublicSuffixFilter(PublicSuffixDomainFilter.decorate(
new RFC2965DomainAttributeHandler() {
@Override
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
// No validation
}
}, PublicSuffixMatcherLoader.getDefault())),
new RFC2965PortAttributeHandler(),
new BasicMaxAgeHandler(),
new BasicSecureHandler(),
new BasicCommentHandler(),
new RFC2965CommentUrlAttributeHandler(),
new RFC2965DiscardAttributeHandler() });
constructor = RFC2109Spec.class.getDeclaredConstructor(boolean.class, CommonCookieAttributeHandler[].class);
constructor.setAccessible(true);
final RFC2109Spec obsoleteStrict = (RFC2109Spec) constructor.newInstance(false,
(Object) new CommonCookieAttributeHandler[] {
new RFC2109VersionHandler(),
new BasicPathHandler() {
@Override
public void validate(
final Cookie cookie,
final CookieOrigin origin) throws MalformedCookieException {
// No validation
}
},
new PublicSuffixFilter(PublicSuffixDomainFilter.decorate(
new RFC2109DomainHandler() {
@Override
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
// No validation
}
}, PublicSuffixMatcherLoader.getDefault())),
new BasicMaxAgeHandler(),
new BasicSecureHandler(),
new BasicCommentHandler() });
constructor = NetscapeDraftSpec.class.getDeclaredConstructor(CommonCookieAttributeHandler[].class);
constructor.setAccessible(true);
final NetscapeDraftSpec netscapeDraft = (NetscapeDraftSpec) constructor.newInstance(
(Object) new CommonCookieAttributeHandler[] {
new PublicSuffixFilter(PublicSuffixDomainFilter.decorate(
new BasicDomainHandler() {
@Override
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
// No validation
}
}, PublicSuffixMatcherLoader.getDefault())),
new BasicPathHandler() {
@Override
public void validate(
final Cookie cookie,
final CookieOrigin origin) throws MalformedCookieException {
// No validation
}
},
new BasicSecureHandler(),
new BasicCommentHandler(),
new BasicExpiresHandler(DATE_PATTERNS) });
constructor = DefaultCookieSpec.class.getDeclaredConstructor(RFC2965Spec.class, RFC2109Spec.class, NetscapeDraftSpec.class);
constructor.setAccessible(true);
this.cookieSpec = (DefaultCookieSpec) constructor.newInstance(strict, obsoleteStrict, netscapeDraft);
} catch (Throwable t) {
Util.handleException(t);
}
}
}
}
return this.cookieSpec;
}

private static class PublicSuffixFilter implements CommonCookieAttributeHandler {
private CommonCookieAttributeHandler parent;

public PublicSuffixFilter(CommonCookieAttributeHandler parent) {
this.parent = parent;
}

@Override
public void parse(SetCookie cookie, String value) throws MalformedCookieException {
parent.parse(cookie, value);
}

@Override
public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
parent.validate(cookie, origin);
}

@Override
public boolean match(Cookie cookie, CookieOrigin origin) {
if (cookie.getDomain() == null || cookie.getDomain().isEmpty()) {
return true;
}
return parent.match(cookie, origin);
}

@Override
public String getAttributeName() {
return parent.getAttributeName();
}
}
}
6 changes: 3 additions & 3 deletions src/com/machinepublishers/jbrowserdriver/LogsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import java.util.Set;
import java.util.logging.Level;

import org.apache.commons.logging.JbdWireLog;
import org.openqa.selenium.logging.LogEntries;

@SuppressWarnings("deprecation") //WireLog is not actually deprecated--it's for internal use only
class LogsServer extends RemoteObject implements LogsRemote, org.openqa.selenium.logging.Logs {
private static class WireAppender implements Appendable {
@Override
Expand All @@ -52,7 +52,7 @@ public Appendable append(char c) throws IOException {
}

static {
JbdWireLog.setAppender(new WireAppender());
WireLog.setAppender(new WireAppender());
}

private final LinkedList<Entry> wire = new LinkedList<Entry>();
Expand All @@ -73,7 +73,7 @@ public Appendable append(char c) throws IOException {
static void updateSettings() {
Settings settings = SettingsManager.settings();
if (settings != null && settings.logWire()) {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.JbdWireLog");
System.setProperty("org.apache.commons.logging.Log", "com.machinepublishers.jbrowserdriver.WireLog");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG");
} else {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openqa.selenium.remote.server;
package com.machinepublishers.jbrowserdriver;

import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.server.DefaultDriverProvider;

import com.machinepublishers.jbrowserdriver.JBrowserDriver;

public class JBrowserDriverProvider extends DefaultDriverProvider {
public JBrowserDriverProvider() {
/**
* Internal use only.
*
* @deprecated
*/
public class SeleniumProvider extends DefaultDriverProvider {
public SeleniumProvider() {
super(new DesiredCapabilities("jbrowserdriver", "1", Platform.ANY), JBrowserDriver.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.cookie.JbdCookieSpecProvider;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.ssl.SSLContexts;
Expand All @@ -75,7 +74,7 @@ class StreamConnectionClient {
private static final Set<String> nonCachedMethods = Collections.unmodifiableSet(new HashSet<String>(
Arrays.asList(new String[] { "POST", "PUT", "DELETE" })));
private static final Registry<CookieSpecProvider> cookieProvider = RegistryBuilder.<CookieSpecProvider> create()
.register("custom", new JbdCookieSpecProvider())
.register("custom", new LaxCookieSpecProvider())
.build();
private static Pattern pemBlock = Pattern.compile(
"-----BEGIN CERTIFICATE-----\\s*(.*?)\\s*-----END CERTIFICATE-----", Pattern.DOTALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging;
package com.machinepublishers.jbrowserdriver;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JbdWireLog implements Log, Serializable {
import org.apache.commons.logging.Log;

/**
* Internal use only.
*
* @deprecated
*/
public class WireLog implements Log, Serializable {
private static final Pattern request = Pattern.compile("^http-outgoing-[0-9]+\\s>>\\s\"(.+)\"$");
private static final Pattern response = Pattern.compile(
"^http-outgoing-[0-9]+\\s<<\\s\"((?:HTTP/.+)|(?:[^:]+:\\s.+))\"$");
private static final int MAX_LEN = 500;
private static final AtomicReference<Appendable> appender = new AtomicReference<Appendable>();

public static void setAppender(Appendable appender) {
JbdWireLog.appender.set(appender);
WireLog.appender.set(appender);
}

public JbdWireLog(String s) {}
public WireLog(String s) {}

@Override
public void debug(Object objMessage) {
Expand Down
Loading

0 comments on commit bb0f0cc

Please sign in to comment.