jersey

Jersey test - Http Delete method with JSON request

…衆ロ難τιáo~ 提交于 2019-12-11 09:54:47
问题 I am using Jersey Test to test Rest service DELETE method: @DELETE @Path("/myPath") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public MyResponse myMethod(MyRequest myRequest) { I have tried the example below and other methods: Entity<MyRequest> requestEntity = Entity.entity(new MyRequest(arg1, arg2), MediaType.APPLICATION_JSON); target(MY_URI).request(MediaType.APPLICATION_JSON).method("DELETE", requestEntity) and target(MY_URI).request(MediaType.APPLICATION

Jersey switch on Content Type dynamically

两盒软妹~` 提交于 2019-12-11 09:52:55
问题 A similar question is here: Supporting both Multipart and Application Url Encoded parameters in Jersey I have an API endpoint (in Jersey) that can accepts POST request. The content types are either: form-urlencoded, or multipart. The two types of request arrive at the same path. How do I switch on that? For the urlencoded request, I want to get argument: @FormParam("recipient") String recipient For multipart request, I want to get: @FormDataParam("file") InputStream uploadedInputStream,

Path parameter in programmatic Jersey resource

自闭症网瘾萝莉.ら 提交于 2019-12-11 09:46:56
问题 I am using Jersey's programmatic API described here to dynamically create configured resources from a configuration file at runtime. My code to create those resources follows these lines: public ResourceCreator() { for (String resource : cfg.getConfiguredResources()) { logger.log(Level.CONFIG, "Creating resource {0}", resource); final Resource.Builder resourceBuilder = Resource.builder() .path(resource); resourceBuilder.addMethod("GET") .produces(MediaType.APPLICATION_JSON_TYPE) .handledBy

java.lang.NoSuchFieldError: WADL_JSON in creating jersey rest client

拜拜、爱过 提交于 2019-12-11 09:44:22
问题 I am creating jersey rest client with jackson pojo mapping . here is code spinet: ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getClasses().add(JacksonJsonProvider.class); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = Client.create(clientConfig); webResource = client.resource("url to exposed rest web service"); This code is throwing following exception at line client = Client.create(clientConfig) Sep 01, 2014 12:42:04 PM

Jersey Update Entity Property MessageBodyWriter

倖福魔咒の 提交于 2019-12-11 09:01:17
问题 I want to create a Jersey provider (MessageBodyWriter) that update a dto object property and continue the chain to Jersey-json default provider an return the json object. the problem is that looks like default provider is not called so the output of my rest service become empty as soon as I register the new Provider. @Provider public class TestProvider implements MessageBodyWriter<MyDTO> { @Override public long getSize( MyDTO arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4)

Unable to upload file with jersey

倖福魔咒の 提交于 2019-12-11 08:46:45
问题 I am using this webservice to upload a file using jersey public class upload { @POST @Path(value = "upload") @Consumes("image/jpg") public Response uploadPng(File file) throws IOException { file = new File("C:/Users/Marwa/Desktop/Capture.jpg"); String uploadedFileLocation = "C:/Users/Desktop/" + file.getName(); DataInputStream diStream =new DataInputStream(new FileInputStream(file)); long len = (int) file.length(); byte[] fileBytes = new byte[(int) len]; int read = 0; int numRead = 0; while

Jersey JAX-RS ResourceConfig with Tomcat

拟墨画扇 提交于 2019-12-11 08:45:31
问题 I have a basic REST web service that works but I do have a question. Here is a brief code snip. package com.my.app; import org.glassfish.jersey.server.ResourceConfig; import javax.ws.rs.ApplicationPath; @ApplicationPath("api") public class RestApplication extends ResourceConfig { RestApplication() { packages("com.my.app"); } } And <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>The name of my

java jersey variable length paths

三世轮回 提交于 2019-12-11 08:26:20
问题 Is there anyway to specify in jersey I want a variable length paths? e.g. I want to implement a jersey resouce that handles e.g. the following url: /images/asdfu213/size;width=100;height=200/reflect;offset=2/rotate;angle=0.45/ This is a variable length path as the user could append another operation on the image e.g.: /images/asdfu213/size;width=100;height=200/reflect;offset=2/rotate;angle=0.45/shear;x=0.3/ is there anyway in jersey to implement this? I have tried: @Path("/{id}/{size}/{ops: .

Jersey Resource .class loading

寵の児 提交于 2019-12-11 08:22:57
问题 I have the Jersey resource classes bundled within a larger WAR as JAR file which is now residing underneath WEB-INF/lib folder on Websphere Application Server. I have the correct web.xml entry(WEB-INF/web.xml) but still on the server, the scan appears to be not able to lookup the Resource classes which are bundled as a JAR. I was looking at a few threads, and the suggestion was to not bundle Resources as a JAR but instead load the classes seperately underneath /WEB-INF/classes. <servlet-name

Is it possible to use Spring MVC with Jersey annotations?

落花浮王杯 提交于 2019-12-11 08:17:58
问题 I am wondering, if it's possible to use Spring Web MVC with Jersey annotations, as I'm having a massive problem with Spring not being able to parse part variables the way Jersey can and I need to migrate some Jersey code to Spring MVC. I have the following code in Jersey: @PUT @Path("{storageId}/{repositoryId}/{path:.*}") @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") public Response upload(@PathParam("storageId") String storageId, @PathParam("repositoryId") String repositoryId, @PathParam