zoukankan      html  css  js  c++  java
  • 配置 cxf-rs spring bean 文件

    http://cxf.apache.org/schemas/jaxrs.xsd

    http://cxf.apache.org/docs/restful-services.html

    示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:jaxrs="http://cxf.apache.org/jaxrs"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:cxf="http://cxf.apache.org/core"
           
           xsi:schemaLocation="
               http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
               http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
                              ">
    <import resource="classpath:META-INF/cxf/cxf.xml" /> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /> <cxf:bus> <cxf:features> <cxf:logging /> </cxf:features> </cxf:bus> <jaxrs:server id="services" address="/"> <jaxrs:serviceBeans> <bean class="cn.zno.HelloWorld" /> </jaxrs:serviceBeans> <jaxrs:providers> <ref bean="jsonProvider" /> <ref bean="jaxbProvider" /> </jaxrs:providers> <jaxrs:extensionMappings> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </jaxrs:extensionMappings> <jaxrs:languageMappings> <entry key="en" value="en-gb" /> </jaxrs:languageMappings> </jaxrs:server> </beans>

    没有endpoint

    <xsd:element name="server">...</xsd:element>
    <xsd:element name="client">...</xsd:element>

    jaxrs:server

    <xsd:attributeGroup ref="cxf-beans:beanAttributes"/>
    <xsd:attribute name="address" type="xsd:string"/>
    <xsd:attribute name="bus" type="xsd:string"/>
    <xsd:attribute name="serviceClass" type="xsd:string"/>
    <xsd:attribute name="transportId" type="xsd:string"/>
    <xsd:attribute name="modelRef" type="xsd:string"/>
    <xsd:attribute name="bindingId" type="xsd:string"/>
    <xsd:attribute name="staticSubresourceResolution" type="xsd:boolean"/>
    <xsd:attribute name="beanNames" type="xsd:string"/>
    <xsd:attribute name="serviceName" type="xsd:QName"/>
    <xsd:attribute name="docLocation" type="xsd:string"/>
    <xsd:attribute name="publishedEndpointUrl" type="xsd:string"/>
    <xsd:attribute name="basePackages" type="xsd:string"/>
    <xsd:attribute name="serviceAnnotation" type="xsd:string"/>
    <xsd:attribute name="publish" type="xsd:boolean"/>
    <xsd:all>
    <xsd:element name="executor" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="features" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="binding" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="dataBinding" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="inFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="invoker" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="serviceFactories" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="outInterceptors" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="outFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="properties" type="beans:mapType" minOccurs="0"/>
    <xsd:element name="serviceBeans" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="modelBeans" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="model" type="model" minOccurs="0"/>
    <xsd:element name="providers" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="extensionMappings" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="languageMappings" type="xsd:anyType" minOccurs="0"/>
    <xsd:element name="schemaLocations" type="schemasType" minOccurs="0"/>
    <xsd:element name="resourceComparator" type="xsd:anyType" minOccurs="0"/>
    </xsd:all>

    开启日志

        <cxf:bus>
            <cxf:features>
                <cxf:logging />
            </cxf:features>
        </cxf:bus>

    增加后,请求时,增加如下日志:
    七月 30, 2015 2:32:26 下午 org.apache.cxf.interceptor.LoggingInInterceptor
    信息: Inbound Message
    ----------------------------
    ID: 1
    Address: http://localhost:8080/cxf-jaxrs-service/hello/jsonBean
    Encoding: ISO-8859-1
    Http-Method: POST
    Content-Type: application/json
    Headers: {Accept=[application/json], cache-control=[no-cache], connection=[keep-alive], Content-Length=[28], content-type=[application/json], host=[localhost:8080], pragma=[no-cache], user-agent=[Apache CXF 3.1.1]}
    Payload: {"val2":null,"val1":"Maple"}
    --------------------------------------
    七月 30, 2015 2:32:26 下午 org.apache.cxf.interceptor.LoggingOutInterceptor
    信息: Outbound Message
    ---------------------------
    ID: 1
    Response-Code: 200
    Content-Type: application/json
    Headers: {Content-Type=[application/json], Date=[Thu, 30 Jul 2015 06:32:26 GMT]}
    Payload: {"val2":"Maple","val1":"Maple"}
    --------------------------------------

    效果等同于:

    <bean id="inInterceptors" class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
    <bean id="outInterceptors" class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>

    [...]

    <jaxrs:inInterceptors>
      <ref bean="inInterceptors" />
    </jaxrs:inInterceptors>
    <jaxrs:outInterceptors>
      <ref bean="outInterceptors" />
    </jaxrs:outInterceptors>

    权限验证

    http://cxf.apache.org/docs/security.html

  • 相关阅读:
    中文字体在CSS中的表达方式
    图片上传+预览+剪切解决方案我们到底能走多远系列(20)
    C# — 饼形图之插入介绍文字
    CSS 网页布局中文排版的9则技巧
    Android UI 优化 使用<include/>和 <merge />标签
    SQLite 的日期时间函数
    GSM、GPRS、EDGE、2G、3G与WAP的关系
    WPF中的Style(风格,样式)
    给力分享新的ORM => Dapper
    WCF开发框架形成之旅如何实现X509证书加密
  • 原文地址:https://www.cnblogs.com/zno2/p/4689362.html
Copyright © 2011-2022 走看看