I need to create an HTTP adapter to work, but the URL must be programmatically provided with a parameter.
1) I was able to pass the user / password, but not the URL. Is there any way to do this?
I am also trying to create my own Java adapter to call the REST API. It works when I test the adapter, but it seems that my answer is not in the expected format to work. I got this error:
2) BAD_PARAMETER_EXPECTED_DOCUMENT_OR_ARRAY_OF_DOCUMENT.
my Java adapter returns JSONArtifact (JSONObject), but it seems that this process requires it to be embedded in another JSONObject, such as {"array": {...}}. Is there a way to convert JSONObject into the format expected at work.
import org.apache.wink.json4j.JSON;
import org.apache.wink.json4j.JSONArtifact;
import org.apache.wink.json4j.JSONException;
private Header headerUserAgent = new Header ("User-Agent", "Mozilla");
private Header headerAccept = new Header ("Accept", "application / json");
private String hostName;
private String baseURL;
protected MyHttpClient (String userName, String userPassword, String hostName, String baseURL) {
super ();
Credentials defaultcreds = new UsernamePasswordCredentials (userName,
userPassword);
this.getState (). setCredentials (AuthScope.ANY, defaultcreds);
this.hostName = hostName;
this.baseURL = baseURL;
}
private GetMethod getGetMethod (String url) throws URIException {
GetMethod httpMethod = new GetMethod (new HttpsURL ("https: //" + hostName + baseURL + url) .getEscapedURI ());
addCommonHeaders (httpMethod);
return httpMethod;
}
private JSONArtifact getResponseAsJSONObject (InputStream inputStream) throws IOException {
InputStreamReader reader = new InputStreamReader (inputStream);
try {
JSONArtifact json = JSON.parse (reader);
return json;
} catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
return null;
}
Adapter:
function getResponse (user, password) {
var client = new com.itdove.mypackage.MyHttpClient (user, password, "myurl", "mybaseurl");
return {
array: client.executeGet ("mypath")
};
}
it works with this, but this solution does not provide the service url as a parameter:
function getResponseAdapters(path, username, password) {
var input = {
method : 'get',
returnedContentType : 'json',
headers: {
'User-Agent':'Mozilla',
'Authorization': 'Basic '+Base64.encode(username+':'+password),
} ,
path : '/resources/' + path
};
return WL.Server.invokeHttp(input);
}
function getResponse(username, password) {
return getMySCAWSAdapters(path, username, password);
}
Collection
vAPPArrayAdapterOptions = {
name: 'myResponseAdapter',
replace: '',
remove: '',
add: '',
load: {
procedure: 'getResponse',
params: ["user","password"],
key: 'array'
},
accept: function (data) {
return (data.status === 200);
}
},
...
vAPPArray = wlJsonStore.initCollection(
"vAPPArray",
vAPPArraySearchFields,
{adapter: vAPPArrayAdapterOptions,
onSuccess: initCollectionSuccessCallback,
onFailure: initCollectionFailureCallback,
load:true});