Receiving request parameters as null for SOAP API in STS - spring-boot

I'm calling an endpoint from SOAP-UI for a POST request.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fet="http://www.example.com/fetchMKDataRequest.xsd">
<soapenv:Header/>
<soapenv:Body>
<fet:fetchMKDataRequest>
<fet:MKDataList>
<fet:CompanyCode>123</fet:CompanyCode>
<fet:PersonnelAreaCode>XYZ</fet:PersonnelAreaCode>
</fet:MKDataList>
</fet:fetchMKDataRequest>
</soapenv:Body>
</soapenv:Envelope>
My endpoint is recognised along with the request body. BUT the value of MKDataList appears null as shown below:
My Endpoint class looks like :
#Endpoint
public class FetchMKDataEndpoint {
private static final String NAMESPACE_URI = "http://example.com/fetchMKDataRequest.xsd";
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "fetchMKDataRequest")
#ResponsePayload
public FetchMKDataResponse fetchMKData(#RequestPayload FetchMKDataRequest request) {
System.out.println("reached FETCHMKDATA endpoint");
FetchMKDataResponse response = new FetchMKDataResponse();
//commented block of code
return response;
}
}
Request model is as follows. It was generated using jaxb2-maven-plugin. I had to remove the annotations #XmlAccessorType(XmlAccessType.FIELD) & #XmlType for each class. Also I had to assign #XmlElement(name = "MKDataList", required = true), all such #XmlElements at respective GET methods. Without doing these 2 changes, i was getting x counts of IllegalAnnotationExceptions exception in SOAP-UI response.
#XmlRootElement(name = "fetchMKDataRequest", namespace="http://www.example.com/fetchMKDataRequest.xsd")
public class FetchMKDataRequest {
protected List<FetchMKDataRequest.MKDataList> MKDataList;
#XmlElement(name = "MKDataList", required = true)
public List<FetchMKDataRequest.MKDataList> getMKDataList() {
if (MKDataList == null) {
MKDataList = new ArrayList<FetchMKDataRequest.MKDataList>();
}
return this.MKDataList;
}
public void setMKDataList(List<FetchMKDataRequest.MKDataList> mKDataList) {
mKDataList = mKDataList;
}
public static class MKDataList implements Serializable {
private static final long serialVersionUID = 1L;
protected String companyCode;
protected String personnelAreaCode;
#XmlElement(name = "CompanyCode", required = true)
public String getCompanyCode() {
return companyCode;
}
public void setCompanyCode(String value) {
this.companyCode = value;
}
#XmlElement(name = "PersonnelAreaCode", required = true)
public String getPersonnelAreaCode() {
return personnelAreaCode;
}
public void setPersonnelAreaCode(String value) {
this.personnelAreaCode = value;
}
}
}
Can anything be done to get MKDataList object in the request body as NOT null?
Thanks in advance

I made changes in my request model and added package-info.java in the request model package.
Request model class:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = { "mkDataList" })
#XmlRootElement(name = "fetchMKDataRequest", namespace="http://www.example.com/fetchMKDataRequest.xsd")
public class FetchMKDataRequest {
#XmlElement(name = "MKDataList", required = true)
protected List<FetchMKDataRequest.MKDataList> mkDataList;
public List<FetchMKDataRequest.MKDataList> getMKDataList() {
if (mkDataList == null) {
mkDataList = new ArrayList<FetchMKDataRequest.MKDataList>();
}
return mkDataList;
}
public void setMkDataList(List<FetchMKDataRequest.MKDataList> mkDataList) {
this.mkDataList = mkDataList;
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"functionalAreaSubGroup",
"personnelAreaCode"
})
public static class MKDataList {
#XmlElement(name = "FunctionalAreaSubGroup", required = true)
protected String functionalAreaSubGroup;
#XmlElement(name = "PersonnelAreaCode", required = true)
protected String personnelAreaCode;
public String getFunctionalAreaSubGroup() {
return functionalAreaSubGroup;
}
public void setFunctionalAreaSubGroup(String value) {
this.functionalAreaSubGroup = value;
}
public String getPersonnelAreaCode() {
return personnelAreaCode;
}
public void setPersonnelAreaCode(String value) {
this.personnelAreaCode = value;
}
}
}
package-info.java:
#javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.com/fetchMKDataRequest.xsd", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.example.model.request;
This worked for me. You can define multiple namespaces in 'package-info' class for multiple request/response models.

Related

org.hibernate.exception.DataException: could not execute query in spring boot and Data JPA

When I am trying to implement the JPQL query, I am getting the following error,
{
"message": "could not execute query; SQL [select alerts0_.nalert_id as nalert_i1_0_, alerts0_.bis_active as bis_acti2_0_, alerts0_.dalert_date as dalert_d3_0_, alerts0_.ndept_to as ndept_to4_0_, alerts0_.ninst_to as ninst_to5_0_, alerts0_.nreceiver_id as nreceive6_0_, alerts0_.nsender_id as nsender_7_0_, alerts0_.nsubdept_to as nsubdept8_0_, alerts0_.salert_action_data as salert_a9_0_, alerts0_.salert_desc as salert_10_0_, alerts0_.salert_subject as salert_11_0_, alerts0_.salert_type as salert_12_0_ from alerts alerts0_ where alerts0_.ninst_to=?]; nested exception is org.hibernate.exception.DataException: could not execute query",
"error": "Internal Server Error",
"path": "/spacestudy/rockefeller/control/alerts/getAlertDetails"
}
And my repository query is like the following,
#Query("SELECT a FROM Alerts a")
public List<Alerts> findByAlertType();
When I hard-coded Query like #Query("SELECT a FROM Alerts a WHERE a.nreceiverId = 649"), then also getting the same error.
And I am calling this query in my service like the following:
alert= alertsRepositoryObj.findByAlertType();
And my model class Alerts.java like the following:
#Entity
#Table(name="alerts")
public class Alerts implements Serializable
{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY, generator = "alerts_seq_generator")
#SequenceGenerator(name = "alerts_seq_generator", sequenceName = "alerts_seq",allocationSize=1)
#Column(name="nalert_id",columnDefinition="serial")
public Integer nalertId;
#Column(name="salert_desc")
public String salertDesc;
#NotNull
#Column(name="nsender_id")
public Integer nsenderId;
#Column(name="dalert_date")
public LocalDate dalertDate;
#Column(name="salert_subject")
public String salertSubject;
#Column(name="salert_action_data")
public String salertActionData;
#Column(name="salert_type")
public String salertType;
#Column(name="ninst_to")
public Integer ninstTo;
#Column(name="ndept_to")
public Integer nDeptTo;
#Column(name="nsubdept_to")
public Integer nsubdeptTo;
#Column(name="nreceiver_id")
public Integer nreceiverId;
#NotNull
#Column(name="bis_active")
public Boolean bisActive=true;
#ManyToOne(optional = true)
#JoinColumn(name = "salert_action_data", insertable = false, updatable = false)
public RoomTransfer roomTransfer;
public Integer getNalertId()
{
return nalertId;
}
public void setNalertId(Integer nalertId)
{
this.nalertId = nalertId;
}
public String getSalertDesc()
{
return salertDesc;
}
public void setSalertDesc(String salertDesc)
{
this.salertDesc = salertDesc;
}
public Integer getNsenderId()
{
return nsenderId;
}
public void setNsenderId(Integer nsenderId)
{
this.nsenderId = nsenderId;
}
public LocalDate getDalertDate()
{
return dalertDate;
}
public void setDalertDate(LocalDate dalertDate)
{
this.dalertDate = dalertDate;
}
public String getSalertSubject()
{
return salertSubject;
}
public void setSalertSubject(String salertSubject)
{
this.salertSubject = salertSubject;
}
public String getSalertActionData()
{
return salertActionData;
}
public void setSalertActionData(String salertActionData)
{
this.salertActionData = salertActionData;
}
public String getSalertType()
{
return salertType;
}
public void setSalertType(String salertType)
{
this.salertType = salertType;
}
public Integer getNinstTo()
{
return ninstTo;
}
public void setNinstTo(Integer ninstTo)
{
this.ninstTo = ninstTo;
}
public Integer getnDeptTo()
{
return nDeptTo;
}
public void setnDeptTo(Integer nDeptTo)
{
this.nDeptTo = nDeptTo;
}
public Integer getNsubdeptTo()
{
return nsubdeptTo;
}
public void setNsubdeptTo(Integer nsubdeptTo)
{
this.nsubdeptTo = nsubdeptTo;
}
public Integer getNreceiverId()
{
return nreceiverId;
}
public void setNreceiverId(Integer nreceiverId)
{
this.nreceiverId = nreceiverId;
}
public Boolean getBisActive()
{
return bisActive;
}
public void setBisActive(Boolean bisActive)
{
this.bisActive = bisActive;
}
public RoomTransfer getRoomTransfer()
{
return roomTransfer;
}
public void setRoomTransfer(RoomTransfer roomTransfer)
{
this.roomTransfer = roomTransfer;
}
public Alerts()
{
super();
}
}
Why this error happening? Since this is a simple JPQL query. How can I trouble shoot the exact error here?

Spring Rest -> Hibernate entity to JSON

I am creating REST API using spring framework. My entity is based on one table and REST API is supposed to be invoked using POST operation with below JSON structure. Can someone explain me how to map the entity class so that it can consume below-shown json.
Since my entity is based on only one table, I am not able to understand how can it create nested json objects for same table properties.
{
"process_ar_receipt": {
"message_header": {
"source_system_guid": "DDED-DBCD-REV-E1F4343DB3434",
"source_system": "MeSo_TravelAds"
},
"receipt_header": {
"customer_number": "123",
"source_receipt_number": "TESTRCPT_1523",
}
}
}
you could use Gson to convert the json to a DTO
https://jarroba.com/gson-json-java-ejemplos/
pseudo code
assuming your Entity class as
#Entity(name="foo")
class Data{
#Id
private String source_system_guid;
#Column
private String source_system;
#Column
private String customer_number;
#Column
private String source_receipt_number;
public Data() {}
public Data(String ssId, String sourceSystm, String custNum, String srcRcptNum) {
this.source_system_guid = ssId;
this.source_system = sourceSystm;
this.customer_number = custNum;
this.source_receipt_number = srcRcptNum;
}
public String getSource_system_guid() {
return source_system_guid;
}
public void setSource_system_guid(String source_system_guid) {
this.source_system_guid = source_system_guid;
}
public String getSource_system() {
return source_system;
}
public void setSource_system(String source_system) {
this.source_system = source_system;
}
public String getCustomer_number() {
return customer_number;
}
public void setCustomer_number(String customer_number) {
this.customer_number = customer_number;
}
public String getSource_receipt_number() {
return source_receipt_number;
}
public void setSource_receipt_number(String source_receipt_number) {
this.source_receipt_number = source_receipt_number;
}
}
Now since your DTO/BO i.e. Data Transfer Object or Business Object is different from the actual entity we will create the required BO object as below
class DataTO{
#JsonProperty("process_ar_receipt")
private ReceiptTO receiptTO=new ReceiptTO();
public ReceiptTO getReceiptTO() {
return receiptTO;
}
public void setReceiptTO(ReceiptTO receiptTO) {
this.receiptTO = receiptTO;
}
}
class ReceiptTO{
#JsonProperty("message_header")
private MessageHeader messageHeder = new MessageHeader();
#JsonProperty("receipt_header")
private ReceiptHeader receiptHeder = new ReceiptHeader();
public MessageHeader getMessageHeder() {
return messageHeder;
}
public void setMessageHeder(MessageHeader messageHeder) {
this.messageHeder = messageHeder;
}
public ReceiptHeader getReceiptHeder() {
return receiptHeder;
}
public void setReceiptHeder(ReceiptHeader receiptHeder) {
this.receiptHeder = receiptHeder;
}
}
class MessageHeader{
#JsonProperty("source_System_Guid")
private String sourceSystemId;
#JsonProperty("system_Id")
private String systemId;
public String getSourceSystemId() {
return sourceSystemId;
}
public void setSourceSystemId(String sourceSystemId) {
this.sourceSystemId = sourceSystemId;
}
public String getSystemId() {
return systemId;
}
public void setSystemId(String systemId) {
this.systemId = systemId;
}
}
class ReceiptHeader{
#JsonProperty("customer_number")
private String customerNumber;
#JsonProperty("source_rcpt_number")
private String sourceReceiptNumber;
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public String getSourceReceiptNumber() {
return sourceReceiptNumber;
}
public void setSourceReceiptNumber(String sourceReceiptNumber) {
this.sourceReceiptNumber = sourceReceiptNumber;
}
}
The #JsonProperty annotation is imported from org.codehaus.jackson.annotate.JsonProperty; i.e from jackson jar
Now a Simple Test class to demo DTO/BO back and forth Entity conversion
public class Test{
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
List<Data> datas = new ArrayList<Data>();
datas.add(new Data("DDED-DBCD-REV-E1F4343DB3434","MeSo_TravelAds","123","TESTRCPT_1523"));
datas.add(new Data("ADED-EWQD-REV-E1F4343YG3434","FooSo_MusicAds","132","TESTRCPT_1523"));
datas.add(new Data("YDED-YUTR-REV-E1F43UIDB3434","BarSo_HealthAds","143","TESTRCPT_1523"));
List<DataTO> dataTOs = new ArrayList<DataTO>();
for (Data data : datas) {
DataTO dataTO = new DataTO();
dataTO.getReceiptTO().getMessageHeder().setSourceSystemId(data.getSource_system_guid());
dataTO.getReceiptTO().getMessageHeder().setSystemId(data.getSource_system());
dataTO.getReceiptTO().getReceiptHeder().setCustomerNumber(data.getCustomer_number());
dataTO.getReceiptTO().getReceiptHeder().setSourceReceiptNumber(data.getSource_receipt_number());
dataTOs.add(dataTO);
}
ObjectMapper mapper = new ObjectMapper();
String str = mapper.writeValueAsString(dataTOs);
System.out.println(str);
}
}
This will give you below result
[
{
"process_ar_receipt":{
"message_header":{
"source_System_Guid":"DDED-DBCD-REV-E1F4343DB3434",
"system_Id":"MeSo_TravelAds"
},
"receipt_header":{
"customer_number":"123",
"source_rcpt_number":"TESTRCPT_1523"
}
}
},
{
"process_ar_receipt":{
"message_header":{
"source_System_Guid":"ADED-EWQD-REV-E1F4343YG3434",
"system_Id":"FooSo_MusicAds"
},
"receipt_header":{
"customer_number":"132",
"source_rcpt_number":"TESTRCPT_1523"
}
}
},
{
"process_ar_receipt":{
"message_header":{
"source_System_Guid":"YDED-YUTR-REV-E1F43UIDB3434",
"system_Id":"BarSo_HealthAds"
},
"receipt_header":{
"customer_number":"143",
"source_rcpt_number":"TESTRCPT_1523"
}
}
}
]
similarly the other conversion
String input = "{ \r\n" +
" \"process_ar_receipt\":{ \r\n" +
" \"message_header\":{ \r\n" +
" \"source_System_Guid\":\"ADED-EWQD-REV-E1F4343YG3434\",\r\n" +
" \"system_Id\":\"FooSo_MusicAds\"\r\n" +
" },\r\n" +
" \"receipt_header\":{ \r\n" +
" \"customer_number\":\"132\",\r\n" +
" \"source_rcpt_number\":\"TESTRCPT_1523\"\r\n" +
" }\r\n" +
" }\r\n" +
" }";
DataTO dataTO = mapper.readValue(input, DataTO.class);
System.out.println(dataTO.getReceiptTO().getMessageHeder().getSourceSystemId());
System.out.println(dataTO.getReceiptTO().getMessageHeder().getSystemId());
System.out.println(dataTO.getReceiptTO().getReceiptHeder().getCustomerNumber());
System.out.println(dataTO.getReceiptTO().getReceiptHeder().getSourceReceiptNumber());
this will print
ADED-EWQD-REV-E1F4343YG3434
FooSo_MusicAds
132
TESTRCPT_1523
You dont have to use the mapper code you can directly add the jackson converter as HttpMessageConverted which will convert the JSON to java object automatically
#Configuration
#EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
... other configurations
#Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.serializationInclusion(JsonInclude.Include.NON_NULL);
builder.propertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
builder.serializationInclusion(Include.NON_EMPTY);
builder.indentOutput(true).dateFormat(new SimpleDateFormat("yyyy-MM-dd"));
converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
converters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
}
}

Error Spring React REST Controller Using Custom Class Response (WebFlux)

I'm trying to build a Spring WebFlux project and realize the follow business logic:
1 - Call an external REST Api using WebClient and parse the Json results using the Models below. It is working OK
2 - To show the Mono results Mono<DeviceList> devices, I'm using the ResponseApi class and returning it, but it is NOT working
I'm getting the follow error:
Response status 406 with reason "Could not find acceptable representation"
Thanks
# Json Result
{
"data": [
{
"id": "5bc3c0efe833d93f401bafa8",
"name": "XXXXX",
"group": "5b8fd1fa0499f54cfa7febb8",
"description": "Geolocalizacao gps",
"payloadType": "None",
"contract": "5bc08be5e833d93f40e1f936",
"keepAlive": 0
}
]
}
# Controller
public class DeviceController{
...
...
#RequestMapping(value = V1 + BASE_URL + "/devices/types", method = GET, produces = APPLICATION_JSON)
public Mono<ServerResponse> getDeviceTypes(){
Mono<DeviceList> devices = deviceService.findDeviceTypes();
ResponseApi r = new ResponseApi();
r.setMessage("Test");
r.setCode("200");
r.setStatus(200);
r.setData(devices);
return ok().body(Mono.just(r), ResponseApi.class);
}
}
# Repository
public Mono<DeviceList> findDeviceTypes() {
return webClient.get()
.uri(DEVICE_TYPES_URL)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(DeviceList.class);
}
# Model
public class DeviceList{
#JsonProperty("data")
private List<Device> data;
public List<Device> getData() {
return data;
}
public void setData(List<Device> data) {
this.data = data;
}
}
public class Device{
#JsonProperty("id")
private String id;
#JsonProperty("name")
private String name;
#JsonProperty("group")
private String group;
#JsonProperty("description")
private String description;
#JsonProperty("keepAlive")
private Integer keepAlive;
#JsonProperty("payloadType")
private String payloadType;
#JsonProperty("contract")
private String contract;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getKeepAlive() {
return keepAlive;
}
public void setKeepAlive(Integer keepAlive) {
this.keepAlive = keepAlive;
}
public String getPayloadType() {
return payloadType;
}
public void setPayloadType(String payloadType) {
this.payloadType = payloadType;
}
public String getContract() {
return contract;
}
public void setContract(String contract) {
this.contract = contract;
}
}
#JsonRootName("data")
public class ResponseApi{
#JsonProperty("status")
private Integer status;
#JsonProperty("code")
private String code;
#JsonProperty("message")
private String message;
#JsonProperty("data")
private Object data;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
You can get devices, then in non blocking way, map them to the ResponseApi like that:
#RequestMapping(value = V1 + BASE_URL + "/devices/types", method = GET, produces = APPLICATION_JSON)
public Mono<ServerResponse> getDeviceTypes(){
return deviceService.findDeviceTypes()
.flatMap(devices -> {
ResponseApi r = new ResponseApi();
r.setMessage("Test");
r.setCode("200");
r.setStatus(200);
r.setData(devices);
return ok().body(Mono.just(r), ResponseApi.class);
});
}

Marshal list of objects of different types with JAXB

I work with Spring and JAXB and want to marshal a list of different DTO Objects so
the required XML response should be like :
<root>
<dto_list>
<dto1>
<name>xxx</name>
</dto1>
<dto2>
<location>xxx</location>
</dto2>
</dto_list>
</root>
Assuming the Class Objects are:
#XmlRootElement(name = "Dto1")
#XmlAccessorType(XmlAccessType.NONE)
public class Dto1 {
#XmlElement
private String name;
// setter/getters
}
and
#XmlRootElement(name = "Dto2")
#XmlAccessorType(XmlAccessType.NONE)
public class Dto2 {
#XmlElement
private String location;
// setter/getters
}
and the wrapper class:
#XmlRootElement(name = "root")
#XmlAccessorType(XmlAccessType.NONE)
public class DTOsWrapper {
private List<Object> dto;
public void setDto(List<Object> dto) {
this.dto = dto;
}
#XmlElementWrapper(name = "dto_list")
#XmlElements({
#XmlElement(name = "dto1", type = Dto1.class),
#XmlElement(name = "dto2", type = Dto2.class)
})
public List<Object> getDto() {
return dto;
}
}
and the endpoint:
#RestController
public class DTOEndpoint {
#Autowired
private IDTOService service;
#RequestMapping(value = "/restxml", produces = "application/xml")
public Object retrieveAllDTOs() {
DTOsWrapper o = service.findDtos(); //returns a DTOsWrapper obj of a list containing Dto objs, i.e Dto1, Dto2 etc
return o;
}
I get {"error": "org.springframework.http.converter.HttpMessageConversionException: Could not instantiate JAXBContext for class [class <>to.DTOsWrapper]: 1 counts of IllegalAnnotationExceptions; anyone have a clue?

smartgwt listgrid RestDataSource not populating

Im new using this front end framework application...
I recently started to work with smartgwt and i'm bulding a new application with a Spring MVC integration.
I'm using a ListGrid with a RestDataSource (Consume the Rest service with mvc:annotation-driven for plain JSON)
I can see that the servaice gets consuming properly perhaps my grid is never shown with the data in it.
Can someone help me here ?
Here's my ListGrid class
public class ListGrid extends com.smartgwt.client.widgets.grid.ListGrid {
private final SpringJSONDataSource springJSONDataSource;
public ListGrid(List<DataSourceField> fields) {
this(new PatientDataSource(fields));
}
public ListGrid(SpringJSONDataSource springJSONDataSource) {
this.springJSONDataSource = springJSONDataSource;
init();
}
private void init() {
setAutoFetchData(true);
setAlternateRecordStyles(true);
setEmptyCellValue("???");
setDataPageSize(50);
setDataSource(springJSONDataSource);
}
}
Now there's the DataSource implmentation
public abstract class SpringJSONDataSource extends RestDataSource {
protected final HTTPMethod httpMethod;
public SpringJSONDataSource(List<DataSourceField> fields) {
this(fields, HTTPMethod.POST);
}
public SpringJSONDataSource(List<DataSourceField> fields, HTTPMethod httpMethod) {
this.httpMethod = httpMethod;
setDataFormat(DSDataFormat.JSON);
addDataSourceFields(fields);
setOperationBindings(getFetch());
addURLs();
}
private void addURLs() {
if(getUpdateDataURL() != null)
setUpdateDataURL(getUpdateDataURL());
if(getRemoveDataURL() != null)
setRemoveDataURL(getRemoveDataURL());
if(getAddDataURL() != null)
setAddDataURL(getAddDataURL());
if(getFetchDataURL() != null)
setFetchDataURL(getFetchDataURL());
}
private void addDataSourceFields(List<DataSourceField> fields) {
for (DataSourceField dataSourceField : fields) {
addField(dataSourceField);
}
}
protected abstract OperationBinding getFetch();
protected abstract OperationBinding getRemove();
protected abstract OperationBinding getAdd();
protected abstract OperationBinding getUpdate();
public abstract String getUpdateDataURL();
public abstract String getRemoveDataURL();
public abstract String getAddDataURL();
public abstract String getFetchDataURL();
}
The class PatientDataSource that extends SpringJSONDataSource
public class PatientDataSource extends SpringJSONDataSource {
public PatientDataSource(List<DataSourceField> fields) {
super(fields);
setPrettyPrintJSON(true);
}
#Override
protected OperationBinding getFetch() {
OperationBinding fetch = new OperationBinding();
fetch.setOperationType(DSOperationType.FETCH);
fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
DSRequest fetchProps = new DSRequest();
fetchProps.setHttpMethod(httpMethod.toString());
fetch.setRequestProperties(fetchProps);
return fetch;
}
#Override
public String getFetchDataURL() {
return "/spring/fetchPatients";
}
#Override
protected OperationBinding getRemove() {
return null;
}
#Override
public String getRemoveDataURL() {
return null;
}
#Override
protected OperationBinding getAdd() {
return null;
}
#Override
public String getAddDataURL() {
return null;
}
#Override
protected OperationBinding getUpdate() {
return null;
}
#Override
public String getUpdateDataURL() {
return null;
}
}
My spring controller PatientControler
#Controller
public class PatienController {
Logger logger = Logger.getLogger(PatienController.class);
#Autowired
private PatientServices patientServices;
#RequestMapping(value = "/patientTest", method = RequestMethod.GET)
#ResponseBody
public Object getTest()
{
return patientServices.getAllPatients();
}
#RequestMapping(value = "/fetchPatients", method = RequestMethod.POST)
#ResponseBody
public Object getAllPatients()
{
return patientServices.getAllPatients();
}
}
PatientServiceImpl
public class PatientServicesImpl implements PatientServices {
public List<Patient> getAllPatients() {
List<Patient> patients = new ArrayList<Patient>();
Patient patient;
for(int i = 0 ; i < 500 ; i++){
patient = new Patient();
patient.setDateOfBirth(new Date());
patient.setFirstName("Joe");
patient.setMiddleName("Moe");
patient.setLastName("Blow");
patient.setLastConsultation(new Date());
patient.setSex(Sex.M);
patients.add(patient);
}
return patients;
}
}
*Im Really stuck right now i've been looking for all type of answers .... but so far nothing worked when i tried to override the transformResponse from my RestDataSource impentation the parameter "data" as an OBJECT, returns me an array [object Object],[object Object],[object Object],[object Object],[object Object] *
The Data which is transferred from the RestDataSource has a specific format which is described in the JavaDoc of the RestDataSource
Your server must understand the request and send back a valid response.
At the moment your example doesn't seem to honour the contract.
To debug the traffic send to and from your server you can use the SmartClient-Console. You can open it by a browser bookmark like this:
javascript:isc.showConsole()
Of cause you need to deploy this console by adding the following module to your gwt.xml
<inherits name="com.smartclient.tools.SmartClientTools"/>
Now go to the RPC Tab and check Track-RPCs

Resources