【问题标题】:Axis2 and fastinfoset - cannot get content-type to changeAxis2 和 fastinfoset - 无法更改内容类型
【发布时间】:2011-03-07 01:54:21
【问题描述】:

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

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

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

POST /axis2/services/AddressBookService HTTP/1.1

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

SOAPAction: "urn: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());


    }

}

【问题讨论】:

    标签: content-type axis2 options fastinfoset


    【解决方案1】:

    阅读“How to Enable Fast Infoset in Axis2/Java”。希望对您有所帮助。

    【讨论】:

    • 我一直使用该文档作为我的代码的基础。它不工作。我希望有一些更有洞察力的东西。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 2012-09-22
      • 2017-11-26
      相关资源
      最近更新 更多