Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system HTTP client that will initialize proxy itself #882

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/src/main/java/org/jivesoftware/resource/Default.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public class Default {
public static final String PLUGIN_BLACKLIST = "PLUGIN_BLACKLIST";
public static final String PLUGIN_BLACKLIST_CLASS = "PLUGIN_BLACKLIST_CLASS";
public static final String PLUGIN_REPOSITORY = "PLUGIN_REPOSITORY";
public static final String PLUGIN_REPOSITORY_USE_PROXY = "PLUGIN_REPOSITORY_USE_PROXY";
public static final String PROXY_PROTOCOL = "PROXY_PROTOCOL";
public static final String IDLE_LOCK = "IDLE_LOCK";
public static final String IDLE_TIME = "IDLE_TIME";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jivesoftware.sparkimpl.updater.AcceptAllCertsConnectionManager;
import org.xml.sax.SAXException;

import javax.swing.*;
Expand Down Expand Up @@ -304,27 +303,7 @@ private void loadAvailablePlugins()
public Object construct()
{
final HttpGet request = new HttpGet(retrieveListURL);

HttpHost proxy = null;
if ( Default.getBoolean( Default.PLUGIN_REPOSITORY_USE_PROXY ) )
{
String proxyHost = System.getProperty( "http.proxyHost" );
String proxyPort = System.getProperty( "http.proxyPort" );
if ( ModelUtil.hasLength( proxyHost ) && ModelUtil.hasLength(proxyPort) ) {
try{
proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
} catch ( NumberFormatException e ) {
Log.error( e );
}
}
}

try (final CloseableHttpClient httpClient =
HttpClients.custom()
.setConnectionManager(AcceptAllCertsConnectionManager.getInstance())
.setProxy(proxy)
.build();
) {
try (final CloseableHttpClient httpClient = HttpClients.createSystem()) {
return httpClient.execute(request, response -> {
if (response.getCode() != 200) {
return null;
Expand Down Expand Up @@ -383,8 +362,6 @@ private void downloadPlugin( final PublicPlugin plugin )
final HttpGet request = new HttpGet(plugin.getDownloadURL());

HttpHost proxy = null;
if ( Default.getBoolean( Default.PLUGIN_REPOSITORY_USE_PROXY ) )
{
String proxyHost = System.getProperty( "http.proxyHost" );
String proxyPort = System.getProperty( "http.proxyPort" );
if ( ModelUtil.hasLength( proxyHost ) && ModelUtil.hasLength(proxyPort) ) {
Expand All @@ -394,14 +371,8 @@ private void downloadPlugin( final PublicPlugin plugin )
Log.error( e );
}
}
}

try (final CloseableHttpClient httpClient =
HttpClients.custom()
.setConnectionManager(AcceptAllCertsConnectionManager.getInstance())
.setProxy(proxy)
.build();
) {
try (final CloseableHttpClient httpClient = HttpClients.createSystem()) {
httpClient.execute(request, response -> {
if (response.getCode() != 200) {
return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@ else if (sparkPluginInstalled) {
* @return true if there is a new build available for download.
*/
public SparkVersion isNewBuildAvailableFromJivesoftware() {

HttpHost proxy = null;
String proxyHost = System.getProperty( "http.proxyHost" );
String proxyPort = System.getProperty( "http.proxyPort" );
if ( ModelUtil.hasLength( proxyHost ) && ModelUtil.hasLength(proxyPort) ) {
try{
proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
} catch ( NumberFormatException e ) {
Log.error( e );
}
}

final String os;
if (Spark.isWindows()) {
os = "windows";
Expand All @@ -144,12 +132,7 @@ else if (Spark.isMac()) {
// if (isBetaCheckingEnabled) {
// post.addParameter("beta", "true");
// }
try (final CloseableHttpClient httpClient =
HttpClients.custom()
.setConnectionManager(AcceptAllCertsConnectionManager.getInstance())
.setProxy(proxy)
.build()
) {
try (final CloseableHttpClient httpClient = HttpClients.createSystem()) {
final ClassicHttpRequest request = ClassicRequestBuilder.post(mainUpdateURL)
.addParameter("os", os)
.setHeader("User-Agent", "Spark HttpFileUpload")
Expand Down Expand Up @@ -179,24 +162,7 @@ public void downloadUpdate(final File downloadedFile, final SparkVersion version
final java.util.Timer timer = new java.util.Timer();

final HttpGet request = new HttpGet(version.getDownloadURL());

HttpHost proxy = null;
String proxyHost = System.getProperty( "http.proxyHost" );
String proxyPort = System.getProperty( "http.proxyPort" );
if ( ModelUtil.hasLength( proxyHost ) && ModelUtil.hasLength(proxyPort) ) {
try{
proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
} catch ( NumberFormatException e ) {
Log.error( e );
}
}

try (final CloseableHttpClient httpClient =
HttpClients.custom()
.setConnectionManager(AcceptAllCertsConnectionManager.getInstance())
.setProxy(proxy)
.build();
) {
try (final CloseableHttpClient httpClient = HttpClients.createSystem()) {
httpClient.execute(request, response -> {
if (response.getCode() != 200) {
return null;
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ APPLICATION_LINK_TXT = www.igniterealtime.org
# for a sample structure see trunk/documentation/sample_plugin_repository.xml
# default: http://www.igniterealtime.org/updater/plugins.jsp
PLUGIN_REPOSITORY = http://www.igniterealtime.org/updater/plugins.jsp
# Use Sparks global Proxy to connect to the repository?
# if your repository lies within your network, this probably needs to be disabled
# default: true
PLUGIN_REPOSITORY_USE_PROXY = true
#http://www.igniterealtime.org/updater/plugins.jsp
# Disable Installing of Plugins
# set true if you want to disable installing of Plugins
INSTALL_PLUGINS_DISABLED =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.updater.AcceptAllCertsConnectionManager;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;

Expand Down Expand Up @@ -124,12 +123,7 @@ private void handleUpload(File file, ChatRoom room, Message.Type type)
private void uploadFile(File file, UploadRequest response, ChatRoom room, Message.Type type)
{
Log.debug("About to upload file for room " + room.getBareJid() + " via HTTP PUT to URL " + response.putUrl);

try (final CloseableHttpClient httpClient =
HttpClients.custom()
.setConnectionManager(AcceptAllCertsConnectionManager.getInstance())
.build()
) {
try (final CloseableHttpClient httpClient = HttpClients.createSystem()) {
final ClassicHttpRequest request = ClassicRequestBuilder.put(response.putUrl)
.setEntity(new FileEntity(file, ContentType.create("application/binary")))
.setHeader("User-Agent", "Spark HttpFileUpload")
Expand Down
Loading