This commit is contained in:
@@ -21,6 +21,8 @@ import java.nio.charset.*;
|
|||||||
*/
|
*/
|
||||||
public final class HttpRequest extends Request {
|
public final class HttpRequest extends Request {
|
||||||
|
|
||||||
|
protected static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
protected static final String SESSIONID_NAME = "JSESSIONID";
|
protected static final String SESSIONID_NAME = "JSESSIONID";
|
||||||
|
|
||||||
private static final byte[] flashRequestContent1 = "<policy-file-request/>\0".getBytes();
|
private static final byte[] flashRequestContent1 = "<policy-file-request/>\0".getBytes();
|
||||||
@@ -55,6 +57,8 @@ public final class HttpRequest extends Request {
|
|||||||
|
|
||||||
private final ByteArray array = new ByteArray();
|
private final ByteArray array = new ByteArray();
|
||||||
|
|
||||||
|
private boolean bodyparsed = false;
|
||||||
|
|
||||||
protected boolean flashPolicy = false;
|
protected boolean flashPolicy = false;
|
||||||
|
|
||||||
protected boolean boundary = false;
|
protected boolean boundary = false;
|
||||||
@@ -164,9 +168,9 @@ public final class HttpRequest extends Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void parseBody() {
|
private void parseBody() {
|
||||||
if (this.boundary || array.isEmpty()) return;
|
if (this.boundary || bodyparsed) return;
|
||||||
addParameter(array, 0, array.count());
|
addParameter(array, 0, array.count());
|
||||||
array.clear();
|
bodyparsed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addParameter(final ByteArray array, final int offset, final int len) {
|
private void addParameter(final ByteArray array, final int offset, final int len) {
|
||||||
@@ -236,6 +240,18 @@ public final class HttpRequest extends Request {
|
|||||||
return String.valueOf(addr);
|
return String.valueOf(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBody(final Charset charset) {
|
||||||
|
return array.toString(charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBody() {
|
||||||
|
return array.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBodyUTF8() {
|
||||||
|
return array.toString(UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
public SocketAddress getRemoteAddress() {
|
public SocketAddress getRemoteAddress() {
|
||||||
return this.channel.getRemoteAddress();
|
return this.channel.getRemoteAddress();
|
||||||
}
|
}
|
||||||
@@ -246,7 +262,7 @@ public final class HttpRequest extends Request {
|
|||||||
return this.getClass().getSimpleName() + "{method:" + this.method + ", requestURI:" + this.requestURI
|
return this.getClass().getSimpleName() + "{method:" + this.method + ", requestURI:" + this.requestURI
|
||||||
+ ", contentType:" + this.contentType + ", connection:" + this.connection + ", protocol:" + this.protocol
|
+ ", contentType:" + this.contentType + ", connection:" + this.connection + ", protocol:" + this.protocol
|
||||||
+ ", contentLength:" + this.contentLength + ", cookiestr:" + this.cookiestr
|
+ ", contentLength:" + this.contentLength + ", cookiestr:" + this.cookiestr
|
||||||
+ ", host:" + this.host + ", params:" + this.params + ", header:" + this.header + "body:" + (array == null ? "null" : array.toString()) + "}";
|
+ ", host:" + this.host + ", params:" + this.params + ", header:" + this.header + "body:" + getBody() + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public final MultiContext getMultiContext() {
|
public final MultiContext getMultiContext() {
|
||||||
@@ -272,6 +288,7 @@ public final class HttpRequest extends Request {
|
|||||||
this.connection = null;
|
this.connection = null;
|
||||||
this.contentLength = -1;
|
this.contentLength = -1;
|
||||||
this.boundary = false;
|
this.boundary = false;
|
||||||
|
this.bodyparsed = false;
|
||||||
this.flashPolicy = false;
|
this.flashPolicy = false;
|
||||||
|
|
||||||
this.header.clear();
|
this.header.clear();
|
||||||
|
|||||||
@@ -1527,12 +1527,16 @@ public final class DataJDBCSource implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String genSQL(String queryColumn, EntityXInfo info, String column, FilterExpress express, Serializable key) {
|
private String genSQL(String queryColumn, EntityXInfo info, String column, FilterExpress express, Serializable key) {
|
||||||
String sql = "SELECT " + queryColumn + " FROM " + info.getTable() + " WHERE " + info.getSQLColumn(column) + " " + express.value();
|
String sql = "SELECT " + queryColumn + " FROM " + info.getTable();
|
||||||
if (key instanceof Number) {
|
if (key instanceof Number) {
|
||||||
sql += " " + key;
|
sql += " WHERE " + info.getSQLColumn(column) + " " + express.value() + " " + key;
|
||||||
} else if (key instanceof Collection) {
|
} else if (key instanceof Collection) {
|
||||||
|
Collection list = (Collection) key;
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
sql += " WHERE 1 " + (express == FilterExpress.NOTIN ? "=" : "!=") + " 1";
|
||||||
|
} else {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Object o : (Collection) key) {
|
for (Object o : list) {
|
||||||
if (sb.length() > 0) sb.append(',');
|
if (sb.length() > 0) sb.append(',');
|
||||||
if (o instanceof Number) {
|
if (o instanceof Number) {
|
||||||
sb.append('"').append(o).append('"');
|
sb.append('"').append(o).append('"');
|
||||||
@@ -1540,10 +1544,14 @@ public final class DataJDBCSource implements DataSource {
|
|||||||
sb.append('"').append(o.toString().replace("\"", "\\\"")).append('"');
|
sb.append('"').append(o.toString().replace("\"", "\\\"")).append('"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sql += " (" + sb + ")";
|
sql += " WHERE " + info.getSQLColumn(column) + " " + express.value() + " (" + sb + ")";
|
||||||
|
}
|
||||||
} else if (key.getClass().isArray()) {
|
} else if (key.getClass().isArray()) {
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
int len = Array.getLength(key);
|
int len = Array.getLength(key);
|
||||||
|
if (len == 0) {
|
||||||
|
sql += " WHERE 1 " + (express == FilterExpress.NOTIN ? "=" : "!=") + " 1";
|
||||||
|
} else {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
Object o = Array.get(key, i);
|
Object o = Array.get(key, i);
|
||||||
if (sb.length() > 0) sb.append(',');
|
if (sb.length() > 0) sb.append(',');
|
||||||
@@ -1553,9 +1561,10 @@ public final class DataJDBCSource implements DataSource {
|
|||||||
sb.append('"').append(o.toString().replace("\"", "\\\"")).append('"');
|
sb.append('"').append(o.toString().replace("\"", "\\\"")).append('"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sql += " (" + sb + ")";
|
sql += " WHERE " + info.getSQLColumn(column) + " " + express.value() + " (" + sb + ")";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sql += " \"" + key.toString().replace("\"", "\\\"") + "\"";
|
sql += " WHERE " + info.getSQLColumn(column) + " " + express.value() + " \"" + key.toString().replace("\"", "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import java.io.*;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import javax.net.ssl.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -16,6 +18,8 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class Utility {
|
public final class Utility {
|
||||||
|
|
||||||
|
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
|
||||||
private static final sun.misc.Unsafe UNSAFE;
|
private static final sun.misc.Unsafe UNSAFE;
|
||||||
@@ -295,6 +299,60 @@ public final class Utility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
public static String postHttpContent(String url) throws IOException {
|
||||||
|
return remoteHttpContent(null, "POST", url, null).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postHttpContent(String url, String body) throws IOException {
|
||||||
|
return remoteHttpContent(null, "POST", url, body).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHttpContent(String url) throws IOException {
|
||||||
|
return remoteHttpContent(null, "GET", url, null).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getHttpBytesContent(String url) throws IOException {
|
||||||
|
return remoteHttpContent(null, "GET", url, null).toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postHttpContent(SSLContext ctx, String url) throws IOException {
|
||||||
|
return remoteHttpContent(ctx, "POST", url, null).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String postHttpContent(SSLContext ctx, String url, String body) throws IOException {
|
||||||
|
return remoteHttpContent(ctx, "POST", url, body).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHttpContent(SSLContext ctx, String url) throws IOException {
|
||||||
|
return remoteHttpContent(ctx, "GET", url, null).toString("UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] getHttpBytesContent(SSLContext ctx, String url) throws IOException {
|
||||||
|
return remoteHttpContent(ctx, "GET", url, null).toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ByteArrayOutputStream remoteHttpContent(SSLContext ctx, String method, String url, String body) throws IOException {
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
conn.setConnectTimeout(3000);
|
||||||
|
conn.setReadTimeout(3000);
|
||||||
|
if (ctx != null && conn instanceof HttpsURLConnection) ((HttpsURLConnection) conn).setSSLSocketFactory(ctx.getSocketFactory());
|
||||||
|
conn.setRequestMethod(method);
|
||||||
|
if (body != null) {
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.getOutputStream().write(body.getBytes(UTF_8));
|
||||||
|
}
|
||||||
|
conn.connect();
|
||||||
|
InputStream in = conn.getInputStream();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
int pos;
|
||||||
|
while ((pos = in.read(bytes)) != -1) {
|
||||||
|
out.write(bytes, 0, pos);
|
||||||
|
}
|
||||||
|
conn.disconnect();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
public static String read(InputStream in) throws IOException {
|
public static String read(InputStream in) throws IOException {
|
||||||
return read(in, "UTF-8");
|
return read(in, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user