Bonjour,

J'ai le message d'erreur suivant sur un Webservice RestEASY
org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class
A priori, lie a un mauvais type ou a un Corps manquant ?
Mais pourquoi ?

Merci d'avance
Phil

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
org.jboss.resteasy.spi.InternalServerErrorException: Bad arguments passed to public javax.ws.rs.core.Response wsrest05.server.SampleService.prototype(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)  ( org.jboss.resteasy.spi.BadRequestException org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput of content type: multipart/form-data;boundary="ad47b34c-3ce5-4060-bcbb-9b4bc9697cea" )
	at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:195)
	at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
	at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
	at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
	at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
	at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:154)
	... 25 more

Mon interface client
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
 
@Path("/prototype") 
      @POST
	  @Consumes("multipart/form-data")
    @Produces(MediaType.TEXT_PLAIN)
      public Response prototype(MultipartFormDataOutput partFormData);

Mon implémentation client
J'envoi un PDF et une String
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
   TestClient client = ProxyFactory.create(TestClient.class, url);
  MultipartFormDataOutput partFormData = new MultipartFormDataOutput(); 
	System.out.println("TestAppPrototype ajout file");
	partFormData.addFormData("file", fileToBytes(tmp),  new MediaType("application/pdf", "pdf")); 
partFormData.addFormData("isbn", "XXXX", new MediaType("text/plain", "text"));
client.prototype(partFormData); 
 
 
 
--
--
  public static byte[] fileToBytes(String fn) {
        byte[] bytes = null;
 
        File            f   = new File(fn);
        FileInputStream fin = null;
        FileChannel     ch  = null;
 
        try {
            fin = new FileInputStream(f);
            ch  = fin.getChannel();
 
            int              size = (int) ch.size();
            MappedByteBuffer buf  = ch.map(MapMode.READ_ONLY, 0, size);
 
            bytes = new byte[size];
            buf.get(bytes);
        } catch (IOException e) {
 
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                if (fin != null) {
                    fin.close();
                }
 
                if (ch != null) {
                    ch.close();
                }
            } catch (IOException e) {
 
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
 
        return bytes;
    }
Mon serveur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
    @POST
    @Path("/prototype")
    @Consumes("multipart/form-data")
    @Produces(MediaType.TEXT_PLAIN)
    public Response prototype(MultipartFormDataOutput partFormData) {
 
 
    Map<String, OutputPart> partsMap = partFormData.getFormData();
 
    String isbn = partsMap.get("isbn").getEntity().toString();	
 
    Random randomGenerator = new Random();
    OutputPart part=partsMap.get("file");
    String mediaType = part.getMediaType().toString();
    int randomInt = randomGenerator.nextInt(100);
 
   try {
            writeFile((byte[]) partsMap.get("file").getEntity(), "\tmp\\rest5_prototype_"+randomInt+isbn);
        } catch (IOException e) {
            e.printStackTrace();
	System.out.println("Erreur="+e.getMessage());
        }
}	
 
/*
*/
private void writeFile(byte[] content, String filename) throws IOException {
        File file = new File(filename);
 
        if (!file.exists()) {
            file.createNewFile();
        }
 
        FileOutputStream fop = new FileOutputStream(file);
 
        fop.write(content);
        fop.flush();
        fop.close();
    }
le pom
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.8.2</version>
			<scope>test</scope>
		</dependency>
 
		<dependency>
			<groupId>org.jboss.resteasy</groupId>
			<artifactId>resteasy-jaxrs</artifactId>
			<version>2.3.0.GA</version>
		</dependency>
 
 
 
		<dependency>
			<groupId>org.jboss.resteasy</groupId>
			<artifactId>resteasy-multipart-provider</artifactId>
			<version>2.3.0.GA</version>
		</dependency>
 
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam-resteasy</artifactId>
			<version>2.2.0.GA</version>
		</dependency>
 
		<dependency>
  <groupId>javax.ws.rs</groupId> 
  <artifactId>jsr311-api</artifactId> 
  <version>0.8</version> 
</dependency>
 
 
		<dependency>
   <groupId>jboss</groupId>
   <artifactId>jbossall-client</artifactId>
   <version>4.2.2.GA</version>
</dependency>
 
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.0.1</version>
		</dependency>
 
 
		<dependency>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
   <version>1.5</version>
</dependency>
 
<dependency>
	<groupId>commons-httpclient</groupId>
	<artifactId>commons-httpclient</artifactId>
	<version>3.1</version>
</dependency>
 
 
<dependency>
   <groupId>jboss</groupId>
   <artifactId>javassist</artifactId>
   <version>3.6.ga</version>
</dependency>
 
<dependency>
<groupId>org.jboss.resteasy</groupId> 
  <artifactId>jaxrs-api</artifactId> 
<!-- <version>2.2.1.ga</version>-->
  <version>2.3.0.ga</version>
</dependency>