I'm trying to debug my networked application to find out a network bug with one of my requests. Instead of using the command line, as the error happens inside a library, I'd rather use Charles Proxy for it.
My problem is that the connection is done by https and it's not visible as the REPL is not going through the proxy. I have tried to add -Dhttp.proxyHost and -Dhttp.proxyPort as parameters to the run/debug config to no avail.
Other applications are running through the proxy correctly.
What options am I missing?
It seems the http client library used by twitter-api doesn't honor the JVM http.proxyHost and http.proxyPort properties.
You could try add :proxy {:host "localhost" :port 8888 :protocol :https} as a named parameter to your twitter-api call.
Related
I want to send multiple requests to my localhost:3000 server from various clients, and I want to simulate that scenario. I'm using the clj-http library to make a request:
(client/get "http://localhost:3000/")
How do I make the request from an ip address other than 127.0.0.1?
One simple answer is to fire up a linux VM in VirtualBox (either directly or by using Vagrant), then make the request from the VM.
Vagrant is an easy-to-use driver since the config files (i.e. Vagrantfile) is simple text and can be checked into git. You can control the IP address of the VM with a simple entry like
config.vm.network "private_network", ip: "192.168.50.4"
See both the
the general Vagrant docs
and the Getting Start docs
(note that they are in 2 different locations!)
Another option could be to have a simple client as a Docker image (or combination of base image and a custom command) and you can launch them fairly quickly. See this answer for some guidance: https://stackoverflow.com/a/24326540/483566
What exactly are you testing? If it's a unit test, send a request to the handler with the desired IP address in the data structure.
If it's an integration test, spin up a server, and use the java library org.apache.http to hit the end points.
To spin up the server use the once fixture. It looks similar to this
(use-fixtures :once
(fn [tests]
(before stuff) ;start server here
(tests)
(after stuff))) ;shut down server here
This is the org.apache.http documentation. This is the subpage you'll want to look at. Read about setting the Requests. You'll want to set the IP address in the header of a request and then send it. Baeldung shows examples of using org.apache.http in java. which you can translate into Clojure code
For a bit now I've just been running lein figwheel to start up my application. I generated the project using the luminus template. However, recently when connecting to a database I found that lein figwheel does not allow me to connect to database. I'm assuming this is because it does not initialize the app. Which is weird because it will reload my plain clj files with no problem.
However, if I just use lein run then I have the database connection.
After poking around I reread the Luminus docs and it says that I need to run both. And this is where I am very confused. lein run opens a port to 3000, and figwheel opens up a port to 3449. Like I said, the first lets me connect to the database and the other gives me autobuilding. Do I connect to both ports?
So what step am I missing to get both worlds?
Harley mentioned this in the comment to the other answer, but I wanted to vouch for it. First, run your server however you'd like (I launch from the repl, but you can also use lein run). Then use your browser navigate to whatever port you choose to run on. Then run lein figwheel in another terminal and it will connect.
I too, have never done both at the same time. However, I have done them separately and the different ports handle different "services". Port 3000 is the http port. If you built this from a luminus template, then you are probably building a web site. So, connect to 3000 with your browser.
Port 3449 is the web socket port that figwheel uses to push changes to the browswer. So,you start up a command-line lein figwheel an it goes looking for your 3449 port to talk to the browser. Now mind you, this command-line is both a repl and a monitor program. As you make changes to the source, figwheel recompiles your changes and sends the to the page at 3449. You can also execute code from the repl by changing the namespace of the repl (i.e. in-ns).
So, two different ports, two different protocols. What does port 3000 return to the browser? Well, depending on your server, whatever page you tell it to. Whereas, the 3449 is whatever figwheel defaults it to.
The real question is how to get figwheel to connect up to an existing page in a browser, not started by figwheel. I thought I had seen where someone had a JavaScript function that you embedded in your page and it talked/listened to figwheel.
I am a GIS tech trying to get migrate to Geoserver, unfortunately I am not very savvy on web hosting.
I installed the Windows version 2.3.1.
I was able to build by map and access it through localhost:8080\geoserver\www\
I take that to mean that the jetty server it working.
I understand that I should be able to replace my local IP address where "localhost" is and be able to access it from another computer via Http.
I can't figure out the next step. I have found great tutorials on every part of geoserver process except this. And the user guide does not get into this either.
My set up: Cable Modem > Router > PC with Geoserver
What I have tried: Setting up a virtual server on my router. I have tried changing by router to inbound port 8080 to private port 8080
I also tried 80 to 8080
and 80 to 80
I also tried windows firewall exception. and turning off windows firewall.
I read about using appache tomcat but I have not installed it because it seems that jetty is working (at least as a local host) and I don't want to put another program on 8080. And to my understanding it can work stand alone but I really honestly don't know no.
I am must be missing some vital piece of information on how to do this. I am hoping it is just so basic that it wasn't worth mentioning on tutorials.
Thanks
Karin
This would be a GeoServer configuration question, but since its deployed in jetty the solution is likely in the underlying jetty configuration. That being said it is a guess on my part (the jetty side of things) how they set up this distribution, but if you find a jetty.xml file, perhaps under an /etc directory then you should be able to edit that file and set a proper host in the configuration.
Seriously though, this has to be a pretty common GeoServer question so I bet they have some documentation floating around for setting this properly in their software distribution.
http://docs.geoserver.org/latest/en/user/webadmin/basics.html
That seems to indicate it might be dependent on your container configuration, in which case look through how ever they are configuring jetty for a Host setting that is likely hardcoded to 'localhost'
I have made a simple Jetty server using this tutorial here, http://www.seas.upenn.edu/~cis550/jetty.html
Now that I have the initial steps completed, I can succesfully connect to my server by entering localhost:8080/hello or 127.0.0.1:8080/hello in my browser. Everything is going great up until this point. The servlet is working properly.
I am now interested in connecting to the server using "Machine B". I want to build a server that can be connected by any browser, anywhere.
My IP is XX.173.XXX.216, parts hidden for obvious privacy reasons. On my "Machine B" I try and enter XX.173.XXX.216:8080/hello into the browser URL. The website cannot be found. From experience I questioned my port mapping and opened my 8080 port.
After a few google searches and a while of reading, I give up. Does anyone know a possible solution to my problem? Are there any further steps I need to do in the setup of the Jetty server to make it accessible from external machines?
It is usually not hard getting from the inside of a firewall and out. It is much trickier to get from the outside and in (just have a look at the hoops Skype jumps through to be able to get two computers each behind a firewall to talk to each other directly).
First of all you need to ensure that Jetty listens to the right network devices.
Identify the IP-number of the computer running Jetty (not 127.0.0.1) and see if you can connect to "http://that-ip-number:8080" from the machine itself. If this doesn't work, fix your jetty configuration. Then put another computer on the same network and connect to "http://that-ip-number:8080" too. This MUST work before you go any further. If this doesn't work, fix your firewall configuration on the computer running Jetty.
When the above works,then you can start thinking about exposing the port through your router. The router most likely has a web interface where you can configure this, but the easiest way to do that is to use a uPNP tool (if your router supports that) which can redirect an external port to a specific host and port on your internal network. I use "Port Map" under OS X which has a very simple interface.
Good luck
I am writing a web application using ring and clojure. I am using the jetty adapter for the development server and emacs/SLIME for IDE. While wrap-reload does help, run-jetty blocks my slime session and I would like to be able to start/stop it at will without having to run it in a separate terminal session. Ideally, I would like to define a server agent and functions start-server and stop-server that would start/stop the server inside the agent. Is this possible?
I usually have a line in my Ring app that looks like the following:
(defonce server (run-jetty #'my-app {:port 8080 :join? false}))
This prevents locking up the REPL. It also allows me to recompile this file without worrying that my server will get redefined. It also lets you interact at the REPL like so:
user=> (.stop server)
and
user=> (.start server)
The Jetty documentation has some information on graceful shutdown of Jetty. That's probably not enough information but it may get you started.
I haven't started playing with compojure yet, but overall I prefer to work with Tomcat. It's more full-featured; among other things, there is a well-documented API for starting it up and shutting it down, it listens for the shutdown command on a dedicated port; there are ant tasks to do this, and they could of course be called from a Java app as well. I just don't know what kind of magic Compojure does with connecting the REPL to a running instance of the Web container, and if/how automatic class reloading happens... hopefully someone else will be able to provide more information.
12 years later.
VSCode / Calva:
If you are like me starting jetty from the repl inside VSCode / Calva
you have to CTRL-C the server process at the terminal not the REPL.
In fact the server process is bound to the terminal not to the REPL.