0

我一直在尝试在我的 Web 服务上启用 fastinfoset 压缩。但是,我无法根据客户端的请求更改内容类型。至少,我认为这就是它不压缩的原因。

我尝试了很多不同的东西,但内容类型始终保持“text/xml”。我很确定它应该按照我现在设置的方式作为“应用程序/soap+fastinfoset”进行。我将 Axis2 作为独立运行,但我再次认为问题在于内容类型标题没有改变。

我知道选项本身是根据请求设置的,因为我能够将另一个选项从“UTF-8”更改为“UTF-16”,并且它显示在标题中。这是 TCPMonitor 的当前标头输出:

POST /axis2/services/AddressBookService HTTP/1.1

内容类型:文本/xml;字符集=UTF-16

SOAPAction:“瓮:anonRobustOp”

用户代理:Axis2

主机:127.0.0.1:1237

传输编码:分块

客户端代码如下所示。非常感谢任何帮助。

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());


    }

}
4

2 回答 2

2

将axis2.xml 文件作为JVM 参数传递为

-Daxis2.xml="location of axis2.xml" 

这里axis2.xml应该配置成FI(messageFormatters和messageBuilders)

于 2012-09-26T10:15:08.677 回答
-1

阅读“如何在 Axis2/Java 中启用快速信息集”。希望能帮助到你。

于 2010-06-23T08:47:45.913 回答