Is it possible to mock two ports using Java version of Wiremock-standalone? - wiremock

I have an app which fetches some data from a url on port 8085. processes the data, then sends it to another url on port 8080 for another process, then processes the response from port 8080 again. Is it possible to have either wiremock or wiremock standalone work on both these ports? I can't find any solution for this in the docs but it seems to me it should be possible somehow. I have created a json file to handle the two URLs but I can't figure out a way to handle two ports. Any solution would be highly appreciated.

My understanding is that this is possible, by having two separate WireMock servers running on the two ports. This can be done either through the java WireMock or standalone WireMock. You'll simply need to specify the port.
java -jar wiremock-jre8-standalone-2.26.3.jar --port 8085 --rootdir /path/to/dir1
java -jar wiremock-jre8-standalone-2.26.3.jar --port 8080 --rootdir /path/to/dir2
The main thing to watch out for is that you'll need to have the servers looking to separate data folders. I've specified this in the CLI via the --rootdir flag. This can be set in java with .usingFilesUnderDirectory()
The part I'm curious about is why you have to have the data sent to a separate port. Could you not accomplish the same workflow by processing the data, sending it to a different endpoint, and then re-processing the data?

Related

Web sockets and Rest API in same Tomcat based application

I have read up on web sockets providing full duplex connections over TCP which can be used in scenarios where long polling was used to get live updates to client from server. Now I have a Tomcat based application which serves multiple REST based web service response, and I want couple of API's to be implemented using web sockets say to render dashboard with latest data where multiple users are working on them concurrently, is that possible ? My concern here was even if the connection was upgraded to TCP from HTTP wouldn't web socket require a separate port to run than the default Tomcat port 8080. In that case should I house the Web Socket based endpoints separate to the Tomcat based application already running. Please do correct me if any of the above is wrong.
A couple of month ago, I wrote a small Spring Boot webapp with embedded Tomcat that provides both, REST endpoints and websocket support, and both via the same port. So, yes that works... if you wanna sneak a peek: https://github.com/tommybrettschneider/pinterest-boot
Besides that, this post should also clarify things:
Shall I use WebSocket on ports other than 80?

How to find the port number in ubuntu 12.04?

I need to write my first socket program involving TCP connections. In the program I have created there is a client and server, both of which are the machine I am coding on.However,it requires that I pass the port number as a command line argument. How do I accomplish this?
The answer is simple : Make sure your server and your client agree on the port to use. As long as the port is available and can be used, set up the connected so that the client and server use that same port.
Here's a link that explain the different ranges available for TCP and UDP ports.
As an exemple, the port 3074 is used by microsoft for its Xbox live service. Making an application using this port might interfere with the service.
The port used will be defined either in a configuration file or hard-coded in the source code of both the server and the client. You should easily be able to find it with a quick look at the code or the directory which contains the application.

Can a Java web app listen to a tcp port in a local network?

forgive the triviality of my question. I was asked this question and I wasn't able to find a proper answer so I decided to research this myself and understand. I have spring ,maven etc background. Supposing I deployed my web app on a box 192.168.0.10 in my network, can I listen on the port say 9090 of the 192.168.0.10 and do something with it in my application itself running on tomcat7 on the usual port 8080.
What all this is supposed to do is listen on a port and display a graph on the client side based on the value received.
I was thinking using maven, I will have a jar packaged project handling the networking bit and transfer the control to the web app.Event that it's really blur in my mind.
Can anyone clarify things a little bit for me?
Thanks in advance
Why do you need a different port, effectively your web app is already callable on the port provided by tomcat. You can have various servlets each distinguished by URL, and one can return graphs. There's lots more possibilities, but I don't see any need for another port.

Making web application go Public

I have my web Application deployed in jboss web server. It contains Servlets. Right now its url is localhost:8080/MyWebApp I want to make it public so that the clients not in localhost can also access MyWebApp. I am new to this so I am not pretty sure about how to do this. I have browsed through many sites offering a domain but I dont understand where will my Server reside. Can I make my own System as Server and run jboss Server?
Regarding listening only on localhost, take a look at your startup scripts ; to make it listen on all the network interfaces you can use
run.sh -b 0.0.0.0
To listen only on a particular ip use
run.sh -b 1.2.3.4
Ideally you do not want users to access http://some_server:8080/MyWebApp but something like http://some_server/MyWebApp. To do this you will need to setup Apache with mod_jk and proxy the requests to jboss. If you have never done this before, it might be challenging. But there are plenty of resources on the internet to help you perform this task.

Is there a way to make it look like two programs are listening to port 80

I do know that I can't have two programs listening to the same port, but I am wondering if it is possible to fake it somehow, for an example:
My machine has two applications, one listening to port 80 and the other to port 6653.
If I get an incoming connection, let's say mysite.com:80/chat then it would be forwarded internally to the application listening on port 6653 and the data returned from that server would be forwarded back to port 80 somehow.
The reason I want to accomplish this is because there are many firewalls that seem to block connections to ports other than 80.
I have a chat server that I want to run on port 80, perhaps I could get another IP and machine for that, but it feels like too much trouble for a single chat server.
Any helpful feedback would be appreciated. Thanks!
You can probably do this with mod_rewrite if you're running Apache. That link has plenty of examples, including what you want (I think).
EDIT: I see you've updated the tags to say "asp.net". I'm guessing that you're not running Apache, then. I'm sure there is a similar tool for IIS, or you can use a proxy server that does the same thing.
There is a module called URL Rewrite that you can install on Windows Server 2008 (and R2) that is functionally the same as Mod_Rewrite. Download it here: http://www.iis.net/download/URLRewrite