Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix committed Mar 1, 2016
2 parents 86c4d28 + 1efe8cc commit 58f51d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ dependencies {
/* Excel & PDF */
compile "org.apache.poi:poi:3.9", optional
compile "org.apache.poi:poi-ooxml:3.9", optional
compile "com.itextpdf:itextpdf:5.5.0", optional
compile "com.itextpdf:itextpdf:5.5.7", optional
compile "com.itextpdf:itext-asian:5.2.0", optional
compile "org.xhtmlrenderer:flying-saucer-pdf-itext5:9.0.6", optional

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ hibernateVersion = 4.3.6.Final
hibernateValidatorVersion = 5.0.1.Final
shiroVersion = 1.2.3

systemProp.http.proxyHost=localhost
systemProp.http.proxyPort=1080
#systemProp.http.proxyHost=localhost
#systemProp.http.proxyPort=1080
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.scup.data.jpa.repository.domain;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.ManyToOne;
Expand All @@ -22,9 +24,11 @@ public abstract class AbstractAuditable<U, PK extends Serializable> extends Abst
private static final long serialVersionUID = -2363991186256484787L;

@ManyToOne
@NotFound(action= NotFoundAction.IGNORE)
private U createdBy;

@ManyToOne
@NotFound(action= NotFoundAction.IGNORE)
private U lastModifiedBy;

@Temporal(TemporalType.TIMESTAMP)
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/edu/scup/io/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ public class HttpClient {
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36";
private static final ObjectMapper objectMapper = new ObjectMapper();
public static Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
public static boolean useProxy;
private static final int socketReadTimeout = 30000;
private static final int connectTimeout = 5000;
public static final int socketReadTimeout = 30000;
public static final int connectTimeout = 5000;

public static String getResponse(String url) throws IOException {
return getResponse(url, null);
}

public static String getResponse(String url, Proxy proxy) throws IOException {
try {
HttpURLConnection conn = openConnection(url);
HttpURLConnection conn = openConnection(url, proxy);
String contentType = conn.getContentType();
String encoding = "utf-8";
if (contentType != null && contentType.indexOf("charset=") > 0) {
Expand Down Expand Up @@ -127,14 +130,18 @@ public static int downloadFile(String fileUrl, File saveTo) throws IOException,
}

public static HttpURLConnection openConnection(String url) throws URISyntaxException, IOException {
return openConnection(url, null);
}

public static HttpURLConnection openConnection(String url, Proxy proxy) throws URISyntaxException, IOException {
if (logger.isDebugEnabled()) {
if (useProxy) {
if (proxy != null) {
logger.debug("open url {} with proxy {}", url, proxy);
} else {
logger.debug("open url {}", url);
}
}
URLConnection conn = useProxy ? new URI(url).toURL().openConnection(proxy) : new URI(url).toURL().openConnection();
URLConnection conn = proxy != null ? new URI(url).toURL().openConnection(proxy) : new URI(url).toURL().openConnection();
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(socketReadTimeout);
Expand Down

0 comments on commit 58f51d3

Please sign in to comment.