Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4552

typical HTML form payload does not seem to work when HTML form is used

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.2
    • Fix Version/s: 2.5.6, 2.6.3, 2.7.1
    • Component/s: JAX-RS
    • Labels:
      None
    • Environment:
    • Estimated Complexity:
      Unknown

      Description

      I am using HTML form below to upload files using jax-rs but the attachments parameter is null.

      The code and error are shown:

      form:
      <html>
      <head>
      <meta http-equiv="pragma" content="no-cache" />
      </head>
      <body>
      <FORM action="/jax_rs_basic/cxf/files/upload"
      enctype="multipart/form-data"
      method="post">
      <P>
      What is your name? <INPUT type="text" name="submit-name"><BR>
      What files are you sending? <INPUT id="files" type="file" name="files"><BR>

      <INPUT type="submit" value="Send"> <INPUT type="reset">
      </FORM>
      </body>
      </html>

      code:
      package demo.jaxrs.server;

      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.util.List;

      import javax.ws.rs.Consumes;
      import javax.ws.rs.POST;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.Response;

      import org.apache.cxf.jaxrs.ext.multipart.Multipart;
      import org.apache.cxf.message.Attachment;

      @Path("/files/")
      public class MultipartService {

      @Path("/upload")
      @Consumes("multipart/form-data")
      @Produces("text/html")
      @POST
      public Response addAttachments(@Multipart("submit-name") String submitName,
      @Multipart("files") List<Attachment> files) {

      System.out.println(submitName);
      System.out.println(files);
      for(Attachment a:files) {
      System.out.println(a.getId());
      InputStream is;
      try

      { is = a.getDataHandler().getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(is)); System.out.println(r.readLine()); }

      catch (IOException e)

      { // TODO Auto-generated catch block e.printStackTrace(); }

      }

      return Response.ok("<html><body>Files Saved</body></html>").type("text/html").build();

      }
      }

      beans.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jaxrs="http://cxf.apache.org/jaxrs"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://cxf.apache.org/jaxrs
      http://cxf.apache.org/schemas/jaxrs.xsd">

      <!-- do not use import statements if CXFServlet init parameters link to this beans.xml -->

      <import resource="classpath:META-INF/cxf/cxf.xml" />
      <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

      <bean id="MyInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>

      <jaxrs:server id="customerService" address="/">
      <jaxrs:inInterceptors><ref bean="MyInterceptor"/></jaxrs:inInterceptors>
      <jaxrs:serviceBeans>
      <!-- ref bean="customerBean" /-->
      <ref bean="filesBean" />
      </jaxrs:serviceBeans>
      </jaxrs:server>

      <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
      <bean id="filesBean" class="demo.jaxrs.server.MultipartService" />
      </beans>

      error log:
      17:10:58 INFO context.ContextLoader - Root WebApplicationContext: initialization completed in 1422 ms
      17:10:58 DEBUG support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'cxf'
      Oct 09, 2012 5:02:09 PM org.apache.cxf.interceptor.LoggingInInterceptor
      INFO: Inbound Message
      ----------------------------
      ID: 1
      Address: http://pinkydebian:8080/jax_rs_basic/cxf/files/upload
      Encoding: ISO-8859-1
      Http-Method: POST
      Content-Type: multipart/form-data; boundary=---------------------------222852432428027
      Headers:

      {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8], accept-encoding=[gzip, deflate], accept-language=[en-us,en;q=0.5], connection=[keep-alive], Content-Length=[469], content-type=[multipart/form-data; boundary=---------------------------222852432428027], host=[pinkydebian:8080], referer=[http://pinkydebian:8080/jax_rs_basic/multipart.html], user-agent=[Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1]}

      Payload: -----------------------------222852432428027
      Content-Disposition: form-data; name="submit-name"

      Miten
      -----------------------------222852432428027
      Content-Disposition: form-data; name="files"; filename="kingfisher.txt"
      Content-Type: text/plain

      Service Temporarily Unavailable

      The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
      ----------------------------222852432428027-

      --------------------------------------
      Miten
      null
      Oct 09, 2012 5:02:09 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
      WARNING: Application

      {http://server.jaxrs.demo/}

      MultipartService has thrown exception, unwinding now
      org.apache.cxf.interceptor.Fault
      at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
      at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
      at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
      at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
      at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.NullPointerException
      at demo.jaxrs.server.MultipartService.addAttachments(MultipartService.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
      ... 34 more

      Oct 09, 2012 5:02:09 PM org.apache.cxf.phase.PhaseInterceptorChain unwind
      WARNING: Exception in handleFault on interceptor org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor@8dae83
      org.apache.cxf.interceptor.Fault
      at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
      at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
      at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
      at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
      at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.NullPointerException
      at demo.jaxrs.server.MultipartService.addAttachments(MultipartService.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
      ... 34 more

      Oct 09, 2012 5:02:09 PM org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver onMessage
      SEVERE: Error occurred during error handling, give up!
      org.apache.cxf.interceptor.Fault
      at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
      at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
      at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
      at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
      at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
      at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.NullPointerException
      at demo.jaxrs.server.MultipartService.addAttachments(MultipartService.java:30)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
      ... 34 more

      Regards,

      Miten
      imiten@yahoo.com

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              imitenmehta Miten Mehta
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: