I have been searching for days on how to get this to work but I have had no success.
I have a project which listens on port 6789 and when a connection is made I need to perform some specific actions. To do that I am trying to use a listener so that anytime that my servers Engineis run upon a connection being made.
Basically a mobile application is going to connect to an instance of a server, as soon as the connection is made, the server needs to authenticate the user, then receive data from the phone and place it in the database. If there is another way to do this please let me know. I have looked at filters but those need a url path to activate, and I also do not know how to use a servlet which will fire when a connection is made!
I have this so far in my server.xml:
<Service name="Catalina">
<Connector connectionTimeout="20000" port="6789" protocol="HTTP/1.1"
redirectPort="8443" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<Engine defaultHost="localhost" name="Catalina">
<Listener className="Listeners.EngineListener" />
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase" />
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost"
unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log."
suffix=".txt" />
<Context docBase="PhoneListener" path="/PhoneListener"
reloadable="true" source="org.eclipse.jst.jee.server:PhoneListener">
</Context>
</Host>
</Engine>
</Service>
I have the full path to the file in the <Listener> tag. This is the same way I have executed many filters (authentication and noCache).
The class which implements the LifeCycleListener is here"
package Listeners;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
#ManagedBean
#SessionScoped
public class EngineListener implements LifecycleListener
{
#Override
public void lifecycleEvent(LifecycleEvent event)
{
// TODO Auto-generated method stub
System.out.println("The engine listener is working!");
}
}
The bean declaration is meaningless here, I get the same result with and without the bean declaration.
I have been working at this for a few days now.
I have installed maven and used it to fix dependencies. I have made new projects in new workspaces in an attempt to remedy and class path errors. I have tried to switch from the Majorra JSF library to the MyFaces library, I get the same errors. I am honestly at my wits end with the Listener.
Any ideas?
It turns out that there were no errors in my code, but an error with where files are placed. I have exported the PhoneListenerproject as a .jar and put it into the /lib folder of the server I am awaiting a connection on.
The server could not find my Listeners.PhoneListener as it was not in the start up directory of the server itself.
Related
I have multiple services defined in server.xml and below is the one which i need to restart(stop and start again) using tomcat manager application/api.
<Service name="myService">
<Executor name="myExecutorPool" namePrefix="my-http-pool"
maxThreads="10" minSpareThreads="1"/>
<Connector
port="8701" protocol="org.apache.coyote.http11.Http11Nio2Protocol" SSLEnabled="true"
executor="myExecutorPool"
maxSavePostSize="-1"
scheme="https" secure="true"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100"
sslEnabledProtocols="${sslEnabledProtocolsMediumSecurity}" server=" "
allowUnsafeLegacyRenegotiation="false"
clientAuth="want"
bindOnInit="false"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
keystoreType="PKCS11"
keyAlias="server"
trustManagerClassName="com.example.com.myproj.cert.RestTrustManager"
sendReasonPhrase="true"
sslImplementationName="com.example.com.myproj.cert.MyProjImplementation"
ciphers="${tls.ciphers}"
/>
<Engine name="myEngine" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.MethodsValve" methodsSupported="GET,POST,PUT,DELETE,HEAD" />
<Host name="localhost" appBase="mywebapp"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="../webapps/ROOT" >
<Valve className="org.apache.catalina.valves.RedirectValve" sendToApp="/myapp/" />
</Context>
</Host>
</Engine>
</Service>
When i do curl -username:password http://localhost:8080/manager/text/list , i don't see this above service listed. It means i assume that, this service is not running as a separate service but contained inside appserver.
So i won't be able to do something like http://localhost:8080/manager/text/reload?path=/myService.
Can you please help here, how do i stop/start (restart) this particular service using tomcat manager app?
If JMX can be used here, can you please provide any links/resources for the same mentioning how to do that?
I have Tomcat 9. I am trying to get the URL lik this: http://default.local:8080/default_war/ but my site is still available only by http://default.local:8080.
The address I am going to set is also generated by Intellij in Run/Configuration so it shoud be possible to set it. Of course I could edit it in Intellij but I wonder how to achieve URL subderictories in Tomcat 9.
What should I change in my code? Here there are my setting files:
$ cat /home/u/opt/tomcat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="default.local" appBase="default"
unpackWARs="true" autoDeploy="true">
<Context path="/default_war" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
u#i3 ~/opt/tomcat
$ cat conf/Catalina/default.local/ROOT.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="${catalina.base}/deploy/default_war.war">
</Context>
u#i3 ~/opt/tomcat
$
This is happening because you are using a context file called ROOT.xml.
The ROOT application is the one which is served from the base URL - in your case, http://default.local:8080.
Depending on exactly how you deployed your WAR, you will need to take the following steps:
1 - Stop Tomcat and change the name of the ROOT.xml file to default_war.xml.
The above step means you are no longer using a ROOT-based webapp (see final note below for more on that).
2 - Because you have specified appBase="default" in your server.xml, you may also need to go to that default folder and remove any sub-folders in there, before restating Tomcat.
I would expect there to be a ROOT folder in there, because you have already used a ROOT.xml context file. You don't want that folder, because that will continue to serve your webapp from the base URL.
When you restart Tomcat, you should see a new folder called default_war in the default folder - and that is where your application will be served from - and it should be available only at http://default.local:8080/default_war/.
Background note: In Tomcat, ROOT is something of a special case. When you download and install a fresh installation of Tomcat, you will see a folder called ROOT in the webapps directory. This is where the main Tomcat welcome/congratulations page is served from - and like your ROOT.xml content, it is served from the base URL. You can see some of the possible configurations in the "naming" table shown in this Tomcat documentation page.
I created a RESTful web service using auto generated entity classes with netbeans. I also used maven. I deployed this in tomcat 8 as localhost. I do see the index page, but I cannot access any endpoints. I initially ran this locally on Glassfish server and it worked fine.
I tried test resource uri in netbeans but it says,
Unable to open resource URL : localhost:8080//api/activity
Here is my server.xml file from apache tomcat.
<?xml version="1.0" encoding="UTF-8"?>
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context antiJARLocking="true" docBase="C:\xxx\yyyy\apache-tomcat-8.0.36\apache-tomcat-8.0.36\wtpwebapps\xxDBWithMaven" path="/VoyateDBWithMaven" reloadable="true" source="org.eclipse.jst.jee.server:VoyateDBWithMaven"/></Host>
</Engine>
</Service>
</Server>
Is there anyway I can fix this so the resources can be accessed? It's confusing because the application gets deployed and the index file is displayed.
Unable to open resource URL : localhost:8080//api/activity
You have two slashes between "localhost:8080" and "api/activity". Remove one in the configuration where you specify the path: api/activity instead of /api/activity.
I am working on Debian X64 where I have tomcat with multiple webapps hosted which works fine.
I have an Apache webserver running which is hosting a CMS and which I would like to open when for example www.domain-cms.com is called.
Right now, the Tomcat has 2 webapps which are called again based upon URL like www.domain-tom1.com and www.domain-tom2.com
Now my question is how to run both together and distinguish based upon URL. I have done the following changes, kindly let me know what am I missing.
Tomcat's server.xml :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">
<Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol" compression="force" compressionMinSize="1024"
connectionTimeout="20000" maxPostSize="5242880"
URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="keystorefile" keystorePass="PASSWORD" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="domain-first.com" autoDeploy="true" unpackWARs="true" appBase="tooltank_webapps">
<Alias>www.domain-first.com</Alias>
<Context path=""/>
</Host>
<Host name="domain-second.com" autoDeploy="true" unpackWARs="true" appBase="aupair_webapps">
<Alias>www.domain-second.com</Alias>
<Context path=""/>
</Host>
<Connector port="8010" protocol="AJP/1.3" redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
</Engine>
apache2.conf :
I have added this in it, but seems wrong as I want to redirect based upon URL, but don't know what to add.
<IfModule jk_module>
JkWorkersFile /etc/apache2/workers.properties
JkLogLevel INFO
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
// I think below is wrong, I want to redirect based on URL.
SetEnvIf Request_URI "/error/*" no-jk
SetEnvIf Request_URI "/blog*" no-jk
JkMount / tomcat
JkMount /* tomcat
</IfModule>
(END)
workers.properties file :
worker.list=tomcat
# Set properties for worker (ajp13)
worker.worker.type=ajp13
worker.worker.host=127.0.0.1
worker.worker.port=8010
(END)
Now whenever I try to start Apache, I get an error :
[....] Restarting web server: apache2(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
failed!
How can I connect both Apache server and tomcat and serve CMS and webapps in parallel based upon URL. Kindly let me know. Thank you. :-)
1) Port 80 usually used by httpd apache server whereas you are using it for Tomcat as I am seeing in your server.xml <Connector port="80"
2) Add virtual host in server.xml to direct different websites in Tomcat for example:
<Host name="domain-tom1.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory-in-webapps"/>
<Alias>www.domain-tom1.com</Alias>
</Host>
<Host name="domain-tom2.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory2-in-webapps"/>
<Alias>www.domain-tom2.com</Alias>
</Host>
you can write this between </hots> and </Engine>
This is my first post here (but not the first time that I visit the page, I found a lot of solutions here), first of all, sorry for my english I will try to explain myself as best I can.
This question appears another time in this page, but I tried all the solutions that the people post and I still with this problem, well here we go.
I made a project on Eclipse(indigo) for launch like a WebService (I did it before with succes, is not my first time) and when I Run on Server(Tomcat7) all seems fine and the appears this Warning.
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:GestorContenidoWS' did not find a matching property.
Then appear in the Web perspective of Eclipse the page "HTTP 404". I'm telling this because I read in other post that this Warning is not a problem, but seems that it is for me (The project is also vinculated with a JPA Persistence).
.I found two solutions for make dissappear this Warning. First, go to Server Overview and select the option 'Publish module contexts to separate XML files' and then try to Run on server again, but didn't work.
The other option was, remove the project from the server from the Server View. Then run the project under the same server for recreated server.xml, but didn't work also.
Anybody can help me? Maybe the problem of this "HTTP 404 requested resource (/GestorContenidoWS/) is not available." is in another part or its because this Warning?"
The code of my server.xml (without comments) is this:
<?xml version="1.0" encoding="UTF-8"?>
--><Server port="8005" shutdown="SHUTDOWN">
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory"name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1"redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="GestorContenidoWS" path="/GestorContenidoWS" reloadable="true" source="org.eclipse.jst.jee.server:GestorContenidoWS"/></Host>
</Engine>
</Service>
Thank you
First of all this is a warning and not an error. So there is no need to worry too much about it. Basically it means, that Tomcat does not know what to do with the source attribute from context.
This source attribute is set by Eclipse (or to be more specific the Eclipse Web Tools Platform) to the server.xml file of Tomcat to match the running application to a project in workspace.
Tomcat generates a warning for every unknown markup in the server.xml (i.e. the source attribute) and this is the source of the warning. You can safely ignore it.
This is a warning and can be safely ignored. Tomcat or the Web container does not understand what to do with the property set by Eclipse
set contex-root
<property name="context-root" value="path" />
and http://localhost:8080/path
show your index file
Find server.xml. For example "C:\Dev\apache-tomcat-8.5.23\conf\server.xml"
Find your application in server.xml
<Context docBase="C:\Dev\apache-tomcat-8.5.23\wtpwebapps\SpringRestExample" path="/spring" reloadable="true" source="org.eclipse.jst.jee.server:SpringRestExample"/></Host>
Expected url http://localhost:8080/SpringRestExample/rest/emp/9999
But (path="/spring") instead (path="/SpringRestExample")
Therefore current url http://localhost:8080/spring/rest/emp/9999