2010-05-17 45 views
4

我得到的代碼看起來應該是正確的,基於我能找到的東西,但是這個被噴出的輸出並不表示它正在使用FastInfoset。我的理解是Accept應該表明它可以接受Fastinfoset,並且響應實際上會使用它,這意味着它不是text/xml作爲響應類型。任何想法我做錯了什麼?我已經和谷歌一起搜索了,而且我很難找到關於如何使用FastInfoset的更多細節。你如何在JAXWS中使用FastInfoset?

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 
    factory.getInInterceptors().add(new LoggingInInterceptor()); 
    factory.getOutInterceptors().add(new LoggingOutInterceptor()); 
    factory.setServiceClass(C360Server.class); 
    factory.setAddress("http://localhost:8501/cxfcontroller/cl_v5"); 
    C360Server client = (C360Server)factory.create(); 
    ((BindingProvider)client).getRequestContext().put(
     "com.sun.xml.ws.client.ContentNegotiation", "optimistic"); 

    C360Request requestTrans = new C360Request(); 
    ... code to fill in the request ... 
    C360Response response = client.findContacts(requestTrans); 

的記錄似乎並不表明FastInfoset是,即使嘗試:

INFO: Outbound Message 
--------------------------- 
ID: 1 
Address: http://localhost:8501/cxfcontroller/cl_v5 
Encoding: UTF-8 
Content-Type: text/xml 
Headers: {SOAPAction=[""], Authorization=[Basic cWFfc3VwZXI6cWFfc3VwZXI=], Accept=[*/*]} 
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:findContacts>...bunch of xml deleted for brevity...</ns1:findContacts></soap:Body></soap:Envelope> 
-------------------------------------- 
May 17, 2010 3:23:45 PM org.apache.cxf.interceptor.LoggingInInterceptor logging 
INFO: Inbound Message 
---------------------------- 
ID: 1 
Response-Code: 200 
Encoding: UTF-8 
Content-Type: text/xml; charset=utf-8 
Headers: {content-type=[text/xml; charset=utf-8], Content-Length=[611], Server=[Jetty(6.1.x)]} 
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:findContactsResponse>...bunch of xml spew deleted for brevity...</ns1:findContactsResponse></soap:Body></soap:Envelope> 
-------------------------------------- 

任何想法我做錯了嗎?即使服務器不支持FastInfoset,我仍然應該在請求中看到嘗試的協商,對吧?

回答

6

答案是我有關於如何啓用它的信息已過時。下面的工作在客戶端(可能服務器端,但我有一個啓用了處理它的Spring配置)。

  JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 
      // This enables FastInfoset as the communication protocol 
      factory.getInInterceptors().add(new FIStaxInInterceptor()); 
      factory.getOutInterceptors().add(new FIStaxOutInterceptor()); 
      ... other code to set username, location, etc. goes here. 
      client = (C360Server) factory.create(); 
0
//Enabling FastInfoset by configuring proxy 
// Enabling FI in pessimistic mode 
Map<String, Object> ctxt = ((BindingProvider)proxy).getRequestContext(); 
ctxt.put(JAXWSProperties.CONTENT_NEGOTIATION_PROPERTY, "pessimistic"); 

OR

使用系統屬性

-Dcom.sun.xml.ws.client.ContentNegotiation=pessimistic 
FastInfoset啓用