Skip to content

Commit

Permalink
去掉多余的jar包
Browse files Browse the repository at this point in the history
  • Loading branch information
foxinmy committed May 24, 2015
1 parent b572239 commit d0aba82
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 80 deletions.
71 changes: 16 additions & 55 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,31 @@
</developer>
</developers>
<properties>
<jdk.version>1.7</jdk.version>
<junit.version>4.8.2</junit.version>
<dom4j.version>1.6.1</dom4j.version>
<xstream.version>1.4.7</xstream.version>
<httpclient.version>4.2.5</httpclient.version>
<fastjson.version>1.2.3</fastjson.version>
<jaxen.version>1.1.6</jaxen.version>
<jedis.version>2.6.0</jedis.version>
<commons.lang.version>3.3.2</commons.lang.version>
<slf4j.api.version>1.7.10</slf4j.api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.source.plugin.version>2.4</maven.source.plugin.version>
<maven.compiler.plugin.version>3.0</maven.compiler.plugin.version>
<maven.resources.plugin.version>2.6</maven.resources.plugin.version>
<maven.jar.plugin.version>2.5</maven.jar.plugin.version>
<maven.assembly.plugin.version>2.5.1</maven.assembly.plugin.version>
<maven.javadoc.plugin.version>2.10.1</maven.javadoc.plugin.version>
<maven.deploy.plugin.version>2.8.2</maven.deploy.plugin.version>
<maven.gpg.plugin.version>1.5</maven.gpg.plugin.version>
<maven.surefire.plugin.version>2.18</maven.surefire.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.plugin.version}</version>
<version>2.6</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<version>2.5</version>
<executions>
<execution>
<id>default-jar</id>
Expand Down Expand Up @@ -112,7 +93,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<version>2.5.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly.xml</descriptor>
Expand All @@ -131,7 +112,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -144,7 +125,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.plugin.version}</version>
<version>2.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -166,12 +147,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.plugin.version}</version>
<version>1.5</version>
<executions>
<execution>
<phase>verify</phase>
Expand All @@ -184,7 +165,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<version>2.18</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
Expand Down Expand Up @@ -212,23 +193,18 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>${xstream.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpclient.version}</version>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
<version>4.2.5</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
Expand All @@ -240,30 +216,15 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.api.version}</version>
<version>2.6.0</version>
</dependency>
</dependencies>
<profiles>
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/com/foxinmy/easemob4j/http/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
Expand All @@ -32,8 +31,6 @@
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.foxinmy.easemob4j.exception.EasemobException;
Expand All @@ -51,9 +48,6 @@ public class HttpRequest {

protected AbstractHttpClient client;

private final static Logger log = LoggerFactory
.getLogger(HttpRequest.class);

public HttpRequest() {
this(150, 100, 10000, 10000);
}
Expand Down Expand Up @@ -111,10 +105,10 @@ public X509Certificate[] getAcceptedIssuers() {
public Response post(String url, String token, String body)
throws EasemobException {
HttpPost method = new HttpPost(url);
if (StringUtils.isNotBlank(token)) {
if (token != null && !token.trim().isEmpty()) {
method.addHeader("Authorization", String.format("Bearer %s", token));
}
if (StringUtils.isNotBlank(body)) {
if (body != null && !body.trim().isEmpty()) {
method.setEntity(new StringEntity(body, ContentType.create(
ContentType.APPLICATION_JSON.getMimeType(), Consts.UTF_8)));
}
Expand All @@ -125,7 +119,6 @@ protected Response doRequest(HttpRequestBase request)
throws EasemobException {
Response response = null;
try {
log.info("em request:{}", request);
HttpResponse httpResponse = client.execute(request);
StatusLine statusLine = httpResponse.getStatusLine();
HttpEntity httpEntity = httpResponse.getEntity();
Expand All @@ -138,7 +131,6 @@ protected Response doRequest(HttpRequestBase request)
response.setStream(new ByteArrayInputStream(data));
response.setText(new String(data, Consts.UTF_8));
EntityUtils.consume(httpEntity);
log.info("em response:{}", response);
if (status != HttpStatus.SC_OK) {
JSONObject errorJson = response.getAsJson();
throw new EasemobException(errorJson.getString("error"),
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/foxinmy/easemob4j/token/FileTokenHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import java.io.IOException;
import java.util.Calendar;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import com.foxinmy.easemob4j.exception.EasemobException;
import com.foxinmy.easemob4j.model.EMAccount;
import com.foxinmy.easemob4j.util.EMConfigUtil;
import com.thoughtworks.xstream.XStream;

/**
* 用FILE保存TOKEN
Expand All @@ -20,7 +24,8 @@
* @since JDK 1.7
*/
public class FileTokenHolder extends TokenHolder {
private final XStream xstream;
private Unmarshaller unmarshaller;
private Marshaller marshaller;
private final String tokenPath;

public FileTokenHolder() {
Expand All @@ -30,11 +35,13 @@ public FileTokenHolder() {
public FileTokenHolder(EMAccount account) {
super(account);
this.tokenPath = EMConfigUtil.getValue("token_path");
xstream = new XStream();
xstream.ignoreUnknownElements();
xstream.autodetectAnnotations(true);
xstream.alias("xml", Token.class);
xstream.processAnnotations(Token.class);
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Token.class);
unmarshaller = jaxbContext.createUnmarshaller();
marshaller = jaxbContext.createMarshaller();
} catch (JAXBException e) {
;
}
}

@Override
Expand All @@ -46,18 +53,20 @@ public Token getToken() throws EasemobException {
long now_time = ca.getTimeInMillis();
try {
if (token_file.exists()) {
token = (Token) xstream
.fromXML(new FileInputStream(token_file));
token = (Token) unmarshaller.unmarshal(new FileInputStream(
token_file));
long expire_time = token.getTime()
+ (token.getExpiresIn() * 1000) - 2;
if (expire_time > now_time) {
return token;
}
}
token = createToken();
xstream.toXML(token, new FileOutputStream(token_file));
marshaller.marshal(token, new FileOutputStream(token_file));
} catch (IOException e) {
throw new EasemobException(e.getMessage());
} catch (JAXBException e) {
throw new EasemobException(e.getMessage());
}
return token;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.foxinmy.easemob4j.token;

import org.apache.commons.lang3.StringUtils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
Expand Down Expand Up @@ -36,7 +34,7 @@ public RedisTokenHolder() {
public RedisTokenHolder(JedisPool jedisPool) {
this(jedisPool, EMConfigUtil.getAccount());
}

public RedisTokenHolder(String host, int port, EMAccount account) {
super(account);
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
Expand All @@ -53,7 +51,6 @@ public RedisTokenHolder(JedisPool jedisPool, EMAccount account) {
this.jedisPool = jedisPool;
}


@Override
public Token getToken() throws EasemobException {
Token token = null;
Expand All @@ -62,7 +59,7 @@ public Token getToken() throws EasemobException {
jedis = jedisPool.getResource();
String cacheKey = getCacheKey();
String accessToken = jedis.get(cacheKey);
if (StringUtils.isBlank(accessToken)) {
if (accessToken == null || accessToken.trim().isEmpty()) {
token = createToken();
jedis.setex(cacheKey, (int) token.getExpiresIn(),
token.getAccessToken());
Expand Down

0 comments on commit d0aba82

Please sign in to comment.