3

I have a jax-rs REST service, using JEE 7 (deployed in glassfish 4), which has a method to process HTTP POST on the resource:

    import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
    import org.glassfish.jersey.media.multipart.FormDataParam; 


    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadVideo(
            @FormDataParam("files") InputStream uploadedInputStream,
            @FormDataParam("files") FormDataContentDisposition fileDetail) { 
        try {

            //do something

        } catch (Exception e) {

            e.printStackTrace();
        }

        return toReturn.build();
    }

My pom.xml in ejb is :

<dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.22.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.22.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>2.22.2</version>
        </dependency>

And I registered the rest resource with these annotations:

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {

@Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> resources = new HashSet<>();
        resources.add(MultiPartFeature.class);
        return resources;
    }

    @Override
    public Map<String, Object> getProperties() {
        Map<String, Object> properties = new HashMap<>();
        properties.put("jersey.config.server.provider.packages", "com.myBean.upload");
        return properties;
    }  
}

When I try to start the server I get this error:

java.lang.ClassCastException: Cannot cast org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionInterceptorProvider to org.glassfish.jersey.server.spi.ComponentProvider

I already read this questions :Jersey 2 injection source for multipart formdata and How can I define a JAX-RS service that processes multi-part data in JEE? but I cannot find a solutions. Any suggestions?

-Log produced

WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds. WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds. WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds. WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds. WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds. WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

5
  • 2
    What happens if you put all the dependencies' <scope> as provided? Mar 15, 2016 at 9:11
  • I tried your suggestion, now the server starts but all the Rest Resource doesn't work. They all respond with 404. I don't know why (the url is the same as before)
    – enricop89
    Mar 15, 2016 at 9:23
  • Do you see any server logs from Jersey? The reason I said to put the scope as provided is the Glassfish already has all the Jersey jars, and (the version) may conflict with the ones you add to your project. I don't see how not providing the jars would cause the app not to run, as Glassfish already has them. I don't know Mar 15, 2016 at 9:27
  • Can you add some logging in the application class to see if it's being created Mar 15, 2016 at 9:30
  • @peeskillet I edit the questions so you can see the log
    – enricop89
    Mar 15, 2016 at 9:38

1 Answer 1

1

Finally I got the solution. For the first problem :

Cannot cast org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionInterceptorProvider to org.glassfish.jersey.server.spi.ComponentProvider

the solution was the one given by @peeskillet.

My real problem was a little different since I miss to register all the packages with Rest Resource. I post here the solution for this problem anyway:

        @ApplicationPath("/rest")
        public class JaxRsActivator extends Application {

        @Override
            public Set<Class<?>> getClasses() {
                final Set<Class<?>> resources = new HashSet<Class<?>>();
                resources.add(MultiPartFeature.class);
                return resources;
            }

            @Override
            public Map<String, Object> getProperties() {
                Map<String, Object> properties = new HashMap<>();
                String array[] = {"com. myBean.home","com. myBean.upload","com.bandyer.search","com.bandyer.mail"};
                properties.put("jersey.config.server.provider.packages", array);
            }
        }
1
  • This is not the solution for you initial problem, but you can update your answer a little bit and accept it (probably tomorrow) to mark the question as solved.
    – unwichtich
    Mar 15, 2016 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.