2014-10-10 59 views
0

我有一個Web應用程序,在後端使用前端和Resteasy + Jackson的Angularjs。我送從角組件文件到REST方法,接收方法是這樣的:Resteasy總是根據請求獲取應用程序/ json內容類型

@POST 
@Path("/upload/attachment/for/{eventId}") 
@Consumes(MediaType.MULTIPART_FORM_DATA) 
public Response uploadFile(MultipartFormDataInput input, 
          final @PathParam("eventId") Long eventId, 
          @Context HttpServletRequest request) { 
    Map<String, List<InputPart>> uploadForm = input.getFormDataMap(); 
    ...my awesome stuff... 

    return Response.ok().build(); 

} 

,並要求有以下標題發送時:

Accept application/json, text/plain, */* 
Accept-Encoding gzip, deflate 
Accept-Language en-US,en;q=0.5 
Content-Length 347085 
Content-Type multipart/form-data; boundary=---------------------------12164806981346771846716776342 
Cookie JSESSIONID=aoBd1hgzR3GM8bSG5P-9g-vQ; csrftoken=ziQ7kN7TlMehR2aURDrmaMLYAroMsSpu 
Host localhost:9000 
Referer http://localhost:9000/local/myapp/index.html 
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:32.0) Gecko/20100101 Firefox/32.0 

的問題是,這個請求總是有application/json作爲內容類型而不是multipart/form-data,正如它在標題中所述。我得到:

20:12:00,490 WARN [org.jboss.resteasy.core.SynchronousDispatcher] (http-/127.0.0.1:8080-2) Failed executing POST /events/upload/attachment/for/null: org.jboss.resteasy.spi.UnsupportedMediaTypeException: Cannot consume content type 

已經在HttpServletDispatcher的內容是錯誤的。

如果這是將Content-Type設置爲錯誤值或其他某些東西的JBOSS,我無法得到。

回答

0

好吧,這是我在角度和服務器之間有一個額外的層,它運行在Node.js上,它只是向服務器發送請求。我不得不添加以下內容:

var r = null; 
r = request.put({uri: url, json: inReq.body, headers: inReq.headers, form: inReq.form}); 
inReq.pipe(r).pipe(inRes); 

此設置所有從傳出的請求和隧道頭請求 現在我有合適的content-type