AngularJS CXF JAXRS文件上载

AngularJS CXF JAXRS文件上载,angularjs,file-upload,cxf,Angularjs,File Upload,Cxf,我正在使用JAXRS方法使用AngularJS客户端上传文件。我遵循这里找到的AngularJS代码示例。在服务器端,找到了该方法,但我遇到了NullPointerException。我将在这里的末尾发布堆栈跟踪 我的CXF JAXRS接口: @Path("/images") public interface LinkableImages { @POST @Path("/upload") @Produces(MediaType.APPLICATION_JSON)

我正在使用JAXRS方法使用AngularJS客户端上传文件。我遵循这里找到的AngularJS代码示例。在服务器端,找到了该方法,但我遇到了NullPointerException。我将在这里的末尾发布堆栈跟踪

我的CXF JAXRS接口:

@Path("/images")
public interface LinkableImages {

    @POST
    @Path("/upload")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public List<Link> uploadFile(@Multipart(value = "userId", type = "application/json")Long userId, 
            @Multipart(value = "folder", type = "application/json") String foldername, 
            @Multipart(value="file") Attachment attachment) throws Exception;
}
这是服务器日志中的堆栈跟踪:

[2015-04-16 10:30:29,427] DEBUG MultipartFilter 114 doFilterInternal - Request [/note/soa/linkableImages/images/upload] is not a multipart request
[2015-04-16 10:30:29,428]  INFO CsrfHeaderFilter 31 doFilterInternal - setting csrf token in the cookie
[2015-04-16 10:30:29,446] DEBUG ServletController 219 invokeDestination - Service http request on thread: Thread[http-nio-8080-exec-64,5,main]
[2015-04-16 10:30:29,448] DEBUG AbstractHTTPDestination 224 invoke - Create a new message for processing
[2015-04-16 10:30:29,487] DEBUG Headers 380 copyFromRequest - Request Headers: {Accept=[application/json, text/plain, */*], accept-encoding=[gzip, deflate], accept-language=[en-us], connection=[keep-alive], Content-Length=[1113], content-type=[undefined], cookie=[JSESSIONID=9D0598F4A5473149F59C385AC83AF11A; XSRF-TOKEN=d1b24eff-67e3-42f0-8707-7b4d1cbb9f24], dnt=[1], host=[localhost:8080], origin=[http://localhost:8080], referer=[http://localhost:8080/note/user/note], user-agent=[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5], x-xsrf-token=[d1b24eff-67e3-42f0-8707-7b4d1cbb9f24]}
[2015-04-16 10:30:29,512] DEBUG LogUtils 452 doLog - Could not determine bean name for instance of class org.apache.cxf.bus.managers.PhaseManagerImpl.
[2015-04-16 10:30:29,529] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.ServiceInvokerInterceptor@5bcb1378 to phase invoke
[2015-04-16 10:30:29,531] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.OutgoingChainInterceptor@716b5a5c to phase post-invoke
[2015-04-16 10:30:29,531] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.OneWayProcessorInterceptor@3ef98830 to phase pre-logical
[2015-04-16 10:30:29,532] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c to phase unmarshal
[2015-04-16 10:30:29,534] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88 to phase pre-stream
[2015-04-16 10:30:29,536] DEBUG PhaseInterceptorChain 722 outputChainToLog - Chain org.apache.cxf.phase.PhaseInterceptorChain@5ba6c109 was created. Current flow:
  pre-stream [CertConstraintsInterceptor]
  unmarshal [JAXRSInInterceptor]
  pre-logical [OneWayProcessorInterceptor]
  invoke [ServiceInvokerInterceptor]
  post-invoke [OutgoingChainInterceptor]

[2015-04-16 10:30:29,536] DEBUG PhaseInterceptorChain 304 doIntercept - Invoking handleMessage on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88
[2015-04-16 10:30:29,539] DEBUG PhaseInterceptorChain 304 doIntercept - Invoking handleMessage on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c
[2015-04-16 10:30:29,587] DEBUG JAXRSUtils 296 selectResourceClass - Trying to select a resource class, request path : /images/upload
[2015-04-16 10:30:29,588] DEBUG MediaTypeHeaderProvider 165 handleMediaTypeWithoutSubtype - Converting a malformed media type 'undefined' to '*/*'
[2015-04-16 10:30:29,593] DEBUG JAXRSUtils 405 findTargetMethod - Trying to select a resource operation on the resource class com.sonam.note.webservice.jaxrs.user.UserImages
[2015-04-16 10:30:29,595] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : hello, request path : /upload, method @Path : /hello, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : multipart/form-data,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,595] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : getFilenames, request path : /upload, method @Path : /user, HTTP Method : POST, method HTTP Method : GET, ContentType : */*, method @Consumes : */*,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,596] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : deleteFile, request path : /upload, method @Path : /user/folder/delete, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : application/x-www-form-urlencoded,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,598] DEBUG JAXRSUtils 449 findTargetMethod - Resource operation uploadFile may get selected
[2015-04-16 10:30:29,598] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : multipartObject, request path : /upload, method @Path : /object, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : multipart/form-data,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,599] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : createFolder, request path : /upload, method @Path : /user/folder/create, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : application/x-www-form-urlencoded,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,600] DEBUG JAXRSUtils 476 findTargetMethod - Resource operation uploadFile on the resource class com.sonam.note.webservice.jaxrs.user.UserImages has been selected
[2015-04-16 10:30:29,604] DEBUG JAXRSInInterceptor 190 processRequest - Request path is: /images/upload
[2015-04-16 10:30:29,605] DEBUG JAXRSInInterceptor 191 processRequest - Request HTTP method is: POST
[2015-04-16 10:30:29,605] DEBUG JAXRSInInterceptor 192 processRequest - Request contentType is: undefined
[2015-04-16 10:30:29,606] DEBUG JAXRSInInterceptor 193 processRequest - Accept contentType is: application/json, text/plain, */*
[2015-04-16 10:30:29,606] DEBUG JAXRSInInterceptor 195 processRequest - Found operation: uploadFile
[2015-04-16 10:30:29,609] DEBUG MediaTypeHeaderProvider 165 handleMediaTypeWithoutSubtype - Converting a malformed media type 'undefined' to '*/*'
[2015-04-16 10:30:29,674] DEBUG PhaseInterceptorChain 477 unwind - Invoking handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c
[2015-04-16 10:30:29,678] DEBUG PhaseInterceptorChain 477 unwind - Invoking handleFault on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88
[2015-04-16 10:30:29,681]  WARN LogUtils 452 doLog - Interceptor for {http://user.jaxrs.webservice.note.sonam.com/}UserImages has thrown exception, unwinding now
java.lang.NullPointerException
    at org.apache.cxf.attachment.AttachmentUtil.getHeader(AttachmentUtil.java:306)
谢谢你的建议


-索纳姆

也许我晚了一点,但我想应该是:

headers: {'Content-Type': undefined}
没有
围绕未定义

[2015-04-16 10:30:29,427] DEBUG MultipartFilter 114 doFilterInternal - Request [/note/soa/linkableImages/images/upload] is not a multipart request
[2015-04-16 10:30:29,428]  INFO CsrfHeaderFilter 31 doFilterInternal - setting csrf token in the cookie
[2015-04-16 10:30:29,446] DEBUG ServletController 219 invokeDestination - Service http request on thread: Thread[http-nio-8080-exec-64,5,main]
[2015-04-16 10:30:29,448] DEBUG AbstractHTTPDestination 224 invoke - Create a new message for processing
[2015-04-16 10:30:29,487] DEBUG Headers 380 copyFromRequest - Request Headers: {Accept=[application/json, text/plain, */*], accept-encoding=[gzip, deflate], accept-language=[en-us], connection=[keep-alive], Content-Length=[1113], content-type=[undefined], cookie=[JSESSIONID=9D0598F4A5473149F59C385AC83AF11A; XSRF-TOKEN=d1b24eff-67e3-42f0-8707-7b4d1cbb9f24], dnt=[1], host=[localhost:8080], origin=[http://localhost:8080], referer=[http://localhost:8080/note/user/note], user-agent=[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5], x-xsrf-token=[d1b24eff-67e3-42f0-8707-7b4d1cbb9f24]}
[2015-04-16 10:30:29,512] DEBUG LogUtils 452 doLog - Could not determine bean name for instance of class org.apache.cxf.bus.managers.PhaseManagerImpl.
[2015-04-16 10:30:29,529] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.ServiceInvokerInterceptor@5bcb1378 to phase invoke
[2015-04-16 10:30:29,531] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.OutgoingChainInterceptor@716b5a5c to phase post-invoke
[2015-04-16 10:30:29,531] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.interceptor.OneWayProcessorInterceptor@3ef98830 to phase pre-logical
[2015-04-16 10:30:29,532] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c to phase unmarshal
[2015-04-16 10:30:29,534] DEBUG PhaseInterceptorChain 242 add - Adding interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88 to phase pre-stream
[2015-04-16 10:30:29,536] DEBUG PhaseInterceptorChain 722 outputChainToLog - Chain org.apache.cxf.phase.PhaseInterceptorChain@5ba6c109 was created. Current flow:
  pre-stream [CertConstraintsInterceptor]
  unmarshal [JAXRSInInterceptor]
  pre-logical [OneWayProcessorInterceptor]
  invoke [ServiceInvokerInterceptor]
  post-invoke [OutgoingChainInterceptor]

[2015-04-16 10:30:29,536] DEBUG PhaseInterceptorChain 304 doIntercept - Invoking handleMessage on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88
[2015-04-16 10:30:29,539] DEBUG PhaseInterceptorChain 304 doIntercept - Invoking handleMessage on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c
[2015-04-16 10:30:29,587] DEBUG JAXRSUtils 296 selectResourceClass - Trying to select a resource class, request path : /images/upload
[2015-04-16 10:30:29,588] DEBUG MediaTypeHeaderProvider 165 handleMediaTypeWithoutSubtype - Converting a malformed media type 'undefined' to '*/*'
[2015-04-16 10:30:29,593] DEBUG JAXRSUtils 405 findTargetMethod - Trying to select a resource operation on the resource class com.sonam.note.webservice.jaxrs.user.UserImages
[2015-04-16 10:30:29,595] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : hello, request path : /upload, method @Path : /hello, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : multipart/form-data,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,595] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : getFilenames, request path : /upload, method @Path : /user, HTTP Method : POST, method HTTP Method : GET, ContentType : */*, method @Consumes : */*,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,596] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : deleteFile, request path : /upload, method @Path : /user/folder/delete, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : application/x-www-form-urlencoded,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,598] DEBUG JAXRSUtils 449 findTargetMethod - Resource operation uploadFile may get selected
[2015-04-16 10:30:29,598] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : multipartObject, request path : /upload, method @Path : /object, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : multipart/form-data,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,599] DEBUG JAXRSUtils 592 logNoMatchMessage - No method match, method name : createFolder, request path : /upload, method @Path : /user/folder/create, HTTP Method : POST, method HTTP Method : POST, ContentType : */*, method @Consumes : application/x-www-form-urlencoded,, Accept : application/json,text/plain,*/*,, method @Produces : application/json,.
[2015-04-16 10:30:29,600] DEBUG JAXRSUtils 476 findTargetMethod - Resource operation uploadFile on the resource class com.sonam.note.webservice.jaxrs.user.UserImages has been selected
[2015-04-16 10:30:29,604] DEBUG JAXRSInInterceptor 190 processRequest - Request path is: /images/upload
[2015-04-16 10:30:29,605] DEBUG JAXRSInInterceptor 191 processRequest - Request HTTP method is: POST
[2015-04-16 10:30:29,605] DEBUG JAXRSInInterceptor 192 processRequest - Request contentType is: undefined
[2015-04-16 10:30:29,606] DEBUG JAXRSInInterceptor 193 processRequest - Accept contentType is: application/json, text/plain, */*
[2015-04-16 10:30:29,606] DEBUG JAXRSInInterceptor 195 processRequest - Found operation: uploadFile
[2015-04-16 10:30:29,609] DEBUG MediaTypeHeaderProvider 165 handleMediaTypeWithoutSubtype - Converting a malformed media type 'undefined' to '*/*'
[2015-04-16 10:30:29,674] DEBUG PhaseInterceptorChain 477 unwind - Invoking handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@705c279c
[2015-04-16 10:30:29,678] DEBUG PhaseInterceptorChain 477 unwind - Invoking handleFault on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@4dce7e88
[2015-04-16 10:30:29,681]  WARN LogUtils 452 doLog - Interceptor for {http://user.jaxrs.webservice.note.sonam.com/}UserImages has thrown exception, unwinding now
java.lang.NullPointerException
    at org.apache.cxf.attachment.AttachmentUtil.getHeader(AttachmentUtil.java:306)
headers: {'Content-Type': undefined}