Axis2 和 fastinfoset - 无法更改内容类型
我一直在尝试在我的网络服务上启用 fastinfoset 压缩。但是,我在根据客户端的请求更改内容类型时遇到问题。至少,我认为这就是它不压缩的原因。
我尝试了很多不同的方法,但内容类型始终保持“text/xml”。我很确定它应该按照我现在设置的方式作为“application/soap+fastinfoset”进行。我将 Axis2 作为独立运行,但我再次认为问题是内容类型标头没有改变。
我知道选项本身是根据请求设置的,因为我能够将另一个选项从“UTF-8”更改为“UTF-16”,并且它显示在标头中。以下是 TCPMonitor 的当前标头输出:
POST /axis2/services/AddressBookService HTTP/1.1
Content-Type: text/xml; charset=UTF-16
SOAPAction: "urn:anonRobustOp"
User-Agent: Axis2
Host: 127.0.0.1:1237
Transfer-Encoding: chunked
客户端代码如下所示。非常感谢任何帮助。
package sample.addressbook.rpcclient;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.Constants;
import sample.addressbook.entry.Entry;
public class AddressBookRPCClient {
public static void main(String[] args1) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setProperty(Constants.Configuration.MESSAGE_TYPE,
"application/soap+fastinfoset");
options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-16");
EndpointReference targetEPR = new EndpointReference(
"http://127.0.0.1:1237/axis2/services/AddressBookService");
options.setTo(targetEPR);
// /////////////////////////////////////////////////////////////////////
serviceClient.setOptions(options);
/*
* Creates an Entry and stores it in the AddressBook.
*/
// QName of the target method
QName opAddEntry = new QName("http://service.addressbook.sample", "addEntry");
/*
* Constructing a new Entry
*/
Entry entry = new Entry();
entry.setName("Abby Cadabby");
entry.setStreet("Sesame Street");
entry.setCity("Sesame City");
entry.setState("Sesame State");
entry.setPostalCode("11111111111111111111111111111111111111111111111111111111111111111111111111111");
// Constructing the arguments array for the method invocation
Object[] opAddEntryArgs = new Object[] { entry };
// Invoking the method
serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
/*
* Fetching an Entry from the Address book
*/
// QName of the method to invoke
QName opFindEntry = new QName("http://service.addressbook.sample", "findEntry");
//
String name = "Abby Cadabby";
Object[] opFindEntryArgs = new Object[] { name };
Class[] returnTypes = new Class[] { Entry.class };
Object[] response = serviceClient.invokeBlocking(opFindEntry,
opFindEntryArgs, returnTypes);
Entry result = (Entry) response[0];
if (result == null) {
System.out.println("No entry found for " + name);
return;
}
System.out.println("Name :" + result.getName());
System.out.println("Street :" + result.getStreet());
System.out.println("City :" + result.getCity());
System.out.println("State :" + result.getState());
System.out.println("Postal Code :" + result.getPostalCode());
}
}
I've been trying to enable fastinfoset compression on my web services. However, I'm having a problem getting the content-type to change on the request from the client. At least, I think that's why it's not compressing.
I've tried a lot of different things, but the content-type always remains "text/xml". I'm pretty sure that it's supposed go through as "application/soap+fastinfoset" the way I have it set up now. I'm running Axis2 as a standalone, but again I think the problem is that the content type header isn't changing.
I know the options themselves are getting set on the request because I was able to change another option from "UTF-8" to "UTF-16", and it showed up in the header. Here's the current header output from TCPMonitor:
POST /axis2/services/AddressBookService HTTP/1.1
Content-Type: text/xml; charset=UTF-16
SOAPAction: "urn:anonRobustOp"
User-Agent: Axis2
Host: 127.0.0.1:1237
Transfer-Encoding: chunked
The client code is shown below. Any help much appreciated.
package sample.addressbook.rpcclient;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.Constants;
import sample.addressbook.entry.Entry;
public class AddressBookRPCClient {
public static void main(String[] args1) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
options.setProperty(Constants.Configuration.MESSAGE_TYPE,
"application/soap+fastinfoset");
options.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-16");
EndpointReference targetEPR = new EndpointReference(
"http://127.0.0.1:1237/axis2/services/AddressBookService");
options.setTo(targetEPR);
// /////////////////////////////////////////////////////////////////////
serviceClient.setOptions(options);
/*
* Creates an Entry and stores it in the AddressBook.
*/
// QName of the target method
QName opAddEntry = new QName("http://service.addressbook.sample", "addEntry");
/*
* Constructing a new Entry
*/
Entry entry = new Entry();
entry.setName("Abby Cadabby");
entry.setStreet("Sesame Street");
entry.setCity("Sesame City");
entry.setState("Sesame State");
entry.setPostalCode("11111111111111111111111111111111111111111111111111111111111111111111111111111");
// Constructing the arguments array for the method invocation
Object[] opAddEntryArgs = new Object[] { entry };
// Invoking the method
serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
/*
* Fetching an Entry from the Address book
*/
// QName of the method to invoke
QName opFindEntry = new QName("http://service.addressbook.sample", "findEntry");
//
String name = "Abby Cadabby";
Object[] opFindEntryArgs = new Object[] { name };
Class[] returnTypes = new Class[] { Entry.class };
Object[] response = serviceClient.invokeBlocking(opFindEntry,
opFindEntryArgs, returnTypes);
Entry result = (Entry) response[0];
if (result == null) {
System.out.println("No entry found for " + name);
return;
}
System.out.println("Name :" + result.getName());
System.out.println("Street :" + result.getStreet());
System.out.println("City :" + result.getCity());
System.out.println("State :" + result.getState());
System.out.println("Postal Code :" + result.getPostalCode());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 axis2.xml 文件作为 JVM 参数传递,如下所示
这里 axis2.xml 应配置为 FI(messageFormatters 和 messageBuilders)
Pass axis2.xml file as a JVM argument as
Here axis2.xml should be configured to FI (messageFormatters and messageBuilders)
请阅读“如何在 Axis2/Java 中启用快速信息集”。希望有帮助。
Read "How to Enable Fast Infoset in Axis2/Java". Hope it helps.