Tag: jersey

如何在jersey WriterInterceptor实现中获取@interface参数

我有一个界面,例如 @NameBinding @Retention(RetentionPolicy.RUNTIME) public @interface AutoLogged { boolean query() default false; } 如何在拦截器实现中获取query参数? @Provider @AutoLogged public class AutoLoggedInterceptor implements WriterInterceptor { @Context private ResourceInfo resourceInfo; @Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { try { final String methodName = this.resourceInfo.getResourceMethod().getName(); BasicAutoLoggedProducer.makeCall(methodName); } catch (final Exception e) { e.printStackTrace(System.err); } finally { context.proceed(); } […]

方言错误信息流口水

我在Tomcat 7中部署了一个webApp。我正在使用Drools。 现在当我连续运行时,Drools抛出运行时exception。 我也在类路径中添加了“core-3.4.2.v_883_R34x.jar”。 请找到错误日志 – Some errors exists in packageBuilder [DialectError message=’Unable to wire compiled classes, probably related to compilation failures:null’] Some errors exists in packageBuilder [DialectError message=’Unable to wire compiled classes, probably related to compilation failures:null’] Nov 23, 2013 11:31:19 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, […]

Jersey服务器日志记录/ w Logback

我如何让Jersey LoggingFilter使用logback? 我看到这篇文章: 如何在服务器上获取泽西日志? 但遗憾的是它依赖于java.util.Logger 。 在web.xml配置方面,我不是非常精通,所以我不知道如何提供init-param不同的记录器。 请注意,我使用Spring 3进行dependency injection,但是使用代码为每个类创建记录器: Logger logger = LoggerFactory.getLogger(MyClass.class); 希望这是足够的信息。 如果没有,请告诉我。 我的Web容器是Tomcat 7.0.12。

使用jackson将json反序列化为java – 特殊字符问题

我使用jackson(泽西和docker)作为我的REST网络服务 – 一切进展顺利。 但是我要求在json post请求中的一个名称值对中包含一个特殊字符。 即json请求(在post正文中) – { “id”: “1”, “print-color” : “red” } //“print-color”中的“ – ”给出了问题。 现在在我对应的这个对象Item.java类的java bean中,我不能创建一个名为print-color的属性(因为不允许使用“ – ”)。 如何在映射中处理它? 谢谢。

通过查询参数选择Jersey方法

我需要实现一个使用第一个查询参数来识别操作的web服务,即客户端调用类似于: http://localhost:8080/ws/operation?info或http://localhost:8080/ws/operation?create&name=something 。 似乎我无法区分使用@Path注释的方法,因为区别特征在于查询参数。 以下示例也是抛出exception: package com.example.ws; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; @Path(“/operation”) public class Operation { @GET public String info(@QueryParam(“info”) String info) { return “info”; } @GET public String create(@QueryParam(“create”) String create) { return “create”; } } 有没有办法根据查询参数指定要使用的方法? 或者我真的必须定义一个方法并在那个方法中检查是否设置了某些查询参数?

Jersey REST Client:发布MultiPart数据

我正在尝试编写一个Jersey客户端应用程序,它可以将多部分表单数据发布到Restful Jersey服务。 我需要发布带有数据的CSV文件和带有元数据的JSON。 我正在使用Jersey客户端1.18.3。 这是我的代码(一些名称已被更改为公司保密)… Client client = Client.create(); WebResource webResource = client.resource(“http://localhost:8080/mariam/service/playWithDad”); FileDataBodyPart filePart = new FileDataBodyPart(“file”, new File(“C:/Users/Admin/Desktop/input/games.csv”)); String playWithDadMetaJson = “{\n” + ” \”sandboxIndicator\”: true,\n” + ” \”skipBadLines\”: false,\n” + ” \”fileSeparator\”: \”COMMA\”,\n” + ” \”blockSize\”: false,\n” + ” \”gameUUID\”: \”43a004c9-2130-4e75-8fd4-e5fccae31840\”,\n” + ” \”useFriends\”: \”false\”\n” + “}\n” + “”; MultiPart multipartEntity = […]

Jersey写了我的mysql时间戳为2011-09-28T21:48:25Z如何用Java格式化它?

我有一个mysql后端,它有一个时间戳字段,自动设置为currenttimestamp,如此( date_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP)。 在将值读为Date后, Jersey发送一个xml,其中时间戳显示为 2011-09-28T21:48:25Z 请不要做太多的背景故事:我无法改变从泽西岛获得的东西。 现在我的问题是这样的:我如何从xml解析2011-09-28T21:48:25Z作为Java理解的日期? 谢谢。

@Context注入无效在Jersey ContainerRequestFilter(Dropwizard)

@Context注入适用于类,但不能使它与Objects一起使用。 ContainerRequestFilter中的httpServletRequest生成空指针。 Dropwizard版本: – 1.1.0 ContainerRequestFilter 公共类ApplicationIPAuthFilter实现ContainerRequestFilter {private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationIPAuthFilter.class); 私人HerculesRestAccessor restAccessor; private String applicationName; @Context private HttpServletRequest httpServletRequest; public ApplicationIPAuthFilter(){} public ApplicationIPAuthFilter(HerculesRestAccessor accessor,String applicationName){restAccessor = accessor; this.applicationName = applicationName; } @Override public void filter(ContainerRequestContext requestContext)throws IOException {//需要remote Ip String remoteIp = this.httpServletRequest.getRemoteAddr(); ….}} DynamicFeature @Provider 公共类ApplicationIPAuthFeature实现DynamicFeature { 私人决赛HerculesRestAccessor访问者; private final […]

Jersey beanvalidationParameterNameProvider

我正在阅读关于beanvalidation的Jersey文档。 ParameterNameProvider示例显示如何为方法定义参数名称。 但是,实现看起来必须对每个显然无法扩展的方法进行。 这个例子基本没用。 有更聪明的方法吗? Jersey不能从@QueryParam或@PathParam注释中推断出这个名字吗?

Jersey:是否可以在@DefaultValue()注释中指定多个值

我正在使用Java API for RESTful Web Services(JAX-RS) ,并在Jersey实现的JAX-RS中遇到@DefaultValue注释。 这是代码片段 @GET @Path(“/query”) public Response getUserWithQueryParams( @DefaultValue(“defaultId”) @QueryParam(“from”)String from, @DefaultValue(“defaultName”) @QueryParam(“to”) String to, @DefaultValue(“mobileNo”)@QueryParam(“orderBy”) List orderBy ){ 我的第三个参数是List ,它可以有多个值 例如,我明确传递参数 users/query?from=100&to=200&orderBy=age&orderBy=name 现在我的第三个参数有值[age,name] , 但如果我没有传递任何显式参数,那么有没有办法设置多个默认值 。 ?