POST payload over HTTPS connection in Spring - java

I am trying to connect to third party system over HTTPS connection and post parameters to receive a response. This is gonna be a POC I will be doing for which I am already started researching. I have already done a client-server TCP connection with an outbound gateway using SI in my spring application. Does SI provide a way to achieve HTTPS connection or is there any easier way, RestTemplate?
I could see Spring Integration - how to send POST parameters with http outbound-gateway, but it talks about HTTP rather than HTTPS.
Note: A linux server already communicates to this third party system using CURL. I need to replicate this communication in my spring application. Here is the sample Req / Res shared.
Request data: ord=000000&term=022&storenum=00623&fgen=667&action=1024&ctime=072119:22:23:32&tmout=08&PLU=00007565604633&BC=10364678071919225000623&QTY= 1.000
Response: 000000022006231024ctime=072119:22:23:32&itmz=P---11NSFU-T&desc=JARU ALL MN LT UP DIAMOND&rmfsline=1&avqty=1.0&barcode=10364678071919225000623&qty=1.0&rcptqty=3.0000&rcptline=5&upc=7565604633&reqqty=1.0&unitprice=1.97&price=5.91&dept=92&resp=00&POST /RMFSWeb/LineAuthListener? HTTP/1.1
Also, the URL shared with me is https://xx-cert.keb.com:20143 but this doesn't have a class/method name in the URL. Is it not required for an HTTPS connection?
Please share your thoughts on how I can achieve https connection from spring with the data above. Thanks for your help

RestTemplate with PostRequest will do all your job.
Refer an answer by 'Tharshan' in this post.
How to POST form data with Spring RestTemplate?

Related

SignalR (ASP .Net) - "The ConnectionId is in the incorrect format" - problem with websocket using own Java Websocket Client

I'm working on websocket integration to Bittrex - v3 API (https://bittrex.github.io/api/v3#topic-Authenticating). Bittrex websocket implementation is based on Microsoft ASP.net’s SignalR - they are not using ASP.net Core’s SignalR implementation.
I'm working on my own Java Client (based on Vert.x) because there is no available actual java client to SignalR.
I've encountered an problem. I want to connect with Bittrex websocket using my own websocket client developed in Java but I’m receiving 400 with information that “The ConnectionId is in the incorrect format”. I don’t know the SignalR protocol, I’ve only made some chrome debugging of bittrex website to get knowledge how can I connect using websocket.
How the process of the connection looks like in my case:
Step 1. I’m requesting for a connection token usign this GET request:
encoded: https://socket-v3.bittrex.com/signalr/negotiate?clientProtocol=2.0&connectionData=[{%22name%22:%22c3%22}]&_=1600500715881
decoded: https://socket-v3.bittrex.com/signalr/negotiate?clientProtocol=2.0&connectionData=[{"name":"c3"}]&_=1600500715881
Step: 2. Nest using the response like:
{"Url":"/signalr","ConnectionToken":"0kBiAOYeOtyGleCNodFQjl6TxKgBZy6o8RmI96GxteRH+GPfeycU+cyODS8YiAgpvCJ4RTmuQYh3Gr6TKo7U1K/nwi1CQxuaBroX0iF6j/wKxkeU","ConnectionId":"c79d4fa4-7518-4dc3-8884-0885598b105d","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"ConnectionTimeout":110.0,"TryWebSockets":true,"ProtocolVersion":"2.0","TransportConnectTimeout":5.0,"LongPollDelay":0.0}
I’m creating a request to establish WS connection using:
host: socket-v3.bittrex.com
port: 443
requestUri (encoded): /signalr/connect?transport=webSockets&clientProtocol=2.0&connectionToken=0kBiAOYeOtyGleCNodFQjl6TxKgBZy6o8RmI96GxteRH+GPfeycU+cyODS8YiAgpvCJ4RTmuQYh3Gr6TKo7U1K/nwi1CQxuaBroX0iF6j/wKxkeU&connectionData%3D%5B%7B%22name%22%3A%22c3%22%7D%5D&tid=0
requestUri (decoded): /signalr/connect?transport=webSockets&clientProtocol=2.0&connectionToken=0kBiAOYeOtyGleCNodFQjl6TxKgBZy6o8RmI96GxteRH GPfeycU cyODS8YiAgpvCJ4RTmuQYh3Gr6TKo7U1K/nwi1CQxuaBroX0iF6j/wKxkeU&connectionData=[{"name":"c3"}]&tid=0
(tid is always constant in the request)
Maybe someone also have the same problem. Do you have any idea what could be wrong? I was trying to put also a ConnectionId into the requestUri but it also did not help.
Thanks
Try use Percent-encoding(https://en.wikipedia.org/wiki/Percent-encoding) for connectionToken and connectionData

Test Soap webservice using jmeter with http request

i have a question for you guys, do you know a way how can i send http request with jmeter to my soap webservice(jax-ws library)?. I have a problem to point server name or ip(its localhost so should it be loopback?) and path. I'm using glassfish4 as my web server. I do not want to use option SOAP/XML RPC Request, because when i use it with my web service i can't see that any data have been sent(it's always 0 -in fact maybe you have idea why is that...it's also a solution to my problem because i need http request to see how much data i've sent)
!https://postimg.org/image/mpbai5n1v/
Thanks in advance
Regards!
Use:
Http Request and fill in:
Server Name or IP
IP if different from 443 or 80
Protocol if https
Add a Header Manager under it with :
Content-Type=text/xml; charset=utf-8
Note there is a template that lets you easily create this, see screenshot:
Finally I suggest you read this tutorial:
http://jmeter.apache.org/usermanual/build-ws-test-plan.html

Java standalone proxy program

I am making a proxy application for a browser. It has to use only the standard libraries. So far, I've managed to create the server. When trying to access a web page from a client, i get the following information:
CONNECT gmail.com:443 HTTP/1.1
User-Agent: Mozilla/5.0 Firefox/49.0
Proxy-Connection: keep-alive
Connection: keep-alive
Host: gmail.com:443
My question is: what to use in order to handle the requests? How to handle a file download?
Once you get that CONNECT command, do what is asked: create the upstream connection, and return the appropriate success/failure response. If the upstream connection was successful, all you have to do now is copy bytes in both directions, simultaneously. The endpoints will take care of all SSL issues, uploads, downloads, etc. You have no further role to play.
The general behaviour of a proxy is as follows:
Receive request from browser
Make a request to the actual server, resolving all redirects if necessary
Get the response from server and passit on to client
I am not getting into complications of changing request/response headers, caching etc.
Now from the above, you are making a SSL connection to gmail.com refer.
The browser is actually sending correct request, in this case you need to implement the handshake and connect to gmail with HTTPS offloading SSL on your side and sending the response received to the browser through the negotiated SSL with the browser.
Suggestion is to use HTTP instead of HTTPS, if this is not a production grader system and try out the concept first

How to test connection to server SSL port via proxy using Apache HttpClient 4.3.4?

I'm trying to validate an SSL connection to an http server through a proxy server. In my case, I have 4 pieces of information which are all supplied by the user, and which I'd like to validate explicitly: target host, target port, proxy host, proxy port. I'd prefer to NOT make an actual HTTP request in order to do this validation, since that requires 2 more pieces of information: a request method, and a path (ie. "GET /"). I'd really like to be able to use the HttpClient library because it supports NTLM proxy auth.
I suppose what I want is to get the response of a CONNECT request sent to the proxy server, as all it requires are the 4 pieces of information I have (plus any proxy creds). However this seems to be an implicit request, the result of which is not available to the library client (unless it returns a 407 status code). Is there some way to trigger the CONNECT request explicitly?
You can use ProxyClient shipped with Apache HttpClient. It does precisely that.

Spring RestTemplate on Jelastic - Connection Refused when requesting external rest service

I have application that need to call Rest service, to do authentication process. The service and my application are in a same server. I used Spring RestTemplate to call it. When it tested in localhost, it works perfectly. But when I deploy it to the cloud server (in this case, Jelastic) I get this error:
I/O error on GET request for "[my_rest_service_address]":Connection refused; nested exception is java.net.ConnectException: Connection refused
All the code is follow this doc : http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html. Only the url that changed to my rest url.
Is it happened because jelastic server blocked outbound request? But, both the service and my application are in the same server, why it still blocked?
Please explain to me, what is the problem? Thanks
The http 401 code means that the user that made the request is not authenticated. It can be the user of your webapp or the user used for the rest call.
It can for example that different credentials are used in prod and test, different security schemes in each environment, etc.

Categories