In mobilefirst 7.0 I succesfully created a soapadapter starting from a wsdl URL.
The web server expose some operations, some work fine but one. I debugging on the webserver side an I see that a complex type is missing one object. Debugging with Mobile Browser Simulator I can see that the post request to mobilefirst server contains the json object I created by javascript. The json object contain an array of objects and a second object. The first object, the array, succesfully reach the webservice, but not the second one.
Is there a way to debug what the adapter does?
This is the prototype of the service:
{
"iscriviUtente": {
"iscrizione": {
"intestatari": {
"item": {
"cciaa": "someValue",
"censito": "someValue",
"codiceFiscale": "someValue",
"formaGiuridica": "someValue",
"partitaIva": "someValue",
"ragioneSociale": "someValue",
"sede": "someValue"
}
},
"utente": {
"cap": "someValue",
"codiceFiscale": "someValue",
"cognome": "someValue",
"dataNascita": "someValue",
"dataScadenza": "someValue",
"email": "someValue",
"indirizzo": "someValue",
"localita": "someValue",
"luogoNascita": "someValue",
"nome": "someValue"
}
}
}
}
This is the javascript method I use to call the service:
function doIscriviUtente(utente, intestatari, options) {
var children = [];
for(i=0; i<intestatari.length; i++) {
var intestatario = intestatari[i];
var child = {
"cciaa": intestatario.cciaa,
"censito": intestatario.censito,
"codiceFiscale": intestatario.codiceFiscale,
"formaGiuridica": intestatario.formaGiuridica,
"partitaIva": intestatario.partitaIva,
"ragioneSociale": intestatario.ragioneSociale,
"sede": intestatario.sede
};
children[i] = child;
}
var param = [{
"iscriviUtente": {
"iscrizione": {
"intestatari": children,
"utente": {
"cap": utente.cap,
"codiceFiscale": utente.codiceFiscale,
"cognome": utente.cognome,
"dataNascita": utente.dataNascita,
"dataScadenza": utente.dataScadenza,
"email": utente.email,
"indirizzo": utente.indirizzo,
"localita": utente.localita,
"luogoNascita": utente.luogoNascita,
"nome": utente.nome
}
}
}
}];
var invocationData = {
adapter : soapAdapter,
procedure : soapProcedure+"iscriviUtente",
parameters : param
};
try {
WL.Client.invokeProcedure(invocationData, options);
} catch(e) {
if (options.onFailure)
options.onFailure(WL.App.getErrorMessage(e));
}
}
The webservice receive the parameter "iscrizione" which contains the array of "intestatari" and a a "utente" object that's null, as the soap adapter failed to compose the soap message.
you are missing an "item" in your javascript method. The code below should work properly.
var param = [{
.......
"intestatari": { "item": children},
.......
}];
Related
I have recently started using Ktor and got stuck at the very beginning itself.
I have a very simple response, which could have content like below -
{
"result": true,
"data": [
{
"Name": "Danish",
"Credit": "80"
},
{
"Name": "Kumar",
"Credit": "310"
}
]
}
Or it could be like this -
{
"result": false,
"data": [],
"message": "No data available, use default user",
"default": [
{
"Name": "Default User",
"Credit": "100"
}
]
}
And my response class is like -
#Serializable
data class UserResponse(
#SerialName("result") var result: Boolean? = null,
#SerialName("data") var data: ArrayList<User?>? = null,
#SerialName("message") var message: String? = null,
#SerialName("default") var default: ArrayList<User?>? = null
)
#Serializable
data class UserResponse(
#SerialName("Name") var name: String? = null,
#SerialName("Credit") var credit: String? = null,
)
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel
And I am getting NoTransformationFoundException, I think it could be due to data object being empty, but how to fix this?
According to this, we can catch this exception, but I can't use this as I need other data to be used.
Exception looks like you haven't install Json content negotiation plugin, when creating ktor client. It should be like this:
val httpClient = HttpClient {
install(ContentNegotiation) {
json()
}
}
Then you can use this client like this:
val response: UserResponse = httpClient.get("URL").body()
I have a SQL Server stored procedure that has an ID parameter and returns a string in JSON format that is needed in the Angular app.
Here is a sample of the JSON needed:
[
{
"type": "date",
"name": "asofdate",
"ui":
{
"label": "As Of Date",
"placeholder": "Enter a date"
},
"validators": { "required": "true" }
},
{
"type": "select",
"name": "scope",
"ui": { "label": "Scope", "placeholder": "Select a scope" },
"validators": { "required": "true" },
"source": [
{ "value": 1, "text": "ABC" },
{ "value": 2, "text": "CDE" },
{ "value": 3, "text": "FGI" }
]
}
]
Here is a what the result of running the stored procedure looks like:
When I run the Web API passing the ID parameter to the stored procedure, I would like to capture the response as a JSON object to be used in the Angular app.
But the Web API is returning this:
[
{
"jsonResponse": "[
{
\"type\":\"date\",
\"name\":\"asofdate\",
\"ui\":{\"label\":\"As Of Date\",\"placeholder\":\"Enter a date\"},
\"validators\":{\"required\":\"true\"}
}
,
{
\"type\":\"select\",
\"name\":\"scope\",
\"ui\":{\"label\":\"Scope\",\"placeholder\":\"Select a scope\"},
\"validators\":{\"required\":\"true\"},
\"source\":[{\"value\":1,\"text\":\"ABC\"},{\"value\":2,\"text\":\"DEF\"},{\"value\":3,\"text\":\"GHI\"}]}
}
]
Is there a way to get the JSON response from the Web API without all the "\" and without:
{
"jsonResponse": "
so that it matches the sample above?
Here is the code from the Web API:
[HttpGet("{ReportID}")]
public async Task<ActionResult<IEnumerable<usp_ReportParameterResult>>> GetReportParameters(int ReportID)
{
if (_context.usp_ReportParameterAsync == null)
{
return NotFound();
}
var op = new OutputParameter<int>();
var JSONresponse = await _context.usp_ReportParameterAsync(ReportID, op);
if (JSONresponse == null)
{
return NotFound();
}
return JSONresponse;
}
The stored procedure uses JSON_QUERY and JSON PATH to create the needed nested arrays.
So, in the angular code I have the following hard-coded:
TESTDATA:any[] = [
{
type:'text',
name:'firstName',
validators:{
required:true
},
ui:{label:'First Name',placeholder:'Enter Your First Name'}
}
,
{
"type":"date",
"name":"asofdate",
"ui":{"label":"****As Of Date","placeholder":"Enter a date","class":["date-picker-wrapper"]},
"validators":{"required":"true"}
}
]
What I need is instead of this data being hrad-coded it is being dynamically generated from a Web API.
The hard-coded data looks like the following from browser debug:
[![enter image description here][2]][2]
From the web api data looks like the following:
It is not an array like the TESTDATA. Is the a way to get response from web api into an array format as required?
Actually, easiest solution was to remove the backlashes in the Angular app by simply doing the following:
for (let item of this.formattedJSON) {
item.ui = JSON.parse(item.ui);
item.validators = JSON.parse(item.validators);
}
I am using Vk Api, and during 1 scenario I am getting a response object with code 200, but body of it's an Error JSON.
I want to ask you - is it possible to somehow get the error object from response and look at the error_code that has been returned from the Vk Api.
I am using Retrofit 2 on android and GsonConverterFactory.
I am trying to do something like this:
class NetworkCheckerInterceptor(val networkChecker: NetworkChecker) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val requestBuilder = chain.request().newBuilder()
if (!networkChecker.isConnected()) {
throw NoNetworkConnectionException("No network connection.")
}
try {
val response = chain.proceed(requestBuilder.build())
val error = Gson().fromJson(response.body()?.string(), Error::class.java)
return response
} catch (e: SocketTimeoutException) {
throw SocketTimeoutException()
} catch (e: UnknownHostException) {
throw UnknownHostException()
}
}
}
But I am getting error when I am trying to get 'Error' object.
Json error example:
{
"error": {
"error_code": 7,
"error_msg": "Permission to perform this action is denied",
"request_params": [
{
"key": "oauth",
"value": "1"
},
{
"key": "method",
"value": "stats.get"
},
{
"key": "timestamp_to",
"value": "1542549195"
},
{
"key": "month",
"value": "month"
},
{
"key": "group_id",
"value": "56461699"
},
{
"key": "v",
"value": "5.87"
},
{
"key": "interval",
"value": "month"
},
{
"key": "stats_groups",
"value": "visitors"
},
{
"key": "timestamp_from",
"value": "1514757660"
}
]
}
}
The only thing I care about is "error_code": 7 it's about permition problem.
So, how can I get this object even if my response code is 200 ?
You can create base class for VK network response
abstract class BaseVkResponse<T> {
var response: T? = null
var error: VKError? = null // (from vk sdk)
}
and each response should extend it. For example
class NewsItem {
var type: String? = null
var text: String? = null
var date: Long? = null
}
class NewsPage {
var items: List<NewsItem>? = null
#SerializedName("nextFrom")
var nextFrom: String? = null
}
class NewsResponse : BaseVkResponse<NewsPage>()
and retrofit interface looks like
interface VkService {
#GET("newsfeed.getRecommended")
fun getNews(#Query("access_token") accessToken: String,
#Query("v") apiVersion: String,
#Query("count") count: Int?,
#Query("start_from") startFrom: String?): Single<NewsResponse>
}
Then register special type adapter to parse VkError type
internal class ErrorTypeAdapter : JsonDeserializer<VKError> {
#Throws(JsonParseException::class)
override fun deserialize(json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext
): VKError? {
return try {
VKError(JSONObject(json.toString()))
} catch (e: JSONException) {
null
}
}
}
val gson = GsonBuilder().apply {
registerTypeAdapter(VKError::class.java, ErrorTypeAdapter())
}
If response's error field is not null, you should handle it as you wish. In other cases you can treat it as successful.
I wrote a custom controller to handle a GET http://localhost:54000/api/v1/portfolios/{id}/evaluate request.
#RequestMapping(value = "/portfolios/{id}/evaluate", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> evaluate(#PathVariable Long id) {
Portfolio portfolio = portfolioService.evaluate(id);
if (portfolio == null) {
return ResponseEntity.notFound().build();
}
Resource<Portfolio> resource = new Resource<>(portfolio);
resource.add(entityLinks.linkForSingleResource(Portfolio.class, id).withSelfRel());
return ResponseEntity.ok(resource);
}
The current response is
{
"summary" : {
"count" : 24.166666666666668,
"yield" : 0.14921630094043895,
"minBankroll" : -6.090909090909091,
"sharpeRatio" : 0.7120933654645042,
"worstReturn" : -2.4545454545454533,
"losingSeason" : 3,
"return" : 3.6060606060606077
},
"_links" : {
"self" : {
"href" : "http://localhost:54000/api/v1/portfolios/4"
}
}
}
but I would like to add collection resources (summaries and systems) linked to that portfolio:
{
"summary": {
"count": 24.166666666666668,
"yield": 0.14921630094043895,
"minBankroll": -6.090909090909091,
"sharpeRatio": 0.7120933654645042,
"worstReturn": -2.4545454545454533,
"losingSeason": 3,
"return": 3.6060606060606077
},
"_links": {
"self": {
"href": "http://localhost:54000/api/v1/portfolios/4"
},
"portfolio": {
"href": "http://localhost:54000/api/v1/portfolios/4"
},
"summaries": {
"href": "http://localhost:54000/api/v1/portfolios/4/summaries"
},
"systems": {
"href": "http://localhost:54000/api/v1/portfolios/4/systems"
}
}
}
I did not find a way to generate those links with the RepositoryEntityLinks entityLinks object
You can always do something like this:
entityLinks.linkForSingleResource(Portfolio.class, id).slash("systems").withRel("systems");
And if your systems endpoint is implemented in a custom controller method you can use the ControllerLinkBuilder to generate a link to your controller method. Lets say you implemented the getSystems method with id parameter in MyControllerClass - then you can generate the link like this (linkTo and methodOn are static methods in ControllerLinkBuilder):
linkTo(methodOn(MyControllerClass.class).getSystems(id)).withRel("systems");
I am currently trying to setup ember to interact with Django's REST Framework using the ember-django-adapter.
This works flawless. But since I started using djangorestframework-gis, ember is not able to process the responses anymore.
I have not found anyone building geoJSON with ember except for: https://gist.github.com/cspanring/5114078 But that does not seem to be the right approach because I do not want to change the data model?
This is the api-response:
{
"type": "FeatureCollection",
"features": [
{
"id": 1,
"type": "Feature",
"geometry": {
"coordinates": [
9.84375,
53.665466308594
],
"type": "Point"
},
"properties": {
"date_created": "2014-10-05T20:08:43.565Z",
"body": "Hi",
"author": 1,
"expired": false,
"anonymous": false,
"input_device": 1,
"image": "",
"lat": 0.0,
"lng": 0.0
}
}
]
}
While ember expects something like:
[{"id":1,
"date_created":"2014-10-05T20:08:43.565Z",
"body":"Hi",
"author":1,
"expired":false,
"anonymous":false,
"input_device":1,
"image":"",
"lat":0,
"lng":0
}
]
My take on this was to write my own Serializer:
import Ember from "ember";
import DS from "ember-data";
export default DS.DjangoRESTSerializer.extend({
extractArray: function(store, type, payload) {
console.log(payload);
//console.log(JSON.stringify(payload));
var features = payload["features"];
var nPayload = [];
for (var i = features.length - 1; i >= 0; i--) {
var message = features[i];
var nmessage = {"id": message.id};
for(var entry in message.properties){
var props = message.properties;
if (message.properties.hasOwnProperty(entry)) {
var obj = {}
nmessage[entry]=props[entry];
}
}
nPayload.push(nmessage);
};
console.log(nPayload); //prints in the format above
this._super(store, type, nPayload);
},
})
But I receive the following error:
The response from a findAll must be an Array, not undefined
What am I missing here? Or is this the wrong approach? Has anyone ever tried to get this to work?
An alternative would be to handle this on the serverside and simply output a regular restframework response and set lat and long in the backend.
This is not a valid answer for the question above. I wanted to share my solution anyways,
just in case anyone ever gets into the same situation:
I now do not return a valid geoJSON, but custom lat, lng values. The following is backend code for django-rest-framework:
Model:
#models/message.py
class Message(models.Model):
def lat(self):
return self.location.coords[1]
def lng(self):
return self.location.coords[0]
And in the serializer:
#message/serializer.py
class MessageSerializer(serializers.ModelSerializer):
lat = serializers.Field(source="lat")
lng = serializers.Field(source="lng")
Ember can easily handle the format.