2010-06-22 18 views
0

我一直在嘗試在我的Web服務上啓用fastinfoset壓縮。不過,我在獲取客戶端請求中的內容類型時遇到問題。至少,我認爲這就是爲什麼它不是壓縮。Axis2和fastinfoset - 無法獲取內容類型

我已經嘗試了很多不同的東西,但內容類型始終保持爲「text/xml」。我很確定,它應該像我現在設置的「application/soap + fastinfoset」一樣。我將Axis2作爲獨立版運行,但我認爲問題在於內容類型標題未更改。

我知道這些選項本身正在設置請求,因爲我能夠將另一個選項從「UTF-8」更改爲「UTF-16」,並且它顯示在標題中。下面是從TCPMonitor中的電流輸出頭:

POST/Axis2的/服務/ AddressBookService HTTP/1.1

內容類型:文本/ XML的;字符集= UTF-16

的SOAPAction: 「甕:anonRobustOp」

的User-Agent: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()); 


    } 

} 

回答

-1

閱讀「How to Enable Fast Infoset in Axis2/Java」。希望能幫助到你。

+0

我已經使用該文件作爲依據是我的碼。它不工作。我希望有更多的洞察力。 – 2010-06-23 18:13:43

2

通axis2.xml文件作爲JVM參數作爲

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

這裏axis2.xml應配置FI(messageFormatters和messageBuilders)