Thanks a lot,
Andrea
Date: Fri, 17 May 2013 03:36:12 -0700
From: [email protected]
To: [email protected]
Subject: Re: Rest ws: how to return an empty List<Integer> avoiding
java.lang.IndexOutOfBoundsException
Hi
Please see comments below,
On 17/05/13 11:04, eanbiso wrote:
Hi all,
I have a problem with rest endPoint that return an empty list.
I have a ws interface like this:
@GET
@Produces("multipart/form-data;type=text/xml")
@Path("/GetNetworkIDsManagedBy/{controller}")
public List<Integer> GetNetworkIDsManagedBy(
@PathParam("controller") int controller);
If in the implementor I return an empty list:
@Override
public List<Integer> GetNetworkIDsManagedBy(int controller) {
List<Integer> temp = new ArrayList<Integer>();
return temp;
}
this exception occurs:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at
org.apache.cxf.jaxrs.ext.MessageContextImpl.convertToAttachments(MessageContextImpl.java:185)
at
org.apache.cxf.jaxrs.ext.MessageContextImpl.put(MessageContextImpl.java:159)
at
org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext.put(ThreadLocalMessageContext.java:83)
at
org.apache.cxf.jaxrs.provider.MultipartProvider.writeTo(MultipartProvider.java:245)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:257)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:144)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:83)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:323)
at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:289)
at
org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:942)
at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:878)
at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:349)
at
org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
at
org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)
at
org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:52)
at
org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
at
org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Unknown Source)
However, if I return null instead of the empty list, no exception occurs and
the client receive the response.
In this case it has to be an empty body and HTTP status 204 - is what
the client is seeing when you return null.
I'd like to get the same behavior, returning an empty list.
Is it possible and how?
Do I use wrong annotations?
What exactly do you expect when you return an empty List<Integer> ?
Empty body & 204 ? Or actually a proper multipart/form-data payload
response with the root part containing some XML ?
FYI, JAXB provider will not handle List<Integer>, you will need to wrap
it into a bean or if you prefer returning List - then wrap Integer into
a bean
Cheers, Sergey
Thanks a lot,
Andrea
--
View this message in context:
http://cxf.547215.n5.nabble.com/Rest-ws-how-to-return-an-empty-List-Integer-avoiding-java-lang-IndexOutOfBoundsException-tp5727816.html
Sent from the cxf-user mailing list archive at Nabble.com.
If you reply to this email, your message will be added to the
discussion below:
http://cxf.547215.n5.nabble.com/Rest-ws-how-to-return-an-empty-List-Integer-avoiding-java-lang-IndexOutOfBoundsException-tp5727816p5727818.html
To unsubscribe from Rest ws: how to return an empty
List<Integer> avoiding java.lang.IndexOutOfBoundsException, click here.
NAML
--
View this message in context:
http://cxf.547215.n5.nabble.com/Rest-ws-how-to-return-an-empty-List-Integer-avoiding-java-lang-IndexOutOfBoundsException-tp5727816p5727819.html
Sent from the cxf-user mailing list archive at Nabble.com.