test connection with OData without getting any data - java

I was wondering, is there some way to get just the response from OData server, preferably with odata4j client, without any particular data actually being sent? I can request the server for metadata, but that's kind of wasteful, since it sends lot of data.
I want to send request and get response that would tell me if authorisation is correct and whether the server generally responds correctly, but I don't want to ask for any particular data. I know I could ask for something random, that's not very elegant though.

Check out the HTTP HEAD method.

Related

How a REST client can parse huge JSON response in REST web services

If a REST API is sending huge JSON (like 1000 fields) and if client is interested in only 10 fields. What will be the best way to parse the xml at client side?
If the server is using GraphQL, then the client can directly request the 10 fields.
Otherwise, you would use a streaming/JSON token parsing library rather than reading the entire response into memory
If you have different subscribers to your API who need different set of data then GraphQL is your ultimate answer.
There are 2 ways of approaching the problem. You can tell your client that they can implement an abstraction layer, called backend for frontend (BFF), in their system. In this BFF, they can send necessary fields to their client-side application.
Another option; if you don't want to lose your client and you want to keep your REST API, your client can define what data fields they need via querystring and in your system you manage the complexity and return customized response.
api/{resource}/fields=name,email,zipcode

Get data from FIX protocol in mobile apps

I need to create an app which get's it's displayed data from FIX protocol in real time.
How would be best practice to accomplish this?
Should the mobile app read directly the FIX data?
Should I put a server in between to transform the FIX data to JSON or something more prepared for service consumption? And if so... how would I do it to not lose the real time? Creating a websocket in Java which for the mobile apps to call and that websocket would transform the FIX data to JSON that way?
I never worked with the FIX protocol before by the way.
So like, the question is, can you put a FIX client on a mobile phone? I guess you can, and I am sure it will happen soon.
Yes, anything can read FIX data, it's simply text stream name value pairs, where the name is a numbered tag to identify some particular financial data or process, as agreed between the FIX community as a whole, or between direct counterparties using messaging data dictionaries.
These days you could try using SBE throughout, including at the mobile client, but for now current practise is yes, to use JSON for client endpoints (where the JSON name is not a FIX tag but the underlying FIX field name so it's easier for people to understand) and pass JSON messages to the mobile device in some kind of REST data processing.
So yeah, you'd have a FIX server (if you are new to FIX try QuickFix) to connect with your provider. Then what you need between that server and mobile clients is asynchronous messaging. Consider a quote request is not a simple request / response where you can block the request thread until a single response is received, it's a request followed by a stream of many responses. So you want an event handler style to route the responses back to clients asynchronously. With many mobile UI clients making requests and receiving responses you need to demultiplex the responses from the 1 FIX server out to the many mobile clients. That's something that QuickFIX itself kind of already does using a session layer. You need to do the same using sessions or identifiers in the messages you're passing around.
Yeah I guess websockets are intended to be that solution for real time. You could write a native mobile app though, using something like node or react to handle the message events.

Servlets - Send Response Based on Session Only

I get a request from one client, I want to build a response and send it to two clients (one of which is the requester). The only piece of information I know about the other client is its session. Is there a way to construct a HttpResponse object using an HttpSession object?
Im not sure about what youre trying to accomplish, but you may want to contact the second client via "reversal ajax". You may want to take a look at Comet Programming
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Wikipedia

What's the best way to let the Ajax app know of the errors back at server?

Hi
I'm working on an application with Java as it's server-side language and for the client-side I'm using Ajax.
But I'm fairly new to ajax applications so I needed some opinions on the issue I've faced.
I'm using Spring Security for my authentication and authorization services and by reading spring forums I've managed to integrate Spring Security with Ajax application in a way that ajax requests can be intercepted and relevant action be taken.
Here's the issue: What is the best way to let the ajax application know that an error has occurred back at server. What I've been doing so far is that by convention I make random http 500+ errors. e. g. to prompt for login I return 550, and 551 for other issue and so forth. But I think this is not the right approach to this. What is the best approach for dealing with this situation?
If standard HTTP error codes (eg 401 Unauthorized) are rich enough, use them. Best not to make up your own HTTP error codes, they're meant to be fixed. If you need more info to be returned, you should return a richer object in the response body (serialized as eg JSON or XML) and parse the object on the client side.
In my experience, making up your own HTTP error codes is not the best approach.
I've known client and server-side HTTP protocol stacks to treat non-standard HTTP status codes as protocol errors.
A non-standard code is likely to lead to confusing error messages if they end up being handled as non-AJAX responses.
Similarly, using the "reason phrase" part of the response can be problematic. Some server-side stacks won't let you set it, and some client-side stacks discard it.
My preferred way of reporting errors in response to an AJAX request is to send a standard code (e.g. 400 - BAD REQUEST) with an XML, JSON or plain text response body that gives details of the error. (Be sure to set the response content type header ...)
If this a bug in your application or a hack that you want to protect from, just return a generic access error. Don't give detail of the error on the client as it could be used by the hacker to better understand how to abuse your API. This would confuse normal users anyway.
If this is to be normal application behaviour, it might be better to be sure that you fail gracefully by allowing to retry later (if it make sence), reconnect or reauthenticate. You should at least recognise if it is a disconnected error or an insuffiscient rights error, and display a nice looking explanation to the user.

Google protocol buffers and servlets

I am wondering how I can use google protocol buffers to accept a request and send a response back to a client? I am thinking about writing a servlet which will take a request.
Is the following trail of thought the correct way to implement this:
1. Have a .proto file which is the message definition for the incoming request.
2. Write a servlet which accepts this request, does various tasks like querying database
and then sends a response. Will this response require a separate .proto message definition with all the fields that make up the response?
3. Will the client just invoke the doGet() method of my servlet and pass the request, it should then return a response as a protobuff object?
Any suggestion or idea will be very much appreciated.
Typically you'd want a request message and a response message, yes. You'd also probably want a method name to describe the action - that's certainly how the built-in PB services work.
The client wouldn't invoke doGet() - it would make a request (probably a POST rather than a GET) and your servlet would receive it.
Now, ideally you could have a general "ProtocolBufferServlet" which could service the requests by handing them off to services implementing the appropriate interfaces.
I suggest you look at the documentation for Protocol Buffer services and the Java services generated code for more information. You could implement an RpcChannel which worked over servlets, or get the client to make the HTTP post directly. You'd probably use dependency injection of some kind at the server side to tell the servlet what was implementing the service.
HI,
I have this up and running. I ended up posting a http request as a post to my servlet. I was able to take the request protocol buffer, read the request, do some processing and then send back a response. It was actually really simple once I got it working. We used the 1 .proto file to define the request and response message structure.

Categories

Resources