forked from karussell/snacktory
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request karussell#34 from skyshard/abhishek/empty_extracti…
…on_apnews Fixed content extraction for apnews.com
- Loading branch information
Showing
8 changed files
with
1,280 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/de/jetwick/snacktory/utils/SSLConnectionSocketFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package de.jetwick.snacktory.utils; | ||
|
||
|
||
import javax.net.ssl.SSLParameters; | ||
import javax.net.ssl.SSLSocket; | ||
import javax.net.ssl.SSLSocketFactory; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* In Java 8, SSLSocketFactory has some weird behaviour when the HostNameVerification is | ||
* bypassed it also skip the SNI header. | ||
* <p> | ||
* To overcome the default behaviour this class helps to include SNI in the SSL requests. | ||
* <p> | ||
* Ref: http://javabreaks.blogspot.in/2015/12/java-ssl-handshake-with-server-name.html | ||
*/ | ||
public class SSLConnectionSocketFactory extends SSLSocketFactory { | ||
|
||
private final SSLSocketFactory sslSocketFactory; | ||
private final SSLParameters sslParameters; | ||
|
||
public SSLConnectionSocketFactory(SSLSocketFactory sslSocketFactory, SSLParameters sslParameters) { | ||
this.sslSocketFactory = sslSocketFactory; | ||
this.sslParameters = sslParameters; | ||
} | ||
|
||
@Override | ||
public String[] getDefaultCipherSuites() { | ||
return sslSocketFactory.getDefaultCipherSuites(); | ||
} | ||
|
||
@Override | ||
public String[] getSupportedCipherSuites() { | ||
return sslSocketFactory.getSupportedCipherSuites(); | ||
} | ||
|
||
@Override | ||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException { | ||
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, autoClose); | ||
setParameters(sslSocket); | ||
return sslSocket; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException { | ||
SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(host, port); | ||
setParameters(socket); | ||
return socket; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) | ||
throws IOException { | ||
SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(host, port, localHost, localPort); | ||
setParameters(socket); | ||
return socket; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(InetAddress host, int port) throws IOException { | ||
SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(host, port); | ||
setParameters(socket); | ||
return socket; | ||
} | ||
|
||
@Override | ||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { | ||
SSLSocket socket = (SSLSocket) sslSocketFactory.createSocket(address, port, localAddress, localPort); | ||
setParameters(socket); | ||
return socket; | ||
} | ||
|
||
private void setParameters(SSLSocket socket) { | ||
socket.setSSLParameters(sslParameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
defaultTimezone: UTC | ||
defaultTimezone: UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.