代码之家  ›  专栏  ›  技术社区  ›  Chris Kessel

你如何在jaxws中使用fastnfoset?

  •  4
  • Chris Kessel  · 技术社区  · 16 年前

    我有一些代码看起来应该是正确的,基于我能找到的,但喷码输出并不表示它使用的是fastnfoset。我的理解是,accept应该表示它可以接受fastnfoset,响应实际上会使用它,这意味着它不是作为响应类型的text/xml。知道我做错了什么吗?我搜索过谷歌,很难找到关于如何使用fastnfoset的详细信息。

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

    日志记录似乎并不表示尝试了fastnfoset,尽管:

    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>
    --------------------------------------
    

    知道我做错了什么吗?即使服务器不支持fastnfoset,我仍然应该在请求中看到尝试的协商,对吗?

    2 回复  |  直到 13 年前
        1
  •  6
  •   Chris Kessel    15 年前

    答案是关于如何启用它的信息已经过时了。下面的工作在客户机端(可能是服务器端,但在这里我启用了一个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();
    
        2
  •  0
  •   krock    13 年前
    //Enabling FastInfoset by configuring proxy 
    // Enabling FI in pessimistic mode
    Map<String, Object> ctxt = ((BindingProvider)proxy).getRequestContext();
    ctxt.put(JAXWSProperties.CONTENT_NEGOTIATION_PROPERTY, "pessimistic");
    

    使用系统属性启用FastInfo集

    -Dcom.sun.xml.ws.client.ContentNegotiation=pessimistic