CXF "Kein Message-body-reader gefunden" für byte-array-parameter in POST-service

Bin ich zu schreiben versucht, einen Dienst, der verantwortlich für das hochladen einer Datei, indem Sie die Datei als array von bytes in den POST Einheit. Hier ist mein code

Meine CXF Service

@Path("MyTest")
public class TestService {
    @POST
    public String MyPost(Byte[] bytes){
        System.out.println("Service invoked");
        return "Hello, I am a POST response";
    }
}

Mein Client

File image = new File("C:\\snake.jpg");
FileInputStream is = new FileInputStream(image);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] fileInBytes = bos.toByteArray();

Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/MyApp");
target = target.path("MyTest");
Response response = target.request().post(Entity.entity(fileInBytes, MediaType.APPLICATION_OCTET_STREAM));

InputStream i = (InputStream) response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(i));
System.out.println(br.readLine());

- Und dies ist die Fehler, dass ich

SEVERE: No message body reader has been found for class [Ljava.lang.Byte;, ContentType: application/octet-stream
Nov 06, 2014 4:02:50 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1298)
...

Irgendwelche Ideen darüber? Gibt es einen besseren Weg, um eine Datei-Upload-service?

Dank

InformationsquelleAutor NikosDim | 2014-11-06
Schreibe einen Kommentar