サーバーへのPOSTリクエストを起動し、サーバーの応答結果を処理した後、サーバーがデータを書き込むときにデータをクライアントに転送できない場合、writer.write()関数で停止するという問題があります。Apache Tomcatを使用してアプリをデプロイします。サーバーが、gzipの前に約7mのデータ、gzipの後に300kのデータに応答する必要があるたびに
助けてください !
私のコード:
protected void dispatch(JSONObject request,
Map<String, FormDataItem> formItems,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse, SecurityToken token,
String callback) throws JSONException, IOException {
long timeGetData = 0;
long begin = System.currentTimeMillis();
String key = null;
if (request.has("id")) {
key = request.getString("id");
}
// getRpcHandler never returns null
Future<?> future = getHandler(request, servletRequest).execute(
formItems, token, jsonConverter);
timeGetData = System.currentTimeMillis();
// Resolve each Future into a response.
ResponseItem response = getResponseItem(future);
ResponseItem responseTemp = (ResponseItem) response.getResponse();
// Generate the output
Writer writer = servletResponse.getWriter();
if ("syndata.getAllDataFromServer".equals(request.getString("method"))) {
if (responseTemp.getErrorCode() == 200) {
SynDataObject outObject = (SynDataObject) (responseTemp
.getResponse());
writer.write(jsonConverter.convertToString(outObject
.getParams()));
writer.write("\r\n");
for (int i = 0; i < outObject.getListTableData().size(); i++) {
TableDataObject subData = outObject.getListTableData().get(
i);
int subDataLength = subData.getData().size();
int currentFarm = 0;
int factor = 1000;
int lastIndex = 0;
while (lastIndex < subDataLength) {
if ((currentFarm * factor + factor) > subDataLength) {
lastIndex = (factor * currentFarm)
+ (subDataLength - (factor * currentFarm));
} else {
lastIndex = (factor * currentFarm) + factor;
}
TableDataObject chilData = new TableDataObject();
chilData.setTableName(subData.getTableName());
chilData.setTableColumns(subData.getTableColumns());
chilData.setPkField(subData.getPkField());
chilData.setData(subData.getData().subList(
currentFarm * factor, lastIndex));
writer.write(jsonConverter.convertToString(chilData));
writer.write("\r\n");
writer.flush();
++currentFarm;
}
}
} else {
Object result = getJSONResponse(key, response);
String content = jsonConverter.convertToString(result);
if (callback != null) {
writer.write(callback);
writer.write('(');
}
writer.write(content);
if (callback != null) {
writer.write(");\n");
}
}
} else {
Object result = getJSONResponse(key, response);
String content = jsonConverter.convertToString(result);
if (callback != null) {
writer.write(callback);
writer.write('(');
}
writer.write(content);
if (callback != null) {
writer.write(");\n");
}
}
}