Skip to content

Commit

Permalink
fixed #156 #157
Browse files Browse the repository at this point in the history
  • Loading branch information
foxinmy committed Jul 8, 2018
1 parent a6ec644 commit b2ca237
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 193 deletions.
9 changes: 9 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,13 @@

* 2018-06-14
+ version upgrade to 1.8.0

+ 新增了微信小程序相关的支持 API 实现

* 2018-07-08

+ [XEE](https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet)bug修复

+ 上传媒体文件content-length为-1导致503问题修复

+ release1.8.2版本
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId>
<version>1.8.1</version>
<version>1.8.2</version>
<packaging>pom</packaging>
<name>weixin4j</name>
<url>https://github.com/foxinmy/weixin4j</url>
Expand Down
8 changes: 1 addition & 7 deletions weixin4j-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.foxinmy</groupId>
<artifactId>weixin4j</artifactId>
<version>1.8.1</version>
<version>1.8.2</version>
</parent>
<artifactId>weixin4j-base</artifactId>
<name>weixin4j-base</name>
Expand Down Expand Up @@ -71,11 +71,5 @@
<version>3.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.19</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,74 @@
*/
public class InputStreamBody extends AbstractContentBody {

private final InputStream in;
private final String filename;
private final InputStream in;
private final String filename;

/**
* @since 4.1
*
*/
public InputStreamBody(final InputStream in, final String mimeType, final String filename) {
this(in, ContentType.create(mimeType), filename);
}
/**
* @since 4.1
*
*/
public InputStreamBody(final InputStream in, final String mimeType,
final String filename) {
this(in, ContentType.create(mimeType), filename);
}

public InputStreamBody(final InputStream in, final String filename) {
this(in, ContentType.DEFAULT_BINARY, filename);
}
public InputStreamBody(final InputStream in, final String filename) {
this(in, ContentType.DEFAULT_BINARY, filename);
}

/**
* @since 4.3
*/
public InputStreamBody(final InputStream in, final ContentType contentType, final String filename) {
super(contentType);
this.in = in;
this.filename = filename;
}
/**
* @since 4.3
*/
public InputStreamBody(final InputStream in, final ContentType contentType,
final String filename) {
super(contentType);
this.in = in;
this.filename = filename;
}

/**
* @since 4.3
*/
public InputStreamBody(final InputStream in, final ContentType contentType) {
this(in, contentType, null);
}
/**
* @since 4.3
*/
public InputStreamBody(final InputStream in, final ContentType contentType) {
this(in, contentType, null);
}

public InputStream getInputStream() {
return this.in;
}
public InputStream getInputStream() {
return this.in;
}

@Override
public void writeTo(final OutputStream out) throws IOException {
try {
final byte[] tmp = new byte[4096];
int l;
while ((l = this.in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
} finally {
this.in.close();
}
}
@Override
public void writeTo(final OutputStream out) throws IOException {
try {
final byte[] tmp = new byte[4096];
int l;
while ((l = this.in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
} finally {
this.in.close();
}
}

@Override
public String getTransferEncoding() {
return MIME.ENC_BINARY;
}
@Override
public String getTransferEncoding() {
return MIME.ENC_BINARY;
}

@Override
public long getContentLength() {
return -1;
}
@Override
public long getContentLength() {
try {
return in.available();
} catch (IOException e) {
return -1;
}
}

@Override
public String getFilename() {
return this.filename;
}
@Override
public String getFilename() {
return this.filename;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,59 @@

class MultipartFormEntity implements HttpEntity {

private final AbstractMultipartForm multipart;
private final ContentType contentType;
private final long contentLength;
private final AbstractMultipartForm multipart;
private final ContentType contentType;
private final long contentLength;

MultipartFormEntity(
final AbstractMultipartForm multipart,
final ContentType contentType,
final long contentLength) {
super();
this.multipart = multipart;
this.contentType = contentType;
this.contentLength = contentLength;
}
MultipartFormEntity(final AbstractMultipartForm multipart,
final ContentType contentType, final long contentLength) {
super();
this.multipart = multipart;
this.contentType = contentType;
this.contentLength = contentLength;
}

AbstractMultipartForm getMultipart() {
return this.multipart;
}
AbstractMultipartForm getMultipart() {
return this.multipart;
}

public boolean isRepeatable() {
return this.contentLength != -1;
}
public boolean isRepeatable() {
return this.contentLength != -1;
}

public boolean isChunked() {
return !isRepeatable();
}
public boolean isChunked() {
return !isRepeatable();
}

public boolean isStreaming() {
return !isRepeatable();
}
public boolean isStreaming() {
return !isRepeatable();
}

@Override
public long getContentLength() {
return this.contentLength;
}
@Override
public long getContentLength() {
return this.contentLength;
}

public ContentType getContentType() {
return this.contentType;
}
public ContentType getContentType() {
return this.contentType;
}

@Override
public InputStream getContent() throws IOException {
if (this.contentLength < 0) {
throw new IllegalArgumentException("Content length is unknown");
} else if (this.contentLength > 25 * 1024) {
throw new IllegalArgumentException("Content length is too long: " + this.contentLength);
}
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
writeTo(outstream);
outstream.flush();
return new ByteArrayInputStream(outstream.toByteArray());
}
@Override
public InputStream getContent() throws IOException {
if (this.contentLength < 0) {
throw new IllegalArgumentException("Content length is unknown");
} else if (this.contentLength > 5 * 1024 * 1024) {
throw new IllegalArgumentException("Content length is too long: "
+ this.contentLength);
}
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
writeTo(outstream);
outstream.flush();
return new ByteArrayInputStream(outstream.toByteArray());
}

@Override
public void writeTo(final OutputStream outstream) throws IOException {
this.multipart.writeTo(outstream);
}
@Override
public void writeTo(final OutputStream outstream) throws IOException {
this.multipart.writeTo(outstream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import org.apache.http.client.methods.HttpTrace;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.util.EntityUtils;

import com.foxinmy.weixin4j.http.AbstractHttpClient;
import com.foxinmy.weixin4j.http.HttpClientException;
import com.foxinmy.weixin4j.http.HttpHeaders;
import com.foxinmy.weixin4j.http.HttpMethod;
import com.foxinmy.weixin4j.http.HttpRequest;
import com.foxinmy.weixin4j.http.apache.mime.MultipartEntity;
import com.foxinmy.weixin4j.http.entity.HttpEntity;
import com.foxinmy.weixin4j.util.StringUtil;

Expand Down Expand Up @@ -119,18 +117,12 @@ protected void resolveHeaders(HttpHeaders headers,
protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest)
throws IOException {
if (entity != null) {
AbstractHttpEntity httpEntity = null;
if (entity instanceof MultipartEntity) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
entity.writeTo(os);
os.flush();
httpEntity = new org.apache.http.entity.ByteArrayEntity(
os.toByteArray());
os.close();
} else {
httpEntity = new InputStreamEntity(entity.getContent(),
entity.getContentLength());
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
entity.writeTo(os);
os.flush();
AbstractHttpEntity httpEntity = new org.apache.http.entity.ByteArrayEntity(
os.toByteArray());
os.close();
httpEntity.setContentType(entity.getContentType().toString());
((HttpEntityEnclosingRequestBase) httpRequest)
.setEntity(httpEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Map.Entry;

import okio.BufferedSink;
import okio.Okio;
import okio.Source;

import com.foxinmy.weixin4j.http.AbstractHttpClient;
import com.foxinmy.weixin4j.http.HttpClientException;
Expand All @@ -20,6 +22,7 @@
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.Util;

/**
* OkHttp2
Expand Down Expand Up @@ -130,7 +133,13 @@ public long contentLength() throws IOException {

@Override
public void writeTo(BufferedSink sink) throws IOException {
entity.writeTo(sink.outputStream());
Source source = null;
try {
source = Okio.source(entity.getContent());
sink.writeAll(source);
} finally {
Util.closeQuietly(source);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public OkHttpClient2Factory() {
okClient.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
okClient.setSslSocketFactory(HttpClientFactory.allowSSLContext()
.getSocketFactory());

}

public OkHttpClient2Factory(OkHttpClient okClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static SceneInfoApp createIOSAPP(String appName, String bundleId) {
* @return
*/
public static SceneInfoApp createAndroidAPP(String appName, String packageName) {
SceneInfoApp app = new SceneInfoApp("IOS", appName, packageName);
SceneInfoApp app = new SceneInfoApp("Android", appName, packageName);
String sceneInfo = String
.format("{\"type\": \"%s\",\"app_name\": \"%s\",\"package_name\": \"%s\"}",
app.getType(), app.getName(), app.getPath());
Expand Down
Loading

0 comments on commit b2ca237

Please sign in to comment.