I have been trying to get a simple REstful web service working, eventually getting this to talk to a database (via another Java class).
I've started simple, seeing if I can pass in some data and get a response.
The code for the web service is :
package com.mystuff.wstest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@Path("/generic")
public class GenericResource
{
@Context
private UriInfo context;
public GenericResource()
{
}
@GET
@Path("/data")
@Produces("application/xml")
public String getXml(@QueryParam("ctype") String cType, @QueryParam("cdata") String cData)
{
return ( "<ret><One>" + cType + "</One><Two>" + cData + "</Two></ret>" );
}
The url to test this is:
http://localhost:8080/WebSvc1/webresources/generic/data?ctype=a\&cdata=b
But the returned response in the browser does not show as XML, but simply a "ab" - i.e. it's interpreting the XML as HTML tags.
Testing with wget show this:
$ wget -S -q -O - http://localhost:8080/WebSvc1/webresources/generic/data?ctype=a\&cdata=b
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Sun, 10 Aug 2014 12:05:37 GMT
<ret><One>a</One><Two>b</Two></ret>
What am I missing?
No comments:
Post a Comment