jersey

Jersey JUnit Test: @WebListener ServletContextListener not invoked

吃可爱长大的小学妹 提交于 2019-12-07 14:39:38
问题 I created this test in Jersey (from the docs), which works fine, with one problem: the @WebListener ServletContextListener is not being invoked. The Resource classes that I need to test rely on an attribute set on the ServletContext by the ServletContextListener. Can I make sure it is invoked, or can I manipulate the ServletContext in some other way? public class SimpleTest extends JerseyTest { @WebListener public static class AppContextListener implements ServletContextListener { @Override

Jersey Inject Weld managed bean into ConstraintValidator

 ̄綄美尐妖づ 提交于 2019-12-07 14:11:43
问题 I've been searching for hours to find a solution for my problem but I can't get it to work. I want to inject my Weld-managed service into a ConstraintValidator that is used to validate a User-Object that is posted to my JAX-RS Rest-Service. Everything is deployed to a glassfish 4.1 server. I have a Service like this @ApplicationScoped public class UserService { } and I want to inject it into a ConstraintValidator like this public class UniqueUserNameValidator implements ConstraintValidator

How to return Array in Jersey REST webservice?

会有一股神秘感。 提交于 2019-12-07 13:20:26
I am new to REST webservice, I tried using Jersey implementation and wrote a simple webservice code to return List to calling client: @GET @Produces(MediaType.TEXT_XML) public GenericEntity<List<String>> stringlist() { List<String> list = Arrays.asList("test", "as"); return new GenericEntity<List<String>>(list) { }; } I am not sure how to get the value of the list in my client. I just tried using the below code in my client but I am getting error. service.path("rest") .path("getVal") .accept(MediaType.TEXT_XML) .get(GenericEntity.class Can someone help me with a simple webservice code which

Spring Data makes spring unable to find JAXRS's @Provider?

喜欢而已 提交于 2019-12-07 13:16:37
问题 I am using Spring + Jersey to build an API service . Recently , I try to incorporate Spring Data to my server . I haven't truly use any Repositories in my running code , just add one line in my app.xml : <jpa:repositories base-package="destiny.web" entity-manager-factory-ref="entityManagerFactoryApp" /> But ! I notice my API not working , complaining " A message body writer for Java class xxx , and Java type class xxx , and MIME media type application/json was not found " If I remove the "jpa

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

浪尽此生 提交于 2019-12-07 13:11:43
问题 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

Passing the URI Path to the JAX-RS Providers

拈花ヽ惹草 提交于 2019-12-07 12:32:04
问题 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

Jersey-Guice doesn't process bound resources if injector is a child?

妖精的绣舞 提交于 2019-12-07 12:29:49
问题 I'm using Jersey-Guice to configure a Jersey app, following this template. Everything works fine if the Injector returned by the GuiceServletContextListener.getInjector() method is created by Guice.createInjector() . If that injector is instead the child of another injector, then the bound resources (e.g., MyResource in the code below) are never added to the Jersey ResourceConfig and Jersey crashes with a complaint about missing root resources. I don't think the bound resources are even

Tomcat Jersey Eclipse ClassNotFound org.glassfish.jersey.servlet.ServletContainer

南笙酒味 提交于 2019-12-07 12:03:17
问题 I am running the hello world example. However, I am using version 2.7. on maven pom.xml I have <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mydomain.restful</groupId> <artifactId>AdvertServer</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Advert Server</name> <dependencyManagement>

Jersey: “Missing dependency for method …”

淺唱寂寞╮ 提交于 2019-12-07 11:09:05
问题 Could somebody please explain the meaning of this error? INFO: Scanning for root resource and provider classes in the Web app resource paths: /WEB-INF/lib /WEB-INF/classes Feb 21, 2012 3:03:48 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class com.foo.dom2jcr.rest.XMLCRUDRestlet Feb 21, 2012 3:03:48 AM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found. Feb 21, 2012 3:03:48 AM com.sun.jersey.server.impl

Jersey - Is there a way to instantiate a Per-Request Resource with parameters?

假如想象 提交于 2019-12-07 10:42:05
问题 Suppose I have this class: @Path("/test") public class TestResource{ private TestService testService; public TestResource(TestService testService){ this.testService = testService; } @GET public String getMessage(){ return testService.getMessage(); } } Then, I want to register it with Jersey. One would do: TestService testService = new TestServiceImpl(); resourceConfig.register(new TestResource(testService)); But the problem is that approach makes a single instance of TestResource. I want to