jersey

Publishing Jersey service instance to Grizzly

元气小坏坏 提交于 2019-12-11 17:34:20
问题 I can publish a jersey service to grizzly by doing the following final String baseUri = "http://localhost:51000"; final Map<String, String> initParams = new HashMap<String, String>(); initParams.put("com.sun.jersey.config.property.packages", "my.rest.service"); SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams); So the specified package will be scanned for any service classes annotated with @Path , and they will be initialized. My question is, is there any

Reading a resource file from a servlet

纵然是瞬间 提交于 2019-12-11 17:19:14
问题 I want to read a text file from a servlet which is made using Jersey and built using Gradle. The server is Tomcat 9. My file structure: project + src + package + App.java + res + file.txt My build.gradle : apply plugin: "java" apply plugin: "war" project.webAppDirName = "WebContent" sourceSets { main { java { srcDirs = ["src"] } resources { srcDirs = ["res"] } } } repositories { mavenCentral() } dependencies { compile "org.glassfish.jersey.containers:jersey-container-servlet:2.25.1" } war {

Http 204 error in REST web service (Jersey)

十年热恋 提交于 2019-12-11 17:17:44
问题 I am using Jersey/Java to develop my REST services. I need to return an XML representation for my CarStore : @XmlRootElement public class CarStore { private List<Car> cars; public List<Car> getCars() { return cars; } public void setCars(List<Car> cars) { this.cars = cars; } Here is my Car object : @XmlRootElement > public class Car { private String carName; private Specs carSpecs; private Category carCategory; public String getCarName() { return carName; } public void setCarName(String

Parent/child model for DTO

只愿长相守 提交于 2019-12-11 17:17:25
问题 I am not sure if this situation would more be related to generics than DTOs , but here it goes: I have a DTO that represents a Person . A Person can have as children other Person (s) or just ResourceLink to those Person (s). This means that the child can be of either of the 2 types: Person (the DTO) or the ResourceLink . What type it would be, is determined through a queryParam and consequently logically through the flow follwed. I want to represent them using just ONE collection object and

How to parse request parameter (query and path param) and request body in same POJO in REST API

五迷三道 提交于 2019-12-11 16:37:30
问题 I have a rest API (PUT verb) which accepts both request body and path params: Ex: curl --data {a:1, b:2} -X PUT "https://example.com/users/{username}/address/{addressname}" I am trying to fetch both request body and path param in one POJO Response myAPI(@BeanParam Users user){ system.out.println(user.username); system.out.println(user.a); Users class public class Users{ @PathParam(username) private String userName; ...... private String a; ...... } But I am getting value of user.a as null.

Cache memory not saving values in cache when running the project

牧云@^-^@ 提交于 2019-12-11 16:12:33
问题 I am implementing cache system in maven project.I am not using spring or any framework.The concept is to : 1.At first user will hit the API and Check whether the data is available in cache or not. 2.If cache is empty ,call the database and put values in cache and send them back. 3.If cache is not empty, then return the values from cache. So,for proper organization,I used the Java caching System(JCS) library,which I took reference from: https://www.javaworld.com/article/2077936/open-source

Marshalling an empty collection to json using jersey

吃可爱长大的小学妹 提交于 2019-12-11 16:11:45
问题 I have a strange issue marshalling an empty object collection to json using jersey with the jaxb based json support. My object looks like ... @XmlWrapper(name = "stuff") @XmlElement(name = "s") private List<Foo> foos; ... Marshaling this to json produces the expected results ... stuff: [{ "s": ... }, { "s": ... }] ... except when the list is empty. I would expect to see ... stuff: [] ... but I see ... stuff: [null] ... instead. Any idea what's wrong? The problem seems to be related to the

Authentication in a client application for REST services

☆樱花仙子☆ 提交于 2019-12-11 15:55:46
问题 Firstly, I'm going to explain my objective: I developed some REST services using Jersey, that were automatically generated from my MySQL DataBase. In that DataBase I have a Login table, that have the information of who can access the REST services. With this Login table I've allready implemented Basic-Authentication for my Jersey REST services, and that's working. When I go to the REST services mainpage, I have to put the correct login and password, and then I can access all information of

Why instance variable inside Custom Exception Mapper has to be static?

孤人 提交于 2019-12-11 15:13:04
问题 I have implemented a custom exception mapper in order to throw the bad request in my application. Here's the code: CustomFilterBadRequest: package com.test.exceptions; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import java.util.Date; public class CustomFilterBadRequest extends Exception implements ExceptionMapper<CustomFilterBadRequest> { private String uriInfo; public CustomFilterBadRequest() { super("Invalid Request. Please

Optional path segment in Jersey JAX-RS

可紊 提交于 2019-12-11 14:12:35
问题 I've searched for hours on this and haven't quite got it right. An API on a project I'm working on is not versioned ( /controller/blah ), so we want to introduce versioning. For example, we have a class with @Path("/controller") associated to it. Naturally to avoid API breakage, this now has to support either / or /v1/ , so the following would be valid: /controller/blah /v1/controller/blah I feel there must be an easy solution to this that I am missing? Thanks in advance! 回答1: I would use a