RestDataSource : example XPath datasource
RestDataSource : example XPath datasource
Ejemplo de un restdatasource mas xpath y manejo de la respuesta con setResponseTransformHandler
public class CurrentUserDS extends RestDataSource {
private static CurrentUserDS instance = null;
public static User getCurrentUser() {
if (instance == null) {
instance = new CurrentUserDS();
}
instance.fetchData();
return null;
}
private CurrentUserDS() {
super();
setFields(new DataSourceTextField("key", "Key"),
new DataSourceTextField("identity", "Identity"),
new DataSourceTextField("nickname", "Nickname"));
setDataFormat(DSDataFormat.JSON);
setResponseTransformHandler(new ResponseTransformHandler() {
public void execute(DSResponse response, DSRequest request, Object data) {
String key = XMLTools.selectObjects(data, "response/data/key").get(0).toString();
String identity = XMLTools.selectObjects(data, "response/data/identity").get(0).toString();
String nickName = XMLTools.selectObjects(data, "response/data/nickname").get(0).toString();
//add logic here
}
});
}
}
Ejemplo de un restdatasource mas xpath y manejo de la respuesta con setResponseTransformHandler
public class CurrentUserDS extends RestDataSource {
private static CurrentUserDS instance = null;
public static User getCurrentUser() {
if (instance == null) {
instance = new CurrentUserDS();
}
instance.fetchData();
return null;
}
private CurrentUserDS() {
super();
setFields(new DataSourceTextField("key", "Key"),
new DataSourceTextField("identity", "Identity"),
new DataSourceTextField("nickname", "Nickname"));
setDataFormat(DSDataFormat.JSON);
setResponseTransformHandler(new ResponseTransformHandler() {
public void execute(DSResponse response, DSRequest request, Object data) {
String key = XMLTools.selectObjects(data, "response/data/key").get(0).toString();
String identity = XMLTools.selectObjects(data, "response/data/identity").get(0).toString();
String nickName = XMLTools.selectObjects(data, "response/data/nickname").get(0).toString();
//add logic here
}
});
}
}
Comments
Post a Comment