Skip to content

Commit

Permalink
调整异常信息:去掉url地址拼接到异常信息,以debug输出到日志文件中
Browse files Browse the repository at this point in the history
  • Loading branch information
yin-bp committed Mar 20, 2020
1 parent be76fed commit 9ce709e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJ_GROUP=com.bbossgroups
PROJ_VERSION=5.6.6
PROJ_VERSION=5.6.7
BBOSS_VERSION=5.6.6
skipTest=true
PROJ_WEBSITEURL=http://www.bbossgroups.com
Expand Down
20 changes: 8 additions & 12 deletions src/org/frameworkset/spi/remote/http/BaseURLResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
* limitations under the License.
*/

import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.frameworkset.spi.remote.http.proxy.HttpProxyRequestException;

import java.io.IOException;

/**
* <p>Description: </p>
* <p></p>
Expand All @@ -39,10 +33,12 @@ public String getUrl() {
public void setUrl(String url) {
this.url = url;
}
protected RuntimeException throwException(int status, HttpEntity entity) throws IOException {
if (entity != null )
return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
else
return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
// protected RuntimeException throwException1(int status, HttpEntity entity) throws IOException {
// if (entity != null ) {
// return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append("\r\n").append(EntityUtils.toString(entity)).toString());
// }
// else{
// return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
// }
// }
}
40 changes: 30 additions & 10 deletions src/org/frameworkset/spi/remote/http/HttpRequestProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3029,8 +3029,12 @@ public static <K,T> Map<K,T> handleMapResponse(String url,HttpResponse response,
return entity != null ? converJson2Map( entity, keyType, beanType) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
Expand All @@ -3044,8 +3048,12 @@ public static <T> List<T> handleListResponse(String url,HttpResponse response, C
return entity != null ? converJson2List( entity, resultType) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
Expand All @@ -3059,8 +3067,12 @@ public static <T> Set<T> handleSetResponse(String url,HttpResponse response, Cla
return entity != null ? converJson2Set( entity, resultType) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
Expand All @@ -3074,8 +3086,12 @@ public static <T> T handleResponse(String url,HttpResponse response, Class<T> re
return entity != null ? converJson( entity, resultType) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
Expand Down Expand Up @@ -3317,8 +3333,12 @@ public String handleResponse(final HttpResponse response)
return entity != null ? EntityUtils.toString(entity) : null;
} else {
HttpEntity entity = response.getEntity();
if (entity != null )
throw new HttpProxyRequestException( new StringBuilder().append("Put request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("PUT Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("Put request url:").append(url).append(",Unexpected response status: " ).append( status).toString());
}
Expand Down
23 changes: 16 additions & 7 deletions src/org/frameworkset/spi/remote/http/HttpRequestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.frameworkset.spi.remote.http.proxy.HttpProxyRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,6 +40,7 @@
* @Date:2016-11-20 11:39:59
*/
public class HttpRequestUtil {
private static Logger logger = LoggerFactory.getLogger(HttpRequestProxy.class);
public static final String HTTP_GET = "get";
public static final String HTTP_POST = "post";
public static final String HTTP_DELETE = "delete";
Expand Down Expand Up @@ -1734,9 +1737,12 @@ public String handleResponse(final HttpResponse response)
// return EntityUtils.toString(entity);
// else
// throw new ClientProtocolException("Unexpected response status: " + status);
if (entity != null )
throw new HttpProxyRequestException( new StringBuilder().append("SendBody request url:").append(url)
.append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("SendBody Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("SendBody request url:").append(url)
.append(",Unexpected response status: " ).append( status).toString());
Expand All @@ -1746,7 +1752,7 @@ public String handleResponse(final HttpResponse response)
});

}

public static <T> T putBody(String poolname,String requestBody, String url, Map<String, String> headers,ContentType contentType, ResponseHandler<T> responseHandler) throws Exception {
HttpClient httpClient = null;
HttpPut httpPost = null;
Expand Down Expand Up @@ -1830,9 +1836,12 @@ public String handleResponse(final HttpResponse response)
// return EntityUtils.toString(entity);
// else
// throw new ClientProtocolException("Unexpected response status: " + status);
if (entity != null )
throw new HttpProxyRequestException( new StringBuilder().append("PutBody request url:").append(url)
.append(",").append(EntityUtils.toString(entity)).toString());
if (entity != null ) {
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder().append("Put Body Request url:").append(url).append(",status:").append(status).toString());
}
throw new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
throw new HttpProxyRequestException(new StringBuilder().append("PutBody request url:").append(url)
.append(",Unexpected response status: " ).append( status).toString());
Expand Down
12 changes: 10 additions & 2 deletions src/org/frameworkset/spi/remote/http/StatusResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.frameworkset.spi.remote.http.proxy.HttpProxyRequestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public abstract class StatusResponseHandler {
private static Logger _logger = LoggerFactory.getLogger(StatusResponseHandler.class);
protected int reponseStatus;
public int getReponseStatus() {
return reponseStatus;
Expand All @@ -27,8 +30,13 @@ public void setUrl(String url) {
this.url = url;
}
protected RuntimeException throwException(int status, HttpEntity entity) throws IOException {
if (entity != null )
return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",").append(EntityUtils.toString(entity)).toString());

if (entity != null ) {
if(_logger.isDebugEnabled()) {
_logger.debug(new StringBuilder().append("Request url:").append(url).append(",status:").append(status).toString());
}
return new HttpProxyRequestException(EntityUtils.toString(entity));
}
else
return new HttpProxyRequestException(new StringBuilder().append("Request url:").append(url).append(",Unexpected response status: ").append( status).toString());
}
Expand Down

0 comments on commit 9ce709e

Please sign in to comment.