Weird Tomcat and Axis Webservice behaviour - java

I have a simple web service deployed on tomcat using Apache Axis.
If i access the webservice as http://localhost:8080/webservices/TransactionService i see the usual message
TransactionService
Hi there, this is an AXIS service!
Perhaps there will be a form for invoking the service here...
showing that the web service is available and ready for use.
However if i access it as http://10.0.0.1:8080/webservices/TransactionService (10.0.0.1 is the actual IP of the machine. I'm accessing it on the same machine as above, machine hosting tomcat) i get:
HTTP Status 404 - /webservices/TransactionService
--------------------------------------------------------------------------------
type: Status report
message: /webservices/TransactionService
description: The requested resource (/webservices/TransactionService) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/5.5
There is nothing in the tomcat logs
If i try deploying on Jetty it all works fine.
Is there any explanation for this? Any pointers most welcome.

Tomcat can listen on different hostnames/IPs in a different way. Specifically, every host/IP can have its own work directory:
<Host name="localhost" workDir="/workdir">
...
</Host>
Application deployed to one workdir won't be available to a host with another workdir.
Check your configuration.
UPDATE: if name is specified as name, not IP, check that that name is resolved to 10.* address too.
Also, one of the hosts is default. It responds to all requests now matter what host they are targeted too, if there is no specific Host. For your setup you may want to leave only that one active.

I don't think a change to Tomcat configuration is the answer. I don't have to do such a thing to use my local IP address or localhost.
Could it be as simple as an addition to your hosts file? I've got mine in c:/windows/system32/drivers/etc/hosts, and there's an entry for "127.0.0.1 localhost" in it.

Related

How to prevent HTTP 404 during deployment of ear in Wildfly/Jboss

We're using WildFly 10 as our application server and deploy via Docker (deployment in WF is ordinary hotdeployment). We're not using WildFly's clustering mechanisms but simply have load-balancers (HAProxys) in front.
The problem is that WF opens its HTTP port while the EAR deployment is still in progress. This (of course?) leads to HTTP 404 errors which we don't want to handle specifically in the LBs. This could lead to false negatives...
Is there a way to allow HTTP connections only after the EAR has started successfully?
Alternatively is it possible to replace the "404 because nothing is deployed here"-error with a "503 service unavailable"? This would much better express the problem and would be easy to handle externally...
You can set default-response-code for host you are running this on.
something along the lines:
<host name="default-host" alias="localhost" default-response-code="503">
or in cli:
/subsystem=undertow/server=default-server/host=default-host:write-attribute(name=default-response-code, value=503)
and similarly for any other host you might have.

Tomcat Request.getPort() stripping port number

Problem:
I am using Java HttpServeltResponse to call sendRedirect but on a particular deployment the URL port number is not included in the HTTP 302 response message.
Details:
I have an application, which uses spring security to authenticate and redirect on success. The redirection URL provided by me is a relative path.
On redirection the spring framework calls sendRedirect on HttpServletResponse passing in the context path along with the relative URL. For example:
HttpServletResponse.sendRedirect("/MyApp/index.html");
This all works fine when we deploy to tomcat instances on various platforms (Windows/Ubuntu etc). However one of our clients is finding that in their deployment, the redirection port is stripped, for example, if the entry point is:
http://server:8082/MyApp/authenticate
The redirection they get is:
http://server/MyApp/index.html - this page does not exist, as it is missing port 8082
Stepping through the code, I can see that the port is determined by asking the Java Request Object, which seems to be supplied by the Web Application Container (i.e Jetty/Tomcat?). In my dev environment it is org.eclipse.jetty.server.Request.
So is this a tomcat configuration issue? We could replicate the same behaviour using Apache2 ProxyPassReverse, but they assure me they are not running Apache2, and their connection is a direct connection to tomcat.
As I can not replicate this issue anywhere, I am really stuck for an answer. Any help would be very much appreciated.

Deploying Java SE6 stand alone web service on a server

Follwing the steps as outlined here: Standalone web service
I created a test web service that works great on my local machine. Since this is 'stand alone' I copied the same root folder on to a 'server' that I use and published the service on the server (as if it is my local machine). When I access the wsdl using localhost as the domain name, it works fine on the server. However, when I try the url from a different macihne on the network giving the server's domain name instead of localhost, I get a 'can not be displayed' error in IE.
My question is, should this even be possible? Or is there anything specific that needs to be done. Since this is a 'stand alone' solution, we should not require 'another' container like tomcat correct?
To be honest, until your post, I had no idea there was a builtin, lightweight, HTTP Server in the JDK. I've always used glassfish for my web service needs.
I can't say for sure, but if you look closely at the example code you'll see:
Endpoint endpoint = Endpoint.publish("http://localhost:8080/calculator", calculator);
I suspect that this limits you to "localhost" as opposed to the host machine. Try changing it so that it represents the name of the server and try again from another machine (naturally making sure it can get through the firewall as well). Something like:
Endpoint endpoint = Endpoint.publish("http://myserver:8080/calculator", calculator);
Rebuild it and try again. Other than that, you'd need to create a proper war file and deploy to glassfish, tomcat, etc.

Spring : How to remove localhost from url

I am working on some project for that using spring 3.2.0. Whenever I run project it looks like
http://IpAddressWithPortNo.com/myprojectName.com/
IpAddressWithPortNo = localhost : 8080
I want to hide localhost:8080 or ip address.
Is there any method available to map this ip to my project?
http://myprojectName.com
I am using apache tomcat 7.0 and fedora 17.
The solution doesn't involve configuring Spring, but the hosts file of your operating system. On Ubuntu, it is found at /etc/hosts, I'm not sure if its the same for Fedora, but it should be.
You just need to add a line in the hosts file that looks like the following:
127.0.0.1 myprojectName.com
That's it. You then access the myprojectName.com address in your browser and it will look at your localhost, behind the scenes.
The above solution works if you only need name resolution for your local machine.
If you'd like to expand to your local or external network, the answer is less trivial:
for your local network, you need to register a custom domain on your network DNS server (see this and this for more information); if you have a network administrator, direct this requirement to him, explaining that you want to expose your local ip through a custom domain name
if you want to expose this name to the entire internet, you have to register the custom domain to a DNS registration service (you can find free DNS services as well, unfortunately I haven't used any lately and dyndns.org doesn't provide free dns service anymore, try searching free dns service on google and lookup some reviews)
The :8080 will go if you configure Tomcat to respond on port 80, or https on port 443.
You can use any host name that resolves to your network address. For instance if your machine name on the local network is athena.mycompany.com then http://athena.mycompany.com/myProjectName should work fine - but only within the local network.
To get to http://myprojectName.com you will need to configure a firewall/router to forward an incoming request (presumably from the Internet) to your machine. Internal access will likely not resolve this URL.
Gabriel has just posted an answer that should work from your machine, but other machines within your intranet would also require entries to map that name to your machine.
For doing exactly what you want, you need to configure apache tomcat to listen on port 80 and tell your operating system that myproject.com resolves to localhost.
To resolve myproject.com to localhost, add the following to your /etc/hosts file:
127.0.0.1 myproject.com
To change the port number to 80, open /usr/share/tomcat7/confserver.xml or /etc/tomcat7/server.xml (whichever applies to your system) and change Connector port = 8080 to Connector port = 80.

How to configure Apache to redirect subdomains to Tomcat applications

I have a few applications hosted on Tomcat running a machine called test-websites throuhg port 8080. So they are accessible like this:
http://test-websites:8080/app1/
http://test-websites:8080/app2/
...
http://test-websites:8080/appN/
What I need to do is make these applications accessible on my local network by:
http://app1.test-websites/
http://app2.test-websites/
...
http://appN.test-websites/
As I add new applications to Tomcat's webapps folder, I want them to be automatically available using the same subdomain pattern.
So I thought using Apache in front of Tomcat to make the URL rewriting would be a good idea, but so far I have not been able to configure the virtual host on Apache to make this redirect. I installed apache2 on port 80 and I see the default "It Works!" apache page when I access http://test-websites/, but I couldn't find how to make the redirects to the apps in the Tomcat following the format above.
I have searched for over 4 hours and didn't get an answer for this use case.. any help us much appreciated!
Thank you!
Eduardo
First you need to add a DNS entry for app1.test-websites, app2.test-websites,.. such that it points to test-websites. Generally CNAME entry works best in this case. If you only need the URLs to resolve on your local machine (for testing purpose), you can just update your /etc/hosts or C:\windows\system32\drivers\etc\hosts file. Otherwise you need to figure out how your company's network is setup and change the DNS entry (if it's a Windows domain network, normally there's a DNS service on the domain controller. On some smaller network you have to configure it on the router).
Next, the quickest way to achieve this is to not use apache2 to front it, bust simply have tomcat listening on port 80. You can setup virtual host on tomcat such that it serves different web-app depending on the URL requested.

Categories