Tag: jersey

泽西岛2.0:创造重复的工作

在我们的REST服务中,我们希望实现一个每10秒检查一次的工作。 所以我们认为我们可以使用Quartz制作一个涵盖这个的Job。 但问题是,我们需要注入一个单例,因为它在作业中使用,并且作业似乎不在我们的服务上下文中,因此注入的类始终为null(NullPointerException)。 那么有没有另一种可能的解决方案来实现这样的工作而不使用Quartz? 我们已经尝试编写自己的JobFactory来连接作业和BeanManager,但它根本没用。 这是无法正常工作的代码: @Stateless public class GCEStatusJob implements Job, Serializable{ private Logger log = LoggerFactory.getLogger(GCEStatusJob.class); @Inject SharedMemory sharedMemory; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { GoogleComputeEngineFactory googleComputeEngineFactory = new GoogleComputeEngineFactory(); List heartbeatList = new ArrayList(sharedMemory.getAllHeartbeats()); List gceList = googleComputeEngineFactory.listGCEs(); List ipAddressList = gceList.stream().map(GCE::getIp).collect(Collectors.toList()); for(HeartbeatModel heartbeat : heartbeatList){ if(ipAddressList.contains(heartbeat.getIpAddress())){ long systemTime = […]

REST @FormParam为null

我有以下从浏览器传递到服务器 Status Code:204 No Content Request Method:POST Content-Type:application/x-www-form-urlencoded Form Data json:{“clientName”:”PACK”,”status”:”success”,”message”:”successful!”} 并在jsp代码中 var loginData = { clientName: cList, status: “success”, message: “successful!” }; $.ajax({ url: subUrl, type: ‘POST’, contentType : “application/x-www-form-urlencoded”, data: { json: JSON.stringify(loginData) }, success: function (data) { handleLoginResult(data); } }); 在Java代码中我有 @POST public Object persistResetPasswordLogs(@FormParam(“clientName”) String clientName) { try { log.info(“in rest […]

MultivaluedMapexception

我试图运行一个大气样本,但当我运行Restful Web服务时它给我跟随错误,我想因为下面的代码它生成错误,我不知道有什么问题我使用glassfish 3和Netbeans IDE,这是示例链接 @Broadcast({XSSHtmlFilter.class, JsonpFilter.class}) @Consumes(“application/x-www-form-urlencoded”) @POST public String publishMessage(MultivaluedMap form) { String action = form.getFirst(“action”); String name = form.getFirst(“name”); if (“login”.equals(action)) { return (“System Message” + “__” + name + ” has joined.”); } else if (“post”.equals(action)) { return name + “__” + form.getFirst(“message”); } else { throw new WebApplicationException(422); } } INFO: […]

服务器与Jersey发送事件:客户端丢弃后,EventOutput未关闭

我正在使用jersey来实施SSE场景。 服务器保持连接活动。 并定期将数据推送给客户。 在我的方案中,存在连接限制,只有一定数量的客户端可以同时订阅服务器。 因此,当新客户端尝试订阅时,我会进行检查(EventOutput.isClosed)以查看是否有任何旧连接不再处于活动状态,因此可以为新连接腾出空间。 但EventOutput.isClosed的结果始终为false,除非客户端显式调用EventSource的close。 这意味着如果客户端意外掉线(断电或互联网切断),它仍然会占用连接,新客户端无法订阅。 有没有解决这个问题?

Jersey POJOMappingFeature将null转换为空字符串?

我正在使用Jersey 1.18并启用了POJOMappingFeature。 我希望所有传入和传出的JSON值都从null转换为空字符串。 如何配置映射? 我搜索过网页但无法找到我要找的内容。 从我的web.xml: Jersey REST Service com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.abc.restControllers com.sun.jersey.api.json.POJOMappingFeature true 1 以及控制器的一个例子: package com.abc.restControllers; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.abc.restModals.Place.Place_descInfo_Request; import com.abc.restModals.Place.Place_descInfo_Response; @Path(“/place”) public class PlaceController { @POST @Path(“/place_descInfo”) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Place_descInfo_Response place_descInfo(Place_descInfo_Request req) { return new Place_descInfo_Response(req); } } // End class

使用“multipart / form-data”进行文件上传服务时出现严重错误 – Apache Jersey

我收到此错误: SEVERE: Resource methods utilizing @FormParam and consuming “multipart/form-data” are no longer supported. See @FormDataParam 当我为基于Apache Jersey的Rest Web服务完成客户端Web访问时,我现在正在工作: @POST @Path(“upload”) @Consumes(“multipart/form-data”) @Produces(“text/plain”) public String uploadFile(@FormParam(“file”) File file, @FormParam(“file”) FormDataContentDisposition fileDetail) { String fileLocation = “/files/” + fileDetail.getFileName(); System.out.println(“File location: ” + fileLocation); // Load image try { byte[] imageBytes = loadImage(fileLocation); MongoConnection conn = MongoUtil.getConnection(); […]

使用@Produces用于不同的方法

我正在学习Jersey webservices并且遇到了@Produces的用法,所以为了理解它,我写了一个这样的小程序: @Path(“users/{username: [a-zA-Z][a-zA-Z_0-9]*}”) public class UserResource { @GET @Produces(“text/plain”) public String getUser(@PathParam(“username”) String userName) { return “Hello ” + userName; } @GET @Produces({“application/xml”, “application/json”}) public String doGetAsXmlOrJson(@PathParam(“username”) String userName) { return “Hello World”; } } 当我将请求作为http://localhost:9998/users/Java传递,并且标题为“Accept:application / json”时,我希望输出为Hello World 。 但不是这样,我将它作为Hello Java 。 我正在使用Chrome浏览器的Postman客户端对此进行测试。 现在如果我删除上面程序中的getUser方法,那么我得到输出为Hello World 。 你能否告诉我为什么即使我设置了Accept标头,请求也不会转到我的doGetAsXmlOrJson方法? 更新:添加更多详细信息 – 使用Jersey文档中提到的以下代码部署该程序: import java.io.IOException; import […]

使用Jersey 1.x自定义注释注入

我正在使用jersey1.9.1。 我有rest方法,如下所示,Authorization标头包含编码凭据,如用户名和密码,并在方法中解析并映射本地值。 @PUT @Path(SystemConstants.REST_MESSAGE_SENDSMS) @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON}) public Response sendSms(@HeaderParam(“Authorization”) String authorization, String param) { String[] credentials = ImosUtils.getUserCredentials(authorization); String username = credentials[0]; String password = credentials[1]; } 我试图设计一种自动生成此过程的方法,而无需在每个方法中编写相同的解析代码。 我的意思是我想知道是否编写了一个特殊的注释,如HeaderParamExtended用于解析此凭据。 我使用泽西1.9.1版作为restapi。 我必须在那个生命周期中编辑一个类? @PUT @Path(SystemConstants.REST_MESSAGE_SENDSMS) @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON}) public Response sendSms(@HeaderParamExtended(“Authorization”,”username”) String username, @HeaderParamExtended(“Authorization”,”password”) String password, , String param) { }

如何使用jackson序列化声明性链接(泽西)

我在我的项目中使用声明性链接。 我的jackson映射器配置是 final ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); 因为我已禁用任何类型的自动检测,注入的链接就像 @InjectLinks({ @InjectLink(rel = “bookmark”, resource = ConnectionsResource.class, style = Style.ABSOLUTE_PATH) }) @JsonProperty(“links”) Link[] links; 被序列化为一个空的JSON对象(因为“Link”中的所有字段都没有用@JsonProperty注释)。 如何在不更改全局映射器配置的情况下为字段rel和href启用链接的序列化?

更新Tomcat LIb文件夹

我有一个使用Jersey插件开发并部署在Tomact 7上的应用程序。 我必须将项目中使用的所有jar导出到Tomact的lib /文件夹..但我不想..是否可以部署我的应用程序而不将jar导出到Tomcat lib文件夹。 如果是,那么如何? https://t1.ap01.aws.af.cm/rest/person 这是我的应用程序链接,如果未导出lib /,则会出现以下错误: HTTP Status 404 – Servlet Jersey REST Service is not available type Status report message Servlet Jersey REST Service is not available description The requested resource (Servlet Jersey REST Service is not available) is not available. Apache Tomcat/6.0.35