cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jervis Liu (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CXF-758) POST with not body causes exception in REST service
Date Thu, 02 Aug 2007 07:40:52 GMT

    [ https://issues.apache.org/jira/browse/CXF-758?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12517165
] 

Jervis Liu commented on CXF-758:
--------------------------------

Below is the comment copied from cxf-dev mailing list:

In general, yes, any non-idempotent operations should not be required to have a body. But
when it comes to using JAX-WS Dispatch/Provider to implement a Restful service, its really
down to the semantics of Provider/Dispatch per spec. As the spec is not specific on this point,
we could extend CXF code to support empty body with POST. However in practical, it is not
very clear to me how this can be done. First, empty body does not equal to a null Source.
Secondly, an empty Source wont be always mapped to an empty body and vice versa. For example,
if I give Dispatch an empty Source by Source emptySource = new DomSource(), the underlying
transformer will create empty source Document using DocumentBuilder.newDocument() thus results
in a XML body with at least an XML declaration of <?xml version="1.0" standalone="no" encoding="UTF-8"?>.
Same thing occurs to the Provider side, for an empty body without an XML declaration, the
parser even wont be able to know the input is indeed an xml document.

I would say this is just the limitation of using JAX-WS Dispatch/Provider to implement a Restful
service. If this blocks you, you can try something else, for example, the HTTP binding for
Restful service.

Cheers,
Jervis

> POST with not body causes exception in REST service
> ---------------------------------------------------
>
>                 Key: CXF-758
>                 URL: https://issues.apache.org/jira/browse/CXF-758
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Conrad O'Dea
>
> Sending a POST with an empty body to a RESTful service causes a 500 to be raised by the
server.
> In the client for the restful_dispatch demo, change this line: 
>         InputStream in = url.openStream();
> to
>         HttpURLConnection conn = (HttpURLConnection)url.openConnection();
>         conn.setRequestMethod("PUT");
>         InputStream in = conn.getInputStream();
> and run the client against the server. 
> I get the following stack trace on the client: 
>      [java] Exception in thread "main" java.io.IOException: Server returned HTTP response
code: 500 for URL: http://localhost:9000/customerservice/customer
>      [java]     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1152)
>      [java]     at demo.restful.client.Client.main(Client.java:66)
>      [java] Java Result: 1
> and the following stack trace on the server 
>      [java] Jul 2, 2007 3:33:12 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
>      [java] INFO: Interceptor has thrown exception, unwinding now
>      [java] org.apache.cxf.interceptor.Fault: Could not parse the XML stream.
>      [java]     at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:96)
>      [java]     at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:86)
>      [java]     at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:48)
>      [java]     at org.apache.cxf.jaxws.interceptors.ProviderInDatabindingInterceptor.handleMessage(ProviderInDatabindingInterceptor.java:103)
>      [java]     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:206)
>      [java]     at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:67)
>      [java]     at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:253)
>      [java]     at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:213)
>      [java]     at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:54)
>      [java]     at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
>      [java]     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
>      [java]     at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
>      [java]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
>      [java]     at org.mortbay.jetty.Server.handle(Server.java:281)
>      [java]     at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:502)
>      [java]     at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:821)
>      [java]     at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
>      [java]     at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:208)
>      [java]     at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:378)
>      [java]     at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:368)
>      [java]     at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
>      [java] Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
>      [java]  at [row,col {unknown-source}]: [1,0]
>      [java]     at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:661)
>      [java]     at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2134)
>      [java]     at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2040)
>      [java]     at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
>      [java]     at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:663)
>      [java]     at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:518)
>      [java]     at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:93)
>      [java]     ... 20 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message