Reputation: 271
I created a web service and I'll call another web service from inside. According to response media type that call from inside, I return my real response.
But whatever I do, all response returned as JSON object.
My web service class is;
@RestController
@RequestMapping("/changeservicemode")
public class ChangeServiceMode {
@RequestMapping(method = RequestMethod.GET)
public Response changeMode(@RequestHeader(value = "serviceUrl") String serviceUrl,
@RequestHeader(value = "serviceMode") String serviceMode) {
IVirtualDocumentService docService = UtilsForSpring.getSingleBeanOfType(IVirtualDocumentService.class);
VirtualDocument documentByUrl = docService.findDocumentByVirtualUrl(serviceUrl);
String mediaType = MediaType.APPLICATION_XML;//I'll get media type from another response that will call above code in this point
if (documentByUrl == null) {
return Response.status(Status.NOT_FOUND).type(mediaType).entity("This url not found on DB!").build();
}
if (SimulationMode.LEARN.equalsIgnoreCase(serviceMode)) documentByUrl.setSimulationMode(SimulationMode.LEARN);
if (SimulationMode.SIMULATE.equalsIgnoreCase(serviceMode)) documentByUrl.setSimulationMode(SimulationMode.SIMULATE);
if (SimulationMode.STOP.equalsIgnoreCase(serviceMode)) documentByUrl.setSimulationMode(SimulationMode.STOP);
docService.save(documentByUrl);
String entity = "url: " + serviceUrl + ", mode: " + documentByUrl.getSimulationMode();
return Response.status(Status.OK).entity(entity).type(mediaType).build();
}
}
here is my response;
{
"context": {
"headers": {
"Content-Type": [
{
"type": "application",
"subtype": "xml",
"parameters": {},
"wildcardSubtype": false,
"wildcardType": false
}
]
},
"entity": "url: http://localhost:8066/virtual/wsapi/personelvirtual/getallpersonels, mode: SIMULATE",
"entityType": "java.lang.String",
"entityAnnotations": [],
"entityStream": {
"closed": false,
"committed": false
},
"length": -1,
"language": null,
"location": null,
"lastModified": null,
.
.
.
. continue..
Upvotes: 1
Views: 816