Reading Jira Webhook POST data - java

I am trying to read Jira issue data using a webhook that posts the data to my servlet.
When I travserve the request parameters map, I don't find anything in it.
But the content lenght shows as "8876" which means webhook is sending the data. Somehow I am not able to read/retrieve the data in my servlet.
Also checked, content-type returns as "application/json".
Does anyone know how to read Jira webhook post data?

You have to read the response body, not the parameters map. For that purpose you can use
request.getInputStream();
or
request.getReader();
method.
PS: You can configure the web hook to post data to http://requestb.in/ so you can easily analyze the request parameters, the request body, the headers, etc.

Related

How to read response data in an Undertow HttpServerExchange object?

I have implemented a reverse proxy with Undertow server.
I want to edit the absolute URLs in the response from target host before sending back to client.
I've used exchange.addResponseCommitListener(httpHandler) so that exchange object contains response from the proxied server and the response hasn't been sent to the client yet.
In httpHandler, I'm able to see the exact length of the proxied response with exchange.getResponseContentLength() but unable to find any function that reads the response data.
I've checked the implementation of exchange.getResponseContentLength() but its only giving the value from one of response headers Content-Length.
Can anyone please help me how to retrieve the response data that has been proxied. Thanks

java httpServer Post request work

I'm start learning java programming, and I want make a simple server application. I read about com.sun.net.httpserver.HttpServer and find a good example on this link: https://github.com/imetaxas/score-board-httpserver-corejava.
I understand how to do Get-request in url, but I don't know how POST works. I think it must be sent a form or data on the server.
I attach the link of project, which I'm learning, in readme the author wrote http://localhost:8081/2/score?sessionkey=UICSNDK - it's not working...
I wrote in url and get sessionkey: "localhost:8081/4711/login --> UICSNDK"
I wrote in url this for Post request: "localhost:8081/2/score?sessionkey=UICSNDK" - not working and in chrome return 404 bad request
3.wrote in url this:"localhost:8081/2/highscorelist"
Please help me, I am beginner.
The difference between GET and POST is that with a GET request the data you wish to pass to the endpoint is done by modifying the url itself by adding parameters to it.
With a POST any data you wish to send to the endpoint must be in the body of the request.
The body of a request is arbitrary data that comes after a blank line in the header The reqiest has the request line, following by any number of header attributes, then a blank line.
The server would need to know what the format of the body of the request was and parse it as appropriate.
Of course 'modern' frameworks like jax-rs allow you to automatically convert request data to objects, so that it is much simpler.

How to send the json data in GET request thru browser/Postman?

I need to send the json object in get request. I installed chrome Postman extension but i am not getting how can i send json object in GET request ?
Postman provides the way to send json data in Post request by adding the header as application/json and then add the json data under raw form.
How to send the json data in GET request ? Do i need to append it in URL ?
It's bad solution to send any objects using get request. But you can send it as a url parameter using url encoding:
String url = "http://example.com/query?json=" + URLEncoder.encode(json, "UTF-8");
In POSTMAN you can send body data in GET request. If you try to append in the URL using url encoding you will get error.
Try to convert json object into string and send it in the URL parameters and see if it works.
Also if your backend server allows only to send data as URL parameters and your URL is long (i.e approx 2048 characters) then I am not sure whether this will work.
If above solution doesn't work then I think you can achieve this using curl. CURL is a tool for doing all sorts of URL manipulations and transfers. You can generate cURL code using Postman. Here is the reference
You can use google chrome Postman Extension
it allows you to send and see any type of data.

Obfuscate rest response using bson

I am using REST API for searching. When an ajax call is fired, REST returns json from Java code
return JResponse.ok(searchResult).build() //searchResult is List of Custom object
In javascript I would stringfy that json and parse to show relevant data on screen.
var search = jQuery.parseJSON(JSON.stringify(data));
Now I want to secure/obfuscate json response returned from REST, so that anyone who directly hits APIs won't get readable response. I tried bson but bot able to implement it successfully. Didn't find much support on how to put collection object in bson and how to retrieve it back in JS while googling.
I will suggest you to go with tokens.
Every time when request made to server request must contain a token which change for every request as well check that the request header for ajax request. If it is an ajax request then and then only return result. Also add rule for no cross browser access.
I think if you did it your data will not be accessible to anyone by direct http request.

Java - send HTTP POST request without downloading all the content

Is it possible to send HTTP POST request to a webserver and retrieve just headers of response or read just few bytes of the body, so the rest won't be downloaded at all (so it won't consume traffic)? If yes, how?
I know that there is a HEAD method for this, but I need to achieve it by POST method .. well, I am not sure if I need the POST method, I just need to post the data. Maybe if the webserver isn't secured well enough (it doesn't check what method it's used - it's just directly access the post data), is it possible to send "post data" by HEAD request?
There is no built-in HTTP mechanism for this, and HTTP HEAD requests do not allow content in the body. If however you are the one writing the server code then anything is possible.
If this is the case, I would suggest a URL parameter that triggers this behavior. For example:
POST /myURL - This would return the whole response
POST /myURL?body=minimal - Returns the reduced size response that you are looking for.
And you would have to code your server method to construct and return the appropriate response based on the URL parameter.

Categories

Resources