Reputation: 111
How do I re-design a high-load REST web service?
I have an existing Java-based REST web service that's receiving a XML file as a String. There are several clients that are sending XML files to this service. It turns out that large XML files (>100 MB) that being sent to this service as Strings, cause causing the web service to slow down, freeze and crash (OutOfMemory).
How can I modify the web service to receive and handle large XML data, without affecting the existing clients?
This is what the existing web service signature is:
@POST
@Path("/acceptMessage")
public String acceptMessage(String request) throws Exception;
The "String request" is causing the load/performance problems. Any changes that I make to the web service signature cannot affect the existing web service clients.
What are my options?
Upvotes: 1
Views: 1943
Reputation: 44355
Change the String request
parameter to Reader request
. According to section 4.2.4 of the JAX-RS specification, it could also be File request
. And there are a number of other valid types which you may or may not find useful:
javax.activation.DataSource
All media types (/).javax.xml.transform.Source
XML types (text/xml, application/xml and application/*+xml).javax.xml.bind.JAXBElement
and application-supplied JAXB classes XML media types (text/xml, application/xml and application/*+xml).Upvotes: 1