JSONRPC format different between Jsonrpc4j and go's rpc/jsonrpc - java

I was meet a problem when I tried used net/jsonrpc package to build a server and a Java client with jsonrpc4j
The problem is jsonrpc4j is when error happen, golang`s method will return error and encoding to json.
I got this json object in client
{"id": -6028374044949000, "result": null, "error": "some error return message"}
This object cast failed in java's json4j.
http://www.jsonrpc.org/specification#error_object
After I checked the jsonrpc page, it is said the error field MUST a json object with fields [code, message, date], the golang jsonrpc package not meet the require.
So I`m confused how to solve this.
Change the jsonrpc lib,
Just replace the rpc way to thrift/gRpc,
Avoid to return error but send error in reply and let Java check the response,
Or just edited the json4j or golang's source code ( I'm very horrible about this option)
Thanks for watch.

If you need JSON-RPC 2.0 support for Go you can try https://github.com/powerman/rpc-codec

Related

Unable to retrieve data from Sabre PriceQuoteServicesRQ 4.10 SOAP API: XML request schema validation failed: PriceQuoteInfo element is not complete

I have a problem when trying to retrieve data from Manage Price Quote Details (PriceQuoteServicesRQ) 4.10 Sabre SOAP API.
I generated Java classes using the WSDL from Sabre website (https://developer.sabre.com/docs/soap_apis/air/fulfill/manage_price_quote_details/resources).
I am constructing my request object in a following way:
ReservationTypeShort reservation = new ReservationTypeShort();
reservation.setValue("YEZUYS");
PriceQuoteInfoSearchParameters info = new PriceQuoteInfoSearchParameters();
info.setReservation(reservation);
PriceQuoteSearchParameters searchParameters = new PriceQuoteSearchParameters();
searchParameters.getPriceQuoteInfo().add(info);
searchParameters.setResultType(StringResultType.S);
GetPriceQuoteRQ req = new GetPriceQuoteRQ();
req.setSearchParameters(searchParameters);
req.setVersion("4.1.0");
I pretty-printed the object and this is what I got:
"priceQuoteInfo" : [ {
"reservation" : {
"value" : "YEZUYS",
"createDate" : null
},
"status" : [ ],
"type" : null,
"priceQuote" : [ ],
"travelItinerary" : null
} ],
So according to their documentation:
I am supplying all fields that are necessary, however it still doesn't work for me.
Did anybody else had the same problem? What am I missing/what am I doing wrong?
This is the error message I am getting:
XML request schema validation failed: PriceQuoteInfo element is not complete. One of the following fields: Status, Type, PriceQuote, TravelItinerary should be used. Please amend your request and try again.
What I have tried so far?
I asked Sabre Support for help, but they responded with a message that basically says "it works on my end".
I intercepted the XML body:
<ns5:GetPriceQuoteRQ version="4.1.0">
<ns5:SearchParameters resultType="S">
<ns5:PriceQuoteInfo>
<ns5:Reservation>YEZUYS</ns5:Reservation>
</ns5:PriceQuoteInfo>
</ns5:SearchParameters>
</ns5:GetPriceQuoteRQ>
I was missing an empty element <PriceQuote/> in my request.
It can be added by doing:
PriceQuoteInfoSearchParameters info = new PriceQuoteInfoSearchParameters();
info.setReservation(reservation);
info.getPriceQuote().add(new PriceQuoteSearch());
So according to their documentation I am supplying all fields that are necessary [...]
By documentation do you mean the WSDL or some human readable documentation (like PDF, DOCX, web pages, etc)? According to the error message you get, your SOAP request isn't valid. Sabre Support responding with "it works on my end" is another way of saying that you are not doing something correctly on your end. You need to troubleshoot your request.
From what I see, the error message is saying Status, Type, PriceQuote, and TravelItinerary but you are sending status, type, priceQuote, and travelItinerary. XML is case sensitive, and it's possible the service field names are too, so this might be the first thing to check.
Then, two of your fields (type and travelItinerary) are null. Also, priceQuote is empty. Is that OK? This is the next thing to check.
The object you pretty-printed shows a JSON format. Is this actually the format you are sending on the wire to the service? SOAP wants XML, not JSON. You also mention you generated the code from the WSDL. Using what framework or library? Does the generated code send XML?
Like I said, you need to troubleshoot the call:
download SoapUI
feed the WSDL file to SoapUI so that it can generate sample requests for you
fill in those request with real data and make calls to the web service until you get back a successful and expected response
using the same parameters from 3) in your code, perform the same call using your code
use SoapUI's monitoring tools to intercept the request at 4) and inspect the SOAP message you are sending
check the request you are making with your code against the successful request you got by using SoapUI directly
correct any differences until your request made by code is like the one send from SoapUI and it returns a successful and expected response.

Why am I getting gson Exception: Expecting object found?

I am using the GSON API 1.7.1 sometimes having following error. Is there a bug for this version? Do I need to upgrade the current version 2.x.x
com.google.gson.JsonParseException: Expecting object found: "<!DOCTYPE"
at com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:100)
at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
at com.google.gson.JsonDeserializationContextDefault.fromJsonPrimitive(JsonDeserializationContextDefault.java:85)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:56)
The server is google push notification server GCM,
Here is my client code.
Gson gson = new Gson();
com.sun.jersey.api.client.ClientResponse webResponse=
resource.header("Authorization", authorizationKey).
header("Content-Type", MediaType.APPLICATION_JSON).
post(com.sun.jersey.api.client.ClientResponse.class, payloadStr);
String responsePayload = webResponse.getEntity(String.class);
GcmResponse response = gson.fromJson(responsePayload, GcmResponse.class); ===>>> Exception point
Is there a bug for this version?
No. Looks like your server is returning a non-JSON response or you're passing wrong parameters, this has nothing to do with the version you're using.
Try to check if the server is working as expected and is returning a JSON.
<!DOCTYPE is not valid Json; your server sometimes sends the wrong messages to your client. Since your client works 99% of the time, the problem is clearly in the server somehow, not the client.
However, since you've only provided us information here from the client side, there isn't enough for us to fix the problem. The best thing to do would be to attempt to capture the complete error message, then use searches or post a different question "Why does my android-scm server send messages that begin with <!DOCTYPE when they should be Json?"
To capture this complete errant message, I would do:
if(response.startsWith("<!DOCTYPE")) {
someLoggingMethod(response);`
} else {
// process the response

Error when sending the json object to Java server standalone application

I am sending the JSON object to server in a Java standalone application .
JSON object is :
{"dateFrom":"0001-01-01 12:00:00"
,"dateTo":"2014-03-29 04:34:49"
,"currency":"AUD"
,"requestStatus":null
,"dateTimeCreated":null
,"requestName":"ProjectedFundingRequest"
,"id":"af2e7ceb-c181-4a6b-a212-2867ea5cfded"
,"loginName":"mendiras"
,"securityToken":null
,"jsonString":null}
error : net.sf.json.JSONException: Error while setting property=requestStatus type class java.lang.String
Please let me know what could be the reason for the above error.
You are passing some null data in your JSON, Make sure server is accept this type of input otherwise at the time of server call it gives a error.
Set "requestStatus":null to "requestStatus":"",

REST API to pass indexed parameters for error messages

I'm designing a client and server system exchanging information using REST API. For i18n, the client to localized while server is always in English. In order to do that, only error code is sent from server to client and client will pick up the correct version of localized error message to display to the user.
Some error messages require indexed parameters. E.g. error message is "Can't find {0} on server {1}". I'm wondering what's the best practice to pass these indexed parameters (i.e. {0}, {1}) along with error code to the client so that the client can create the error message.
Can't you simply pass the errorcode + parameters in a single JSON object (or xml)?
{
"errorCode": "123",
"parameters": ["param0", "param1"]
}
Or am I missing something here?
Follow the suggestions from Nottingham & Wilde.
"This document defines a "problem detail" as a way to carry machine-readable details of errors in a HTTP response, to avoid the need to invent new error response formats for HTTP APIs."

How to send a unix path as part of a JSON object to a web service via GET

Sorry if this is a duplicate question but google isn't smart enough to understand me or I'm too dumb to express my question simple enough for it to understand.
I don't know if this is my problem but I'm 90% sure this is it.
I'd like to know how to represent a Unix path within a GET request so that my web service doesn't return a 404. I think it's because one of my JSON fields in the query is a Unix path and because of the slashes, the webservice thinks it's part of the URL and not a part of my query.
For example, I'm using a RESTClient that's an add-on to Mozilla to test my web service. For the POST request, I enter as the url
http://mytestserver:8080/mydir/
and in the body, I put in my JSON object
{"filename":"obit.jpg", "Path":"test/2/1"}
This method works fine. I get a status code 200 and a return JSON object with the expected output.
When I use the same string for a GET request, I get a status code 404 and no return JSON object. I put as the url in the RESTClient
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test/2/1"}
and I get a status code 404 and the response body just says 404 - Not found
To further test my theory, I entered the following url in a GET request, removing the /2/1 from the path, which works.
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test"}
I've tried encapsulating the whole JSON string in quotes but that didn't work either so I've run out of things to try.
Thanks in advance for any help you can give me. If I need to show some code, please let me know, although, I don't think it's a code problem, I think it's a representation problem. Thanks.
Found out that JSON objects are usually sent via POST, not GET. Since I appended it to the URL via GET, it gave me problems. Per How to send a GET request with a "/" in the query

Categories