Skip to content

Commit

Permalink
Merge pull request #101 from PRIDE-Archive/proxyIssue
Browse files Browse the repository at this point in the history
Proxy , HttpErrorCorrection And UpdateChecker
  • Loading branch information
selvaebi authored Aug 12, 2020
2 parents 3ca6e38 + cda39c2 commit 0cb1ed3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package uk.ac.ebi.pride.gui.task;

import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import uk.ac.ebi.pride.App;
import uk.ac.ebi.pride.archive.submission.model.submission.SubmissionReferenceDetail;
Expand All @@ -12,6 +9,8 @@
import uk.ac.ebi.pride.toolsuite.gui.task.TaskAdapter;
import uk.ac.ebi.pride.web.util.template.SecureRestTemplateFactory;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Properties;

/**
Expand Down Expand Up @@ -42,10 +41,9 @@ protected SubmissionReferenceDetail doInBackground() throws Exception {
String proxyPort = props.getProperty("http.proxyPort");

if (proxyHost != null && proxyPort != null) {
HttpComponentsClientHttpRequestFactory factory = ((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory());
DefaultHttpClient defaultHttpClient = (DefaultHttpClient) factory.getHttpClient();
HttpHost proxy = new HttpHost(proxyHost.trim(), Integer.parseInt(proxyPort));
defaultHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setProxy(proxy);
}
result = restTemplate.postForObject(baseUrl, submissionRecord.getUploadDetail(), SubmissionReferenceDetail.class);
} catch(Exception ex){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package uk.ac.ebi.pride.gui.task;

import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import uk.ac.ebi.pride.App;
import uk.ac.ebi.pride.archive.submission.model.project.ProjectDetail;
Expand All @@ -15,6 +12,8 @@

import javax.swing.*;
import java.awt.*;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -47,10 +46,10 @@ protected Set<String> doInBackground() throws Exception {
String proxyPort = props.getProperty("http.proxyPort");

if (proxyHost != null && proxyPort != null) {
HttpComponentsClientHttpRequestFactory factory = ((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory());
DefaultHttpClient defaultHttpClient = (DefaultHttpClient) factory.getHttpClient();
HttpHost proxy = new HttpHost(proxyHost.trim(), Integer.parseInt(proxyPort));
defaultHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
logger.info("Using proxy server {} and port {}", proxyHost, proxyPort);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setProxy(proxy);
}
ProjectDetailList projectDetailList = restTemplate.getForObject(baseUrl, ProjectDetailList.class);

Expand Down
18 changes: 8 additions & 10 deletions src/main/java/uk/ac/ebi/pride/gui/task/GetPrideUserDetailTask.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package uk.ac.ebi.pride.gui.task;

import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import uk.ac.ebi.pride.App;
Expand All @@ -19,6 +16,8 @@
import uk.ac.ebi.pride.toolsuite.gui.desktop.DesktopContext;
import uk.ac.ebi.pride.toolsuite.gui.task.TaskAdapter;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Properties;

/**
Expand Down Expand Up @@ -72,10 +71,9 @@ protected ContactDetail doInBackground() throws Exception {

if (proxyHost != null && proxyPort != null) {
logger.info("Using proxy server {} and port {}", proxyHost, proxyPort);
HttpComponentsClientHttpRequestFactory factory = ((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory());
DefaultHttpClient defaultHttpClient = (DefaultHttpClient) factory.getHttpClient();
HttpHost proxy = new HttpHost(proxyHost.trim(), Integer.parseInt(proxyPort));
defaultHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setProxy(proxy);
}

HttpHeaders headers = new HttpHeaders();
Expand All @@ -89,7 +87,7 @@ protected ContactDetail doInBackground() throws Exception {
return restTemplate.exchange(userDetailUrl, HttpMethod.GET, entity, ContactDetail.class).getBody();
} catch (ResourceAccessException resourceAccessException) {
publish("Proxy/Firewall issue");
} catch (HttpServerErrorException ex) {
} catch (HttpClientErrorException ex) {
publish("UserCredentials mismatch");
}

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/uk/ac/ebi/pride/gui/task/GetUploadDetailTask.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package uk.ac.ebi.pride.gui.task;

import org.apache.http.HttpHost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import uk.ac.ebi.pride.App;
import uk.ac.ebi.pride.archive.submission.model.submission.UploadDetail;
Expand All @@ -12,6 +9,8 @@
import uk.ac.ebi.pride.toolsuite.gui.task.TaskAdapter;
import uk.ac.ebi.pride.web.util.template.SecureRestTemplateFactory;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Properties;

/**
Expand Down Expand Up @@ -49,10 +48,9 @@ protected UploadDetail doInBackground() throws Exception {
String proxyPort = props.getProperty("http.proxyPort");

if (proxyHost != null && proxyPort != null) {
HttpComponentsClientHttpRequestFactory factory = ((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory());
DefaultHttpClient defaultHttpClient = (DefaultHttpClient) factory.getHttpClient();
HttpHost proxy = new HttpHost(proxyHost.trim(), Integer.parseInt(proxyPort));
defaultHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)));
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setProxy(proxy);
}
uploadDetail = restTemplate.getForObject(baseUrl, UploadDetail.class, method.getMethod());
} catch(Exception ex){
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/uk/ac/ebi/pride/gui/util/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class UpdateChecker {

private final String updateUrl;

private static String toolCurrentVersion;
private static String latestOrHigherVersion;


public UpdateChecker(String updateUrl) {
this.updateUrl = updateUrl;
}
Expand All @@ -39,6 +43,7 @@ public UpdateChecker(String updateUrl) {
* @return boolean return true if there is a new update.
*/
public boolean hasUpdate(String currentVersion) {
toolCurrentVersion = currentVersion;
boolean toUpdate = false;
BufferedReader reader = null;
try {
Expand All @@ -53,8 +58,9 @@ public boolean hasUpdate(String currentVersion) {
if (matcher.matches()) {
String version = matcher.group(1);
if (isHigherVersion(currentVersion, version)) {
latestOrHigherVersion = version;
currentVersion = version;
toUpdate = true;
break;
}
}
}
Expand Down Expand Up @@ -94,12 +100,20 @@ private boolean isHigherVersion(String currentVersion, String version) {
*/
public static void showUpdateDialog() {
int option = JOptionPane.showConfirmDialog(null, "<html><b>A new version of ProteomeXchange submission tool is available</b>.<br><br> " +
"Would you like to update?</html>", "Update Info", JOptionPane.YES_NO_OPTION);
"Please download latest version by clicking yes </html>", "Update Info", JOptionPane.YES_NO_OPTION);

if (option == JOptionPane.YES_OPTION) {
DesktopContext context = Desktop.getInstance().getDesktopContext();
String website = context.getProperty("px.submission.tool.url");
HttpUtil.openURL(website);
}

String latestOrHigherVersionParts[] = latestOrHigherVersion.split("\\.");
String toolCurrentVersionParts[] = toolCurrentVersion.split("\\.");

if (Integer.parseInt(latestOrHigherVersionParts[0]) > Integer.parseInt(toolCurrentVersionParts[0])
|| Integer.parseInt(latestOrHigherVersionParts[1]) > Integer.parseInt(toolCurrentVersionParts[1])) {
System.exit(0);
}
}
}

0 comments on commit 0cb1ed3

Please sign in to comment.