0

I'm trying to create a very simple RESTful Web Service with Spring Boot to perform NLP to the content passed as a parameter. You can find it on my GitHub.

For some reason, I can't deploy it to my Tomcat container in my home server as a WAR (see here), therefore I decided at least to try to set it up as a runnable JAR.

If I run it on my development machine by invoking:

java -jar -Xss32M -Xmx8G -XX:+UseG1GC -XX:+UseStringDeduplication ClearWS-0.1.0.jar

it works like a charm. If I point my browser to http://localhost:8888/process?content=This%20is%20a%20test., I get the expected JSON:

{ "id": 1,
  "sentences": [
      { "start": 0,
        "end": 0,
        "content": "This is a test.",
        "tokens": [
          { "start": 0, "end": 4, "index": 0, "text": "This", "posTag": "DT", "chunkTag": "NP", "lemma": "this" },
          { "start": 5, "end": 7, "index": 1, "text": "is", "posTag": "VBZ", "chunkTag": "VP", "lemma": "be" },
          { "start": 8, "end": 9, "index": 2, "text": "a", "posTag": "DT", "chunkTag": "NP", "lemma": "a" },
          { "start": 10, "end": 14, "index": 3, "text": "test", "posTag": "NN", "chunkTag": "NP", "lemma": "test" },
          {"start": 14, "end": 15, "index": 4, "text": ".", "posTag": ".", "chunkTag": ".", "lemma": "." } ],
        "size": 5 
      } ]
}

Now, I've moved the ClearWS-0.1.0.jar file to my home server and there I started it with the same command as above: no error messages. Locally (via localhost:8888), everything is still working perfectly. If I try to use it remotely, however, it doesn't work: after some time the browser tells me that my attempt to connect has failed.

That home server machine has a NATed address that doesn't change often, so I can hook it using no-ip.com and access it anyway. Notice that my other J2EE services deployed to Tomcat container are perfectly reachable and usable remotely. I thought it might be the embedded Tomcat conflicting with the stand-alone one, so I shut the latter down but still I can't reach ClearWS-0.1.0.

I'm starting to think that Spring understand that I still don't fully trust it, so it fails on me on purpose... Out of the joke, can anybody with a better understanding of Spring and networks help me to sort this problem out? Thanks in advance.


Solution: I simply forgot to forward port 8888... Once added that configuration to my router, I was able to remotely use the service. Now I'd like to be able to deploy it in my existing Tomcat container... any idea?

Community
  • 1
  • 1
Stefano Bragaglia
  • 622
  • 1
  • 8
  • 25
  • 1
    This doesn't sound like a problem with Spring, but a networking issue. Are you sure port 8888 is accessible? Sounds like it isn't. If you can run the jar and access it from localhost on the server, then there is some kind of firewall blocking the request. – hyness Jun 25 '15 at 20:30
  • @hyness you were right, I was not forwarding port 8888. Shame on me! – Stefano Bragaglia Jun 25 '15 at 22:36
  • @StefanoBragaglia Under the assumption that, I don't have access to router configuration, are there any solutions available for this issue? – Ganapathi Basimsetti Dec 13 '18 at 15:46

1 Answers1

0

If you really want to deploy it to a tomcat container, you need to create a war file as specified in the Spring Boot documentation. It mostly involves setting the maven packaging as a war. If your tomcat container is 6.0 or less, you would need to write a web.xml, otherwise you will to provide a SpringBootServletInitializer.

Personally, I don't see any benefit to running within a container these days. The movement in the java world now is for embedded servlet conatiners, which makes it much easier to run in the cloud or in a container like docker.

hyness
  • 4,785
  • 1
  • 22
  • 24
  • Thanks again for the helpful discussion. The main reason why I am targeting is backward compatibility: I have a few running Tomcat services that I's like to keep running. Just for curiosity, how can you run more than one spring jar on the same port? My Tomcat is running locally at port 8080, but it is forwarded to 80. I can only forward to port 80. Last but not least, I have tried to create a war out of Spring Boot even using the document you linked without success. You can find a link to a post with a MWE that is not working in my question... – Stefano Bragaglia Jun 29 '15 at 14:30
  • One process, one port. If you wish to run multiple webapps on the same port, you would need a tomcat container. I'm no expert in mod rewrite or iptables, but I would think something could be done to map distinct paths on port 80 to the different ports for embedded containers. However, it's probably simpler to run within the container. – hyness Jun 29 '15 at 14:57