I am trying to mock an external service(my.domain.com:1234), which is called by WebClient. But I didn't figure out how to configure the host and port correctly. It seems only work with localhost and port: 8080. What did I missed?
#BeforeEach
void setUp() {
WireMockServer wireMockServer = new WireMockServer();
configureFor("localhost", 8080);
wireMockServer.start();
}
I wound be great if someone can show me a working code example. Thanks in advance.
Related
I am using the Vert.x Web library to create a test application for a reverse proxy. I am using the information provided on the Vert.x site:
https://vertx.io/docs/4.1.0/vertx-web-proxy/java/#_using_vert_x_web_proxy
I have written some simple test code, based on the documentation at the above site:
public class WebTest
{
public static void main(String[] args)
{
Vertx vertx = Vertx.vertx();
HttpClient client = vertx.createHttpClient();
HttpProxy proxy = HttpProxy.reverseProxy(client);
proxy.origin(8080,"localhost");
HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.route(HttpMethod.GET,"/foo").handler(ProxyHandler.create(proxy));
server.requestHandler(router);
server.listen(8010);
}
}
I have a web server (the so- called "origin" in Vert.x terminology) running on Port 8080. The only difference between the code above and the code on the web site is that I am using different port numbers for the proxy and the origin server. According to the documentation on the Vert.x website, a browser going to http://localhost:8010/foo should access the origin server.
Instead, I am getting 404 Not found errors.
Is there something missing in this code? Maybe something not covered in the documentation?
Does anyone have any idea how to make it work properly?
#Factor Three you are missing backend part of the guide and also you are mixing parts in an unorganized way. Following the guide it can be like this:
Vertx vertx = Vertx.vertx();
// Origin Server (Backend 8080)---------
// Here you deploy the real server with the endpoint ("hello world" in this case)
HttpServer backendServer = vertx.createHttpServer();
Router backendRouter = Router.router(vertx);
backendRouter
.route(HttpMethod.GET, "/foo")
.handler(
rc -> {
rc.response().putHeader("content-type", "text/plain").end("hello world");
});
backendServer.requestHandler(backendRouter).listen(8080);
// Proxy Server (8010)
// Here you deploy the server that will act as a proxy
HttpServer proxyServer = vertx.createHttpServer();
Router proxyRouter = Router.router(vertx);
proxyServer.requestHandler(proxyRouter);
proxyServer.listen(8010);
// Proxy Magic
// Here you route proxy server requests (8010) to the origin server (8080)
HttpClient proxyClient = vertx.createHttpClient();
HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient);
httpProxy.origin(8080, "localhost");
proxyRouter.route(HttpMethod.GET, "/foo").handler(ProxyHandler.create(httpProxy));
I wrote a simple client side program that creates a socket using
CFSteamCreatePairWithSocketToHost function
and connects to the server that runs on the local host on port 8080. It creates the socket just fine but it never connects to the server. I wrote the server in C. It didn't work and gave me a
kCFErrorDomainCFNetwork error 72000
and the only information that relays is that apparently the TCP connection couldn't be made don't know why though. So I tried to write the client side script in C too and added it to my Swift project bridging header and all but it still doesn't connect. It creates the socket just fine but it fails to connect to the server and I have no idea why.
But the same C client script worked when I compiled it using clang and ran it but didn't connect when I ran it with my swift project in Xcode. Is my mac blocking the libraries from making a TCP connection or something?
I don't even know what to search for. The only thing I found was an issue on a Github library called starscream which had the same errors I had and I'm not even using that library and the reply there was "the only thing we can discern from this error is that the TCP connection was unsuccessful".
Here's the code I used to connect to the server using Swift 4. The server is running on port 8080 on localhost.
class client:NSObject {
var inputstream = InputStream!
var outputstream = OutputStream!
func setupNetworkCom() {
var readstream = Unmanaged<CFReadStream>?
var writestream = Unmanaged<CFWriteStream>?
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, "localhost" as CFString, 8080, &readstream, &writestream)
inputstream = readstream!.takeRetainedValue()
outputstream = writestream!.takeReatainedValue()
inputstream.schedule(in: .current, forMode: .common)
outputstream.schedule(in: .current, forMode: .common)
inputstream.open()
outputstream.open()
}
}
I've also tried replacing "localhost" with "127.0.0.1" which is the IP I specified for the server to run on but it still doesn't work.
click on your project settings and go to capabilities there you'll see the app sandbox. make sure it's turned on and then enable incoming connections and outgoing connections.
I have a message sending program from server to client which is working inside adempiere. Here I have to give supply port: 8080 dynamically, ie. port must not be hardcoded. Now I am hard coding port 8080 at serversocket and socket
Server
ServerSocket srvr = new ServerSocket(8080, 1, InetAddress.getByName(mSession.getRemote_Addr()));
Client
Socket skt = new Socket(ip.getHostAddress(), 8080);
Please suggest a method rebel to this hard coding.
Please help me.
The web port is part of the configuration data that is used when the setup process is run but it isn't accessed by the server/client once the setup is complete. To access the data, you will need to load the configuration data again like this:
int webPort = 8080;
ConfigurationData data = new ConfigurationData(null);
if (data.load()) {
webPort = data.getAppsServerWebPort ();
}
ServerSocket srvr = new ServerSocket(webPort, 1, InetAddress.getByName(mSession.getRemote_Addr()));
I need to establish a connection with the following data:
Protocol: XMPP
Username: <Your username>
Password: AIR_<Your LoL password>
Domain: pvp.net
Connection security: Use old-style SSL
Connect port: 5223
connection server: chat.euw1.lol.riotgames.com
I only managed to connect to a normal domain server in this form:
username#domain.com/resource
However, I need to add somehow the connectionserver (chat.euw1.lol.riotgames.com).
I really hope someone is familiar with agsXMPP and can help me!
Thanks in advance!
Alright I was just confused, maybe it was just too late for exploring new libs.
However, if someone stucks like me on connecting, here is a easy solution on how to test a login with this library:
XmppClientConnection xmpp = new XmppClientConnection("pvp.net");
xmpp.UseSSL = true;
xmpp.Port = 5223;
xmpp.ConnectServer = "chat.euw1.lol.riotgames.com";
xmpp.Open("username", "AIR_password");
xmpp.OnLogin += delegate(object o) { MessageBox.Show("logged in"); };
I have a simple socket.io chat application which I've uploaded to one of the new Heroku 'cedar' stacks.
Now I almost have everything working but I've hit one stumbling block. On my localhost, I open a connection to the socket server from the client with:
// lots of HTML omitted
socket = new io.Socket('localhost', {port: 8888});
But on Heroku, I obviously must substitute something else in for these values.
I can get the port from the process object on the server like so:
port = process.env.PORT || 8888
and pass that to the view.
But what do I substitute for 'localhost'?
The correct way according the article on heroku is:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
socket = new io.Socket();
This ensures that io.Socket won't try to use WebSockets.
I was able to get Socket.IO v0.8 to work on Heroku Cedar by doing the following:
Within the Express app (in CoffeeScript in my case):
app = express.createServer();
socket = require("socket.io")
...
io = socket.listen(app);
io.configure () ->
io.set("transports", ["xhr-polling"])
io.set("polling duration", 10)
io.sockets.on('connection', (socket) ->
socket.on('myaction', (data) ->
...
socket.emit('result', {myData: data})
### The port setting is needed by Heroku or your app won't start
port = process.env.PORT || 3000;
app.listen(port);
And within the front-facing Javascript of your application:
var socket = io.connect(window.location.hostname);
function sendSocketRequest() {
socket.emit('myaction', $("#some_field").val());
}
socket.on('result', function(data) {
console.log(data);
}
Helpful links:
Heroku Node help
Heroku Socket.IO help
This has now changed as of Oct 2013, heroku have added websocket support:
https://devcenter.heroku.com/articles/node-websockets
Use:
heroku labs:enable websockets
To enable websockets and dont forget to remove:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
After trying every combination under the sun I finally just left it blank. Lo and behold that works perfectly. You don't even need the port.
socket = new io.Socket();
I was also having this problem on heroku. I was able to make it work using the hostname "myapp.herokuapp.com" (or simply window.location.hostname, to work both local and in production) and setting the port to 80. I'm using SocketIO 0.6.0.
Wouldn't you just put your actual hostname?
2011-06-25T21:41:31+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET appxxxx.herokuapp.com/socket.io/1/websocket/4fd434d5caad5028b1af690599f4ca8e dyno=web.1 queue= wait= service= status=503 bytes=
Does this maybe mean the heroku router infront of the app is not configured to handle web socket traffic?
[update]
It would appear as of 6/22/2011 the answer is yes... heroku does not support socket.io see this post: http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/