I have a project which, for purposes of server configuration, is just a wicket quickstart archetype. I've added some application code, but haven't really done anything to change the default jetty configuration.
I can run and test my application locally using:
http://localhost:8080
or:
http://bekkar:8080 (my PC's network name)
or:
http://192.168.1.2:8080/ (my PC's local IP)
I want to access my wicket app from outside my router firewall. (I eventually will test it on my Blackberry, but for now I'm using Google Chrome to try to reach it externally.)
Using http://www.whatismyip.com/ I found my router's IP.
I use:
http://###.###.###.###:8080
and I get a screen that says Authentication Required, asking for a username and password. I don't have any kind of authentication set up in my wicket app.
I have a NetGear router, WGR614v7. Using the router admin, under port forwarding, I add the following custom service:
Service Name=wicket
Starting Port=8080
Ending Port=8080
Server IP Address=192.168.1.2 //my computer's local IP
After adding the port forwarding service definition, I get a different message from Chrome:
Oops! Google Chrome could not connect to ###.###.###.###:8080
How can I make my wicket jetty quickstart accessible from outside my router firewall? I don't know if this is a wicket/jetty issue (belonging on SO) or a firewall issue (belonging on serverfault), so I'll post it here, first.
Thanks!
First, try with just simple apache, or woof. Be sure to bind it to 0.0.0.0 (all IPs).
A) If you can't reach it, it's the router config problem.
B) If that works, you know it't jetty/wicket config.
case A) I don't know that router, but look for port forwarding. I wasn't able to get ASUS WL500gP passing requests in, so I am not the right one to advice here :)
case B) Does Jetty bind to 0.0.0.0? Can you reach it from other machine on the local network?
Not much useful answer, but I hope it helps a bit.
I run jetty/wicket apps on my system all the time and access them remotely. I don't think there is anything special that I've done with Jetty, and especially not wicket to make this work. But if it helps, here is an example Start.java file (this is from one of my apps -- not sure if it is the same as the one in quickstart, as I don't have a quickstart available right now):
public class Start {
public static void main(String[] args) throws Exception {
Server server = new Server();
SocketConnector connector = new SocketConnector();
// Set some timeout options to make debugging easier.
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(8080);
server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath("/");
bb.setWar("src/main/webapp");
// START JMX SERVER
// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
// MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
// server.getContainer().addEventListener(mBeanContainer);
// mBeanContainer.start();
server.addHandler(bb);
try {
System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
System.in.read();
System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
// while (System.in.available() == 0) {
// Thread.sleep(5000);
// }
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
}
I'm using a DLink router, so I'm not sure how to configure yours. However, you should also check your router to see if it has remote web admin turned on, and if it is on port 8080. If so, turn it off, as it might be interfering with your port forwarding.
Related
I am new to using Micrometer as a metrics/stats producer and I am having a hard time in getting it configured correctly with my Jersey/Embedded Jetty server. I would like to get Jetty statistics added.
I already have the servlet producing stats for the JVM in a Prometheus format.
Does anyone know of a good working example on how to configure it?
I am not using SpringBoot.
The best way is to look at the Spring Boot code. For example it binds the jetty connections
JettyConnectionMetrics.addToAllConnectors(server, this.meterRegistry, this.tags);
And it uses an ApplicationStartedEvent to find the server reference.
private Server findServer(ApplicationContext applicationContext) {
if (applicationContext instanceof WebServerApplicationContext) {
WebServer webServer = ((WebServerApplicationContext) applicationContext).getWebServer();
if (webServer instanceof JettyWebServer) {
return ((JettyWebServer) webServer).getServer();
}
}
return null;
}
There are other classes that record the thread usage and SSL handshake metrics.
I have a grails project which uses Spring websockets. I have implemented the DefaultHandshakeHandler to create random principal name for each new session and use convertAndSendToUser to send messages.
Everything works fine in local run. I am also able to deploy the WAR file on an AWS EC2 Linux Instance running latest tomcat. The file deploys fine and the Connect and Disconnect events on websockets can be detected correctly.*
The only problem is, My CustomHandshakeHandler's determineUser does not get called on production. Due to this my StompHeaderAccessor's principal is always null and the code starts spitting NPEs.
This is how i have declared the CustomHandshakeHandler :
class CustomHandshakeHandler extends DefaultHandshakeHandler {
#Override
protected Principal determineUser(ServerHttpRequest request,
WebSocketHandler wsHandler,
Map<String, Object> attributes) {
// Generate principal with UUID as name
return new StompPrincipal(UUID.randomUUID().toString())
}
}
This is how i set the handshake handler configuration :
#Override
void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/ws-ep") // Set websocket endpoint to connect to
.setHandshakeHandler(new CustomHandshakeHandler()) // Set custom handshake handler
.withSockJS() // Add Sock JS support for frontend
}
I tried deploying the same WAR file on local Tomcat 8 and it again works fine. It seems problem happens due to AWS. I also searched for some other AWS and websocket related issues. I came across some ELB compatibility related things but i Don't think that's my case since my websockets are working fine (Events are being received)
Can someone please help out or point me in right directions
Problem was with Nginx settings which upgrade the Http Request to WS request. This question helped a lot : Spring WebSocket: Handshake failed due to invalid Upgrade header: null
I have created a project in Go using gin and it is working fine locally. However, when I tried deploying this on an EC2 instance on AWS, I was unable to access the APIs on the server.
I did a ssh into the hosted machine and gave a curl request (curl localhost:8080) and it gave a proper response. But any request from outside is not reachable.
The server is running on port 8080. I have opened the ports in the AWS security groups.
Is there any setting in Go/gin that I need to make for it to be accessible from the internet?
Sample code:
package main
import (
"myConstants"
"myDatabase"
"myMiddleware"
"onboarding"
"github.com/gin-gonic/gin"
)
func main() {
var db = myDatabase.DBConnect()
router := gin.Default()
router.Use(myMiddleware.RestrictInputContent)
router.Use(myMiddleware.CheckToken(db))
router.Use(myMiddleware.RequestLoggerMiddleware())
router.POST("/signup", onboarding.Signup(db))
router.POST("/login", onboarding.Login(db))
router.POST("/logout", onboarding.Logout(db))
router.GET("/", onboarding.Hello(db))
defer db.Close()
//Listen and serve
router.Run("127.0.0.1:8080")
}
Changed the router.Run from router.Run("127.0.0.1:8080") to router.Run(":8080") and it works.
As suggested by #elithrar and #user3591723
127.0.0.1 (local host) is only the loop back interface on the machine
Binding to ":8080" means 0.0.0.0:8080 - which means all interfaces
I want to specify the timezone for our embedded jetty server.
Trying to avoid this:
java -Duser.timezone=UTC.
Jetty is currently configured like this:
public Server jettyServerConfig() {
org.eclipse.jetty.server.Server server = new Server();
.
.
server.setAttribute("-Duser.timezone", "UTC");//doesn't work
server.setAttribute("user.timezone", "UTC");//doesn't work
return server;
}
public HttpServer jettyServer() {
return new JettyHttpServer(jettyServerConfig(), true);
}
How should I go about to pass VM arguments to JETTY?
Any advice appreciated ;)
Use the TimeZone.setDefault(TimeZone zone) method to change the time zone programmatically for the JVM, e.g.:
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
I have setup a Windows Server 2012 instance on AWS and I am running Jenkins with a Selenium grid server. The build portion goes through fine, however it is failing with a 404 when it tries to call the browserMob.NET server.CreateProxy() call. I thought perhaps it was a security port issue, so I opened 9090 and 9091 but still having the same issue. If I use the IWebDriver on my local system, everything goes through fine, but when I change over to the remoteWebDriver and point it to the AWS server and try to proxy, I get an error. If anyone has any ideas about how I might be able to go about this, I'm ready for a kick in the right direction :) Thanks!
--Edit:
Some more info: I now have Jenkins running on 8081 and now it stops with a InvalidOperationException. On the same call of server.CreateProxy() the error fired says:
"The specified domain either does not exist or could not be contacted"
Ports currently opened in IIS8 are 80, 9090, 9091, and 8080
I also downloaded the the project to the server and tried to run it from the server and I am seeing the same thing. I also am still running IWebDriver and it doesn't work. So if I run this locally on my personal Win 7 Box, it works fine, but when I run it from Windows Server 2012, it does not. This is the same project, but I have no clue as to what may be going on here.
try
{
Server server = new Server(pathToBrowserMobProxy);
server.Start();
Client client = server.CreateProxy();
client.NewHar("google");
var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
var capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability(CapabilityType.Proxy, seleniumProxy);
var driver = new RemoteWebDriver(new Uri(seleniumServerUrl), capabilities);
driver.Navigate().GoToUrl("http://www.google.co.uk");
HarResult harData = client.GetHar();
driver.Quit();
client.Close();
server.Stop();
return Newtonsoft.Json.JsonConvert.SerializeObject(harData);
}
catch (Exception e) { throw e; }
So I finally figured out what was going on and thought I'd post here. The call to server.CreateProxy was using the AutomatedTester.BrowserMob .NET wrapper. This internally had a reference to a version of Newtonsoft JSON.net that was compiled as 32bit. Because of this and my Server 2012 box being 64bit, it was causing an error stating "32 bit processes cannot access modules of a 64 bit process" when it would instantiate the "Process" object. It would open the command window and then crash which would close the window and it wouldnt eb able to find the instance to conenct to. In looking at the NativeErrorCode of 299, I found this was stating that only part of a ReadProcessMemory or WriteProcessMemory request was completed. So I got the src for AutomatedTester, removed the ref to newtonsoft they were using (since this was the first 32bit ref I had found) and added the Nuget version which is compiled for Any CPU. This stopped the crash and allowed me to run my tests. Hope this helps someone else one day.