jersey

Dependency injection into ResourceFilter not working?

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:56:31
问题 I have a bunch of JAX-RS resources that provide an API for a new WebService. In order to understand what's happening, I'd like to store information about each request in a data warehouse. In my mind, this is a perfect example for a cross-cutting concern, which could be implemented by a ResourceFilter , right? So I built a DataWarehouseService which is supposed to store stuff in the DB: @Stateless @LocalBean public class DataWarehouseService { public void logApiCall(ContainerRequest cr) { //

Guice - Jersey - Servlet binding

冷暖自知 提交于 2019-12-06 05:56:22
问题 I recently switched to two phase injection and this has created an error in my servlet binding. I am currently toggling between two error modes and not sure which direction is best to pursue. The first error I encountered was: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes. My servlet module looked like this: public class MyServletModule extends JerseyServletModule { @Override protected void configureServlets() { bind

GCM: java.lang.NoClassDefFoundError: com/google/android/gcm/server/Sender

强颜欢笑 提交于 2019-12-06 05:56:04
I have been trying to get Google Cloud Messaging to work in eclipse. I was able to compile the example given on their demo webpage and run that without any errors; however, when I try to create my own example using jersey I get the run time error "java.lang.NoClassDefFoundError: com/google/android/gcm/server/Sender" when the following code tries to create a sender. @POST @Path("/send") public Response sendMessage() throws IOException { Sender sender = new Sender("api_key"); Message message = new Message.Builder().build(); sender.send(message, DataStore.getDevices(), 5); return Response.status

Any way to get the path parameters in httpservlet request

家住魔仙堡 提交于 2019-12-06 05:51:09
问题 I have rest service implemented. I am trying to get the path parameters of the the request in filter. My request is /api/test/{id1}/{status} public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { //Way to get the path parameters id1 and status } 回答1: There's no other way to do it in a ServletFilter other than trying to parse the URI yourself, but you can access the path parameters if you decide to use a JAX-RS request filter:

What is the best way of securing a REST API? [closed]

放肆的年华 提交于 2019-12-06 05:48:45
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am developing a REST API with Java using Jersey and what is the best way of securing it? I looked at various things from password based authentication, Servlet Context , and I heard about tokenization and so on. But what is the industry standard way to secure it and make sure

How to turn my Jersey REST API into an executable JAR?

帅比萌擦擦* 提交于 2019-12-06 05:48:32
I am using Jersey, Maven; and could use Jetty, Tomcat or J2EE Preview (is that embeddable?). What is the easiest way to port my REST API as a standalone/executable JAR? Can I do it without Spring Boot? Follow these steps to create a standalone application with Jersey and Tomcat : Adding Maven dependencies Add the following dependencies and properties to your pom.xml : <properties> <tomcat.version>8.5.23</tomcat.version> <jersey.version>2.26</jersey.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8<

How do I use Custom Validations in Jersey

蹲街弑〆低调 提交于 2019-12-06 05:37:21
问题 I want to Implement a validation in a jersey such that if I send a duplicate value of UserName or Email which already exists in DataBase then it should throw an Error saying UserName/Email already exists. How can I acheive this? I gone through this jersey documentation https://jersey.java.net/documentation/latest/bean-validation.html https://github.com/jersey/jersey/tree/2.6/examples/bean-validation-webapp/src But I couldn't understood what exactly I have to follow to make my custom Jersey

How to serialize declarative links (jersey) with jackson

限于喜欢 提交于 2019-12-06 05:21:23
I am using declarative linking in my project. My jackson mapper configuration is 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); As I have disabled any kind of auto

File upload services using jersey in tomcat without maven

浪子不回头ぞ 提交于 2019-12-06 05:09:38
I want to upload images into server using restful jersey web services.I have included jersey-multipart-1.9.jar , jersey-bundle-1.14.jar and asm-3.3.1.jar jar files and I am not using Maven . Below code snippet for upload function. @POST @Path("/uploadImage") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) { String filePath = SERVER_UPLOAD_LOCATION_FOLDER + contentDispositionHeader.getFileName(); saveFile(fileInputStream, filePath);//method to save

How is the PUT request in this example using subresource is processed by JAX-RS run time?

浪子不回头ぞ 提交于 2019-12-06 05:06:19
问题 I am reading through this example of Storage-service example in Jersey Sample provided in oracle docs. I am just unable to understand how this PUT request is resolved by JAX-RS runtime? curl -X PUT http://127.0.0.1:9998/storage/containers/quotes here is the code snippet that corresponds to this request (taken from above link). @Path("/containers") @Produces("application/xml") public class ContainersResource { @Context UriInfo uriInfo; @Context Request request; @Path("{container}") public