English 中文(简体)
如何在基于 JAX-RS 的 CXF 服务处的 ExcuseHandler 中获取参数名称和值
原标题:How to get parameters name and value in RequestHandler of JAX-RS based Service in CXF

我正在在 CXF 中创建基于 JAX-RS 的网络服务, 我想将参数传送到 < code> requestHandler 中注册为 < code@lt; jaxrs: superr> 的方法中 。

我要处理器中的参数名称和相应值, 这是我的代码:

public class SampleRequestHandler implements RequestHandler {

@Override
public Response handleRequest(Message arg0, ClassResourceInfo arg1) {
    OperationResourceInfo resourceInfo = arg0.getExchange().get(OperationResourceInfo.class);
    String name = resourceInfo.getMethodToInvoke().getName();

    return null;
    }
}

我的JAX-RS服务:

@Service("bookService")
@Path("/bookstore")
public class BookStore {

    @POST
    @Path("/books")
    @Produces({ "application/xml" })
    @Consumes({ "application/xml" })
    public Book addBook(Book book) {
        return book;
    }

}

和我的beans.xml ,我在那里登记了处理者和勤奋的服务:

<context:component-scan base-package="com.tutorial.cxf.jaxrs.service"/>

<bean id="sampleHandler" class="com.tutorial.cxf.jaxrs.interceptors.SampleRequestHandler"/>
<jaxrs:server id="restContainer" address="/">
    <jaxrs:serviceBeans>
        <ref bean="bookService"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
        <ref bean="sampleHandler"/>
    </jaxrs:providers>
</jaxrs:server>

谁已经处理过这个案子了?

问题回答

我也有同样的问题 试图采取的方法与:

List<Parameter> params = ori.getParameters();

它只返回参数 s 名称( 方法中声明的名称), 但不返回值 。

官方网站>CXF文件 只略微说明了这一点,但正如所解释的那样,你总是可以接受信息的QUERY_string值并加以分析。

你可以在你的控制器/过滤器里做这种事情:

String queryString = (String) arg0.get(Message.QUERY_STRING);
MultivaluedMap<String, String> queryMap = JAXRSUtils.getStructuredParams(queryString, "&", false, false);

并在调阅查询地图收藏之后。 地图将包含您的所有查询参数, 即使那些在您的书库Store 类的“ 休息方法” 中未申报的参数 。





相关问题
Allow RESTful DELETE method in asp.net mvc?

im currently setting up asp.net to accept DELETE http verb in the application. However, when i send "DELETE /posts/delete/1" i always get a 405 Method not allow error. I tried to take a look at ...

Most appropriate API for URL shortening service

I ve just finished an online service for shortening URLs (in php5 with Zend Framework); you can enter an URL and you get an short URL (like tinyurl and such sites). I m thinking about the API for ...

Use HTTPClient or HttpUrlConnection? [closed]

We re implementing a REST client on JRE 1.4. Seems two good options for a client REST framework are HttpClient and HttpUrlConnection. Is there a reason to use HttpClient over the JRE s ...

Why can t I find the truststore for an SSL handshake?

I m using the Spring RESTTemplate on the client side to make calls to a REST endpoint. The client in this case is a Spring app and Tomcat is the servlet container. I m running into issues making a ...

Which Http redirects status code to use?

friendfeed.com uses 302. bit.ly uses 301. I had decided to use 303. Do they behave differently in terms of support by browsers ?

Three Step Buyonline The RESTful way

We are re-developing our buyonline functionality and we are doing it the RESTful way. The process is a three step one and the customer is asked to enter data at each step. Let s say the three URL s ...

热门标签