Axis2 和 fastinfoset - 无法更改内容类型

发布于 2024-09-06 19:27:30 字数 3459 浏览 4 评论 0原文

我一直在尝试在我的网络服务上启用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听闻余生 2024-09-13 19:27:30

将 axis2.xml 文件作为 JVM 参数传递,如下所示

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

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

Pass axis2.xml file as a JVM argument as

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

Here axis2.xml should be configured to FI (messageFormatters and messageBuilders)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文