Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Marco Castigliego
    @marcocast
    Cool
    Marco Castigliego
    @marcocast
    John, I m trying to create a multipart rest POST method in micro service,
    @POST
    @Path("send/image")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces("application/json")
    public Response send(@FormDataParam("file") InputStream fileInputStream)throws Exception {
        return Response.ok("Report sended").build();
    }
    i can see in the microservice doc
    that i need to register those resources
    so in my module, i m doing the following
    @Override
    public List<Class> getRestResourceClasses() {
    final List<Class> resources = Lists.newArrayList();
        // Add additional features such as support for Multipart.
        resources.add(ReportRest.class);
    
        // Add additional features such as support for Multipart.
        resources.add(MultiPartFeature.class);
    
        return resources;
    }
    unfortunately when i start the server
    i always get an exception on that method
    WARNING: The following warnings have been detected: WARNING: Cannot create new registration for component type class com.ucd.parkabled.rest.ReportRest: Existing previous registration found for the type.
    Existing previous registration found for the type.; source='null', [FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response com.ucd.parkabled.rest.ReportRest.send(java.io.InputStream,com.ucd.parkabled.model.ParkingLocation) throws java.lang.Exception at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.ucd.parkabled.rest.ReportRest, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@1f971be1]}, definitionMethod=public javax.ws.rs.core.Response com.ucd.parkabled.rest.ReportRest.send(java.io.InputStream,com.ucd.parkabled.model.ParkingLocation) throws java.lang.Exception, parameters=[Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class com.ucd.parkabled.model.ParkingLocation, source=parkingLocation, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
    any idea where to look at?
    John McClean
    @johnmcclean
    Is ReportRest an annotation or Rest Resource Class ?
    because for Rest Resources you can just annotatie them @Rest and they will be picked up automatically with no config
    the configuration is for registering your own Annotations
    Marco Castigliego
    @marcocast
    ReportRest is a normal Rest
    resource calss
    class
    it works perfectly if methods consume application/json
    it does n t work if methods consume MULTIPART_FORM_DATA
    in Jersey there is a specific lib to use in case of multipart
    i m investigating and in case micro server will need a change i ll do it
    John McClean
    @johnmcclean
    excellent - thanks Marco! I think Ciaran Treanor may have done something around this, will check my mails
    Marco Castigliego
    @marcocast
    ah ok
    let me know so
    btw i implented oauth token authentication with micro server and stormpath. Works like a charm :)
    John McClean
    @johnmcclean
    cool :)
    yeah, he has done it in his own service. We should add a wiki entry
    need to add jersey multi-part to the classpath
    compile 'org.glassfish.jersey.media:jersey-media-multipart:2.17'
    then create your app something like this
        new MicroserverApp(ConfigurableModule
    
                                          .builder()
    
                                          .context(“multipart-app")
    
                                          .defaultResources(Arrays.asList(MultiPartFeature.class))
    
                                          .build()).run();
    John McClean
    @johnmcclean
    so it looks like you are doing something similar - it’s probably down to the dependencies
    let me know if that works, and we can add a wiki entry
    Marco Castigliego
    @marcocast
    I saw that
    but it does not work
    John McClean
    @johnmcclean
    with this dependency? compile 'org.glassfish.jersey.media:jersey-media-multipart:2.17'
    Marco Castigliego
    @marcocast
    yes
    that dependency is already in the micro-server
    John McClean
    @johnmcclean
    what error do you get ?
    Marco Castigliego
    @marcocast
    basically if i add the .defaultResources(Arrays.asList(MultiPartFeature.class))
    then