在JBOSS Appserver中托管Axis2 JSON Web服务,并在连接器中配置响应压缩(在server.xml文件中)。由Java客户端测试服务并接收处于压缩(GZIP)模式的响应(通过eclipse中的TCP / IP监视器监视)。
现在问题是,当我从jQuery客户端调用相同的Web服务时,响应不处于压缩模式并且接收到正常响应而不是压缩(GZIP)模式。
低于JBOSS中的配置。
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
compression="on" compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/css,text/javascript,application/x-javascript,application/javascript,application/json;charset=UTF-8,image/svg+xml,text/json,gzip"/>
以下是jQuery客户端
<title>Calling Web Service from jQuery</title>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">
if (!window.console) console = {log: function() {}};
$(document).ready(function () {
jQuery.support.cors = true;
$("#btnCallWebService").click(function (event) {
var start = new Date().getTime();
var wsUrl = "http://10.191.54.97:8080/axis2/services/TestCompression?wsdl";
var soapRequest ="<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><ns1:Compression xmlns:ns1=\"http://www.example.org/TestCompression/\"><CompressionReq>test</CompressionReq></ns1:Compression></soapenv:Body></soapenv:Envelope>";
$.ajax({
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "json",
headers: { "Accept-Encoding" : "gzip" },
data: soapRequest,
success: processSuccess,
error: processError
});
});
});
function processSuccess (data) {
console.log(data);
var strdata = JSON.stringify(data);
$('#response').html(strdata);
}
function processError(data, status, req) {
alert('iam failure')
alert(req.responseText + " " + status);
}
</script>
以下来自Fiddler的回复标题,
HTTP/1.1 200 OK
Via: 1.1 RSI-CHE-TMG01
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Transfer-Encoding: chunked
Date: Wed, 09 Apr 2014 08:42:36 GMT
Content-Type: application/json;charset=UTF-8
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181439)/JBossWeb-2.0
请你帮我解决这个问题..
谢谢。
答案 0 :(得分:0)
最后我从下面的帖子中得到了解决方案,
Using Fiddler to check IIS Compression
<强>解决方案:强>
我刚在浏览器中禁用了互联网代理详情。触发了服务,现在我可以看到fiddler中的压缩响应。
感谢。