Requestid receiving as 0 for spring SOAP service - java

I developed one spring SOAP web service that is up and running. However, the request id I'm passing from the request is not getting updated. For all the requests I'm getting request id as 0. please help me with this issue.
My Endpoint details.
package com.example.thirdsoapweb.ThirdSoapWebService.soap;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import com.in_28minutes.courses.CourseDetails;
import com.in_28minutes.courses.GetCourseDetailsRequest;
import com.in_28minutes.courses.GetCourseDetailsResponse;
#Endpoint
public class CourseDetailsEndpoint {
//endpoint
//reuestobject
//respopnseobject
// http://in_28minutes.com/courses
// GetCourseDetailsRequest
#PayloadRoot(namespace = "http://in_28minutes.com/courses", localPart = "GetCourseDetailsRequest")
#ResponsePayload
public GetCourseDetailsResponse processCurseDetailsRequest(#RequestPayload GetCourseDetailsRequest request)
{
GetCourseDetailsResponse response=new GetCourseDetailsResponse();
CourseDetails courseDetails=new CourseDetails();
courseDetails.setId(request.getId());
System.out.println(request.getId());// here only i'm getting 0
courseDetails.setName("Rakesh");
courseDetails.setDescription("Spring Microservices and for the first time");
response.setCourseDetails(courseDetails);
return response;
}
}
Request payload
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetCourseDetailsRequest xmlns="http://in_28minutes.com/courses">
<id>[908]</id>
</GetCourseDetailsRequest>
</Body>
</Envelope>
Response payload
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:GetCourseDetailsResponse xmlns:ns2="http://in_28minutes.com/courses">
<ns2:CourseDetails>
<ns2:id>0</ns2:id>
<ns2:name>Rakesh</ns2:name>
<ns2:description>Spring Microservices and for the first time</ns2:description>
</ns2:CourseDetails>
</ns2:GetCourseDetailsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I tried debugging but cannot find out why I'm getting 0 in my request id. I want the requestid which I'm passing from the request.

Related

Customize SOAPEnvelope on SOAP webservice in Java

I have a SOAP web service. When it is called, I return a response this way:
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "...")
#ResponsePayload
public JAXBElement<MyResponseObject> mySoapService(#RequestPayload MyRequestObject request) {
MyResponseObject res = new MyResponseObject();
res.setField("my field content");
...
return createJaxbElementWithPrefix(res, MyResponseObject.class, "prefix");
}
Testing with SoapUI, the returned XML is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<prefix:MyResponseObject xmlns:prefix="http://..url">
<field>my field content</field>
</prefix:MyResponseObject>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Unfortunately, for some reason that's beyond my control, the systems who calls my service, expects the prefix namespace in the envelope, so something like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prefix="http://..url">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<prefix:MyResponseObject>
<field>my field content</field>
</prefix:MyResponseObject>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This brings to my problem. I need to manually modify the Envelope, but I can't find a way. Could someone help me?

How to upgrade java 8 SOAP call to java 11 SOAP call using feign

I'm moving from java 8 to java 11. I have integration with old style SOAP 1.2 service. Because of cutting of JEE web services stuff from java 11 extending from javax.xml.ws.Service and call super.getPort(new QName(...), SomeWebService.class, someFeatures); from generated sources is not working for me any more.
So I decided to use for this SOAP call OpenFeign https://github.com/OpenFeign/feign#soap , https://github.com/OpenFeign/feign/tree/master/soap
Service I would like to call is:
SOAP 1.2 based
charset is utf-8
Content-Type request: application/soap+xml
Content-Type response: application/xop+xml
The call I would like to do looks like this in plain xml:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc</wsa:To>
<wsa:Action>http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj</wsa:Action>
</soap:Header>
<soap:Body>
<ns:Zaloguj>
<ns:pKluczUzytkownika>theUsersKey</ns:pKluczUzytkownika>
</ns:Zaloguj>
</soap:Body>
</soap:Envelope>
What I did using OpenFeign was interface for connecting:
import my.domain.schema.cis.bir.publ._2014._07.Zaloguj;
import feign.Headers;
import feign.RequestLine;
public interface MyWebServiceCallInterface {
#RequestLine("POST /")
#Headers({
"SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj",
"Content-Type: application/soap+xml"
})
String zaloguj(Zaloguj zaloguj);
}
Zaloguj class looks like this:
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"pKluczUzytkownika"
})
#XmlRootElement(name = "Zaloguj")
public class Zaloguj {
#XmlElementRef(name = "pKluczUzytkownika", namespace = "http://CIS/BIR/PUBL/2014/07", type = JAXBElement.class, required = false)
protected JAXBElement<String> pKluczUzytkownika;
public JAXBElement<String> getPKluczUzytkownika() {
return pKluczUzytkownika;
}
public void setPKluczUzytkownika(JAXBElement<String> value) {
this.pKluczUzytkownika = value;
}
}
and I have implemented service with SOAP calling:
public ResponseEntity callSOAPService() {
JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder()
.withMarshallerJAXBEncoding("UTF-8") .withMarshallerSchemaLocation("https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl")
.build();
MyWebServiceCallInterface myWebServiceCallInterface = Feign.builder()
.encoder(new SOAPEncoder(jaxbFactory))
.decoder(new SOAPDecoder(jaxbFactory))
.target(MyWebServiceCallInterface.class, "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc");
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> userKeyElement =objectFactory.createZalogujPKluczUzytkownika("topSecretUserKey");
Zaloguj zaloguj = new Zaloguj();
zaloguj1.setPKluczUzytkownika(userKeyElement);
String result = myWebServiceCallInterface.zaloguj(zaloguj);
}
But for this call I've received:
feign.FeignException$BadRequest: [400 Bad Request] during [POST] to [https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/] [MyWebServiceCallInterface#zaloguj(Zaloguj)]: []
I was trying to debug and in Feign SynchronousMethodHandler method executeAndDecode has a template field with value:
POST / HTTP/1.1
Content-Length: 511
Content-Type: application/soap+xml
SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj
<?xml version="1.0" encoding="UTF-8" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><Zaloguj xmlns="http://CIS/BIR/PUBL/2014/07" xmlns:ns2="http://CIS/BIR/PUBL/2014/07/DataContract" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl"><pKluczUzytkownika>b7e7df92129b4e25aeab</pKluczUzytkownika></Zaloguj></SOAP-ENV:Body></SOAP-ENV:Envelope>
and in Feign ErrorDecoder method decode has request field with value:
POST https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc/ HTTP/1.1
Content-Length: 511
Content-Type: application/soap+xml
SOAPAction: http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj
<?xml version="1.0" encoding="UTF-8" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><Zaloguj xmlns="http://CIS/BIR/PUBL/2014/07" xmlns:ns2="http://CIS/BIR/PUBL/2014/07/DataContract" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://wyszukiwarkaregon.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl-ver11-prod.wsdl"><pKluczUzytkownika>b7e7df92129b4e25aeab</pKluczUzytkownika></Zaloguj></SOAP-ENV:Body></SOAP-ENV:Envelope>
Maybe some on of You know how to fix it?
Did I make something wrong in my MyWebServiceCallInterface implementation?
I'm looking forward for Your advises!

Axis2 issue: xsi:type= returns on soap message when multiple web services exist in the same eclipse project

xsi:type comes back in the soap envelope when multiple web services exist in the same Eclipse project. The WSDL's don't appear to change, just how the soap message returns. Why? How can this be prevented?
Here is the java web service:
package com.fedins.certificateservice.service.certificatelist;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService(targetNamespace = "com.fedins.certificateservice.service.certificatelist")
//#Addressing(enabled = false)
public class CertificateListService {
public CertificateListService() {
super();
}
#WebMethod
// #WebResult(name = "CertificateList")
public Sparky[] getCertificateList() {
//List<Sparky> myReturn = new ArrayList<Sparky>();
Sparky[] myReturn = new Sparky[2];
Sparky myCert0 = new Sparky();
myCert0.setGoober("2342342");
myReturn[0] = myCert0;
//myReturn.add(myCert0);
Sparky myCert10 = new Sparky();
myCert10.setGoober("2342343434342");
myReturn[1] = myCert10;
//myReturn.add(myCert10);
System.out.println("ME WANT CAKE");
return myReturn;
}
}
Here is the second web service:
package com.fedins.certificateservice.service.franklist;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService()
public class FrankListService {
public FrankListService() {
super();
}
#WebMethod
public String getFrankList() {
return "pokemon";
}
}
This is an example when multiple services are in the Eclipse project:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dlwmin:getCertificateListResponse xmlns:dlwmin="com.fedins.certificateservice.service.certificatelist" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<return xsi:type="sparky">
<goober>2342342</goober>
</return>
<return xsi:type="sparky">
<goober>2342343434342</goober>
</return>
</dlwmin:getCertificateListResponse>
</soapenv:Body>
</soapenv:Envelope>
This is an example of when only this service is in the Eclipse project:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dlwmin:getCertificateListResponse xmlns:dlwmin="com.fedins.certificateservice.service.certificatelist" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<return>
<goober>2342342</goober>
</return>
<return>
<goober>2342343434342</goober>
</return>
</dlwmin:getCertificateListResponse>
</soapenv:Body>
</soapenv:Envelope>

Consume REST web service using POST call returns 415

I am pretty new to REST based web services. I am trying to call a small REST WS that I created the start of which looks as below
package webServices;
import java.net.UnknownHostException;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.json.JSONException;
import org.json.JSONObject;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
#Path("/login")
public class LoginService {
#Path("/isUp")
#GET
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String checkServiceStatus(){
return "up and running";
}
#Path("/authenticate")
#POST
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String authenticateUser(#FormParam("user") String user, #FormParam("password") String pwd){
DB db;
DBCollection coll;
MongoClient mongoClient;
String loginResponse="user does not exist";
try {
mongoClient = new MongoClient( "localhost" , 27017 );
db = mongoClient.getDB( "Hackathon" );
coll = db.getCollection("users");
BasicDBObject filter = new BasicDBObject();
filter.put("user", user);
BasicDBObject selectField = new BasicDBObject();
selectField.put("password", 1);
selectField.put("_id", 0);
DBCursor cursor = coll.find(filter, selectField);
String jsonString = cursor.next().toString();
JSONObject json = new JSONObject(jsonString);
String password = json.getString(user);
System.out.println("password "+password);
if(password.equals(pwd)){
loginResponse="success";
System.out.println("success");
}else{
loginResponse="failure";
System.out.println("failure");
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return loginResponse;
}
}
Whenever I call the POST service same from Chrome postman using form-data
http://localhost:8080/HackDataEngine/login/authenticate
Content-Type application/json
user admin
password admin
POSTMAN call screenshot
I get below response
<html>
<head>
<title>Apache Tomcat/7.0.67 - Error report</title>
<style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
</style>
</head>
<body>
<h1>HTTP Status 415 - Unsupported Media Type</h1>
<HR size="1" noshade="noshade">
<p>
<b>type</b> Status report
</p>
<p>
<b>message</b>
<u>Unsupported Media Type</u>
</p>
<p>
<b>description</b>
<u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u>
</p>
<HR size="1" noshade="noshade">
<h3>Apache Tomcat/7.0.67</h3>
</body>
</html>
You need to set the Headers correctly at Postman.
At your request tab, press Headers and set a new variable like this.
Content-Type -> application/json
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
Try to use one of them, for sample only MediaType.APPLICATION_JSON
For beginning with Rest Service this is a top tutorial:
http://crunchify.com/how-to-build-restful-service-with-java-using-jax-rs-and-jersey/
Thanks everyone for their quick responses ... The JSON type paremeter passing works. In case the original approach has to be debugged I did the following change in method parameter signature and it worked
public String authenticateUser(#FormParam("user") String user, #FormParam("password") String password)
previously it was
public String authenticateUser(#FormParam("user") String user, #FormParam("password") String pwd)

Exception in thread "main" javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable

I get the following exception when I execute the REST Client :
InboundJaxrsResponse{ClientResponse{method=GET, uri=http://localhost:8080/com.dcr.jersey.first/webapi/todo, status=406, reason=Not Acceptable}}
Exception in thread "main" javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable
On web browser( when tomcat is running), the URL : http://localhost:8080/com.dcr.jersey.first/webapi/todo gives output
todo>
<description>This is my first todo - Description</description>
<summary>This is my first todo - Summary</summary>
</todo>
But running the client code throws the exception, what is the mapping that's missing here?, appreciate your guidance( included all code samples)
Here is the web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<!-- <param-value>com.dcr.jersey</param-value> -->
<!-- <param-value>com.dcr.jersey.first</param-value> -->
<param-value>com.dcr.jersey.jaxb.model</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
Here is the TodoResourceCliient executed:
package com.dcr.jersey.client;
import java.net.URI;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.glassfish.jersey.client.ClientConfig;
public class TodoResourceCliient {
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
System.out.println(target.path("webapi").path("todo").request()
.accept(MediaType.TEXT_PLAIN).get(Response.class)
.toString());
System.out.println(target.path("webapi").path("todo").request()
.accept(MediaType.TEXT_HTML).get(String.class));
System.out.println(target.path("webapi").path("todo").request()
.accept(MediaType.TEXT_XML).get(String.class));
System.out.println(target.path("webapi").path("todo").request()
.accept(MediaType.TEXT_PLAIN).get(String.class));
System.out.println(target.path("webapi").path("todo").request()
.accept(MediaType.APPLICATION_JSON).get(String.class));
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/com.dcr.jersey.first").build();
}
}
TodoResource.java:
package com.dcr.jersey.jaxb.model;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/todo")
public class TodoResource {
#GET
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Todo getXML() {
Todo todo = new Todo();
todo.setSummary("This is my first todo - Summary\n");
todo.setDescription("This is my first todo - Description\n");
return todo;
}
// This can be used to test the integration with the browser
#GET
#Produces({ MediaType.TEXT_XML,MediaType.TEXT_PLAIN,MediaType.TEXT_HTML})
public Todo getHTML() {
Todo todo = new Todo();
todo.setSummary("This is my first todo - Summary\n");
todo.setDescription("This is my first todo - Description\n");
return todo;
}
}
Todo.java:
package com.dcr.jersey.jaxb.model;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Todo {
private String summary;
private String description;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
Stacktrace from Console :
InboundJaxrsResponse{ClientResponse{method=GET, uri=http://localhost:8080/com.dcr.jersey.first/webapi/todo, status=500, reason=Internal Server Error}}
Exception in thread "main" javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1002)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:799)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:91)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:687)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:683)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:411)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:307)
at com.dcr.jersey.client.TodoResourceCliient.main(TodoResourceCliient.java:27)
Dependencies included from pom.xml: am I missing any dependencies ?
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
</dependencies>
See Http Status Codes
406 Not Acceptable
The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
The .accept(mediatype) is what set the Accept header for the request. You currently have five requests, each accepting a different type
MediaType.TEXT_PLAIN,MediaType.TEXT_HTML, MediaType.TEXT_XML, MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON
This is Content-Negotiation at work. The server side configuration of this is with the use of the #Produces (which goes in hand with the Accept header) and #Consumes(which goes in hand with the Content-Type header).
That being said, look at all your #Produces annotations. You currently only support the producing of media types
MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON
The missing ones are in bold above. Remove those, and given all else is correct, this should work for you.
Check your content type!
Setting to .accept(MediaType.TEXT_PLAIN) worked for me.
As correctly stated by peeskillet, your client calls with accept(MediaType.TEXT_PLAIN) and accept(MediaType.TEXT_HTML) will cause issues since your TodoResource methods do not specify these media types in the #Produces annotation.
Either
change your TodoResource class to support these media types
change your client code to remove the calls corresponding to these media types

Categories