jersey

章三、Spring+Jersey搭建REST服务器

我是研究僧i 提交于 2019-12-06 03:16:39
前两章已经写了如何使用jersey搭建REST接口服务器,本章将简单讲解如何使用jersey+Spring搭建REST接口服务器。 1、服务器 1.1 导入所需JAR包 jersey相关包的maven依赖 <!-- jersey客户端需要的包 --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.18.1</version> </dependency> <!-- jersey服务器端需要的包 --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-bundle</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json<

SBT - Failed to precise Play 2 app's project dependency

不想你离开。 提交于 2019-12-06 03:06:55
问题 I'm creating a play 2 project using Scala as main language and so need a rest client implemented in Scala. Unfortunately, I can't easily use the known Java Jersey-Client. I found on github this probably great api: sjersey-client Using SBT as dependency management tool, I try to indicate to play app its dependency to sjersey: object ApplicationBuild extends Build { val appName = "myWebapp" val appVersion = "1.0-SNAPSHOT" val appDependencies = Seq( jdbc, anorm ) lazy val sjersey = RootProject

Remove “/” from api call when optional parameter is null

混江龙づ霸主 提交于 2019-12-06 02:51:38
We are using RESTful Web Services (Jersey) for API calls on java. While API needs optional parameter, we are doing as: api-interface/user/userid/9000/companyid/90909/{optionalparameter*} and we have to call this api when there is no optional parameter as: api-interface/user/userid/9000/companyid/90909/ What needed is: Case:1 If optional parameter exists api-interface/user/userid/9000/companyid/90909/name/john/address/MA/age/34 Case:2 If Optional parameter doesn't exists. api-interface/user/userid/9000/companyid/90909 My present implementation is: @GET @Path("user/companyid/{companyid}/userid/

Read request attribute in a Jersey ContainerRequestFilter

不打扰是莪最后的温柔 提交于 2019-12-06 02:49:37
问题 I've got a Jersey API that's protected by Shibboleth, an SSO implementation. Shibboleth puts the id of the logged-in user in a request attribute. On the back end, I'm using Shiro for authorization. Shiro would like to know the logged-in user so it can load up permissions. What is the correct way to get that userId out of the request attribute and into Shiro? Right now, what I'm trying is: @Provider public final class ShiroLoginFilter implements ContainerRequestFilter { @Context private

How can I exclude null fields form my JSON request in Jersey?

雨燕双飞 提交于 2019-12-06 02:35:22
What I'm trying to do is to avoid null fields in my request. I use this Jersey dependencies <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.18</version> </dependency> <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-multipart</artifactId> <version>1.17</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId>

Accepting a List as a parameter to a Jersey webservice that consumes a content type of multi-part

前提是你 提交于 2019-12-06 02:34:29
I had an existing Jersey webservice method that accepts a number of parameters via Http POST method which is designed to handle a standard form data, content type of application/x-www-form-urlencoded; one of these parameters was a list of Strings. Below is an example of the method signature I have. @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response createItem( @FormParam("p1") long p1, @FormParam("p2") String p2, @FormParam("p3") List<String> p3, @FormParam("p4") String p4, @Context UriInfo uriInfo ) throws SQLException { This was working correctly and when multiple p3

Creating a folder within web server under /public_html/ in Java

天大地大妈咪最大 提交于 2019-12-06 02:29:42
I am trying to create a folder within web server using Java File handling APIs in my RESTFul web service developed using JERSEY. According to my understanding, when I target "xyz.com" , it by default points out /home/xyz/public_html/ in my server. So when I try to create a folder as follows String appFolderPath = "/xyz.com/appFolder/"; File userNameFolder = new File(appFolderPath + userName); if (!userNameFolder.exists()) { folderPath = userNameFolder.mkdir(); } The above code fails, I am not getting any exception, and no folder is created. How exactly I suppose to do it ? How to give path for

Passing the URI Path to the JAX-RS Providers

北城余情 提交于 2019-12-06 02:07:00
I recently implemented a Jersey JAX-RS Rest service. I created a JIBX provider that allows one to unmarshal and marshall between XML and Java types. I would like to also version my service by specifying the version in the URL path. Versioning would include the version of message binding used to marshal and unmarshall the Java types. Therefore, it is necessary that the version is passed to the custom JIBX provider, and therefore the URL path that contains the version. However, the Provider interfaces ( MessageBodyWriter and MessageBodyReader ) do not provide the URI path in their interface

Jersey setup without web.xml

安稳与你 提交于 2019-12-06 02:01:27
问题 I'm attempting to set up a simple REST web application that uses Jersey. In the documentation, it seems that I should be able to create my application without using a web.xml file. From the site: JAX-RS provides a deployment agnostic abstract class Application for declaring root resource and provider classes, and root resource and provider singleton instances. A Web service may extend this class to declare root resource and provider classes. The example that follows shows this code: public

Is it possible in Jersey to have access to an injected HttpServletRequest, instead of to a proxy

五迷三道 提交于 2019-12-06 01:41:48
问题 When injecting HttpServletRequest in Jersey/JAX-RS resources, the injected value is a proxy. E.g.: @Path("/myResource") class MyResource { @Inject HttpServletRequest request; ... } Will inject a Proxy object for the requested HttpServletRequest . I need access to the actual HttpServletRequest instance object, because I want to use some container specific features that are not in the proxied HttpServletRequest interface. Is there a way in jersey to have access to the actual object via