I have the following code in struts2.3 ::
SessionEvent se = new SessionEvent();
se.setSessionID(session.getId());
se.setUserID(user.getUserId());
session.setAttribute("SessionEvent", se);**
Map attributes = ActionContext.getContext().getSession();
attributes.put("USER", user); // user is a serialized object
attributes.put("ID", 0);
ActionContext.getContext.setSession(attributes);
CustomSessionManager cst = new CustomSessionManager();
cst.setUserID(user.getUserId());
cst.setUserMachineIP(req.getRemoteHost());
cst.setUsersessionId(session.getId());
session.setAttribute("boundUnboundUser", cst);
SessionEvent And CustomSessionManager are Serialized Listener classes ::
public class SessionEvent implements HttpSessionBindingListener, Serializable
{
public void valueBound(HttpSessionBindingEvent arg0)
{
}
public void valueUnbound(HttpSessionBindingEvent arg1)
{
}
}
public class CustomSessionManager implements HttpSessionBindingListener, Serializable
{
public void valueBound(HttpSessionBindingEvent arg0)
{
}
public void valueUnbound(HttpSessionBindingEvent arg1)
{
}
}
Now the problem is that at replication time DeltaManager is able to replicate the SessionEvent and CustomSessionManager Object but unable to replcate user object . Now if i change the sequence of code and put the session code for user above Session Event then user object gets replicated but Custom Session Manager does not . Not sure whether this is a problem in my code or there is problem in behavior of Delta Manager in tomcat 7 . I have marked my web application as also . My Receiver ports of tomcat are also different . I am using sticky session . Following is server.xml configuration for cluster
I have also specified jvmRoute attribute inside Engine tag in server.xml file . I am using mod_proxy_balancer for load balancing
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45569"
frequency="500"
dropTime="3000"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4001"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor
className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" deployXML="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<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>
Related
**Primefaces don't allow me to upload a file greater than 1 MB as shown in the picture. The code works on my local tomcat server but would not work on the Amazon prod tomcat server. Any suggestions please I even used maxPostSize but it does not work. I guess the issue is with the server.xml as the code works fine. **
Server.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<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>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<!--
<Connector compressableMimeType="text/html,text/xml,text/css,text/javascript,application/x-javascript,application/javascript,image/png,image/jpeg,font/woff2,text/css; chartset=utf8,text/html;charset=UTF-8" compression="on" compressionMinSize="256" connectionTimeout="20000" noCompressionUserAgents="gozilla, traviata" port="8081" protocol="HTTP/1.1" redirectPort="8443"/>
-->
<!-- A "Connector" using the shared thread pool-->
<Connector executor="tomcatThreadPool"
port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
maxPostSize="-1"
redirectPort="8443" />
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<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>
File Upload Handler
public void handleFileUpload(FileUploadEvent event) {
UploadedDocument doc = new UploadedDocument();
try {
doc.setDoc(IOUtils.toByteArray(event.getFile().getInputstream()));
} catch (IOException e) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
event.getFile().getFileName() + " could not be uploaded.", null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
doc.setDocName(event.getFile().getFileName());
if (temporaryUploadedDocuments == null) {
temporaryUploadedDocuments = new ArrayList<UploadedDocument>();
}
temporaryUploadedDocuments.add(doc);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
event.getFile().getFileName() + " has been uploaded.", null);
FacesContext.getCurrentInstance().addMessage(null, message);
count = count + 1;
}
File upload button
<p:fileUpload style="word-break: break-all;"
update="dtaAttachments"
fileUploadListener="#{AccountComponent.handleFileUpload}"
mode="advanced" sizeLimit="10000000" multiple="false"
fileLimit="5"
fileLimitMessage="Please zip if you have more than 5 files."
allowTypes="/(\.|\/)(pdf|docx|doc|png|jpg|jpeg|png|rar|zip|PDF|DOCX|DOC|PNG|JPG|JPEG|RAR|ZIP|xls|XLS|xlsx|XLSX|txt|eml)$/">
</p:fileUpload>
This post issue has been resolved. The issue was not with my tomcat. I had a Nginx server running blocking all uploads above 1 MB. To resolve this, just set this paramter in block below in /etc/nginx/nginx.conf file. This will allow uploads upto 100 Mb
http {
...
client_max_body_size 100M;
}
Since I need the runtime information of every request processed by Tomcat, I've configured the access log output for Tomcat in the file {$CATALINA_HOME}/conf/server.xml as following. But when running the application, the access log file just stays empty. Anybody knows the reasons? Thanks a lot!
<Host name="localhost" appBase="deploy"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="/home/admin/shopcenter/logs/"
prefix="localhost_access_log"
suffix=".log"
buffered="false"
encoding="GB18030"
pattern="common"/>
</Host>
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.
C:\asset (there I have images like 1.jpg / 2.jpg / 3.jpg etc)
My tomcat server.xml looks like this:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="C:/asset" debug="0" reloadable="true" crossContext="false"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
Still when i go to localhost:8080/test/1.jpg I have 404 error any ideas why this don't work ?
Another question is there any possibility to configure this path in my spring project ? As a variable ?
I have a relatively simple spring web application running on tomcat which returns an xml document. The initial request goes in and I can debug into my code. However, subsequent requests do not drop into the debugger. I can make the initial request with either a browser or soapUI, and subsequent requests (on different browsers/programs/machines) get the same response as the initial one.
The localhost_access_log is getting populated with every request. However the log4j file is not getting populated beyond the first request.
I'm using Tomcat 7 and spring 3.1.1. This happens on both the tomcat deployed within eclipse (used to enable debugging), as well as deploying it on another tomcat server on linux.
This is similar to another question (Tomcat gives Same Response ) which never had an accepted answer.
So it doesn't appear to be browser caching (different applications making requests get the same response), but rather some sort of Tomcat caching.
Any ideas? Here is the server.xml which I believe may be the cause of the problem somehow, but I don't see any red flags. Also, I'm doing GETs to the web application, which may be caching somehow on the server side.
Example GET request: http://localhost:8130/bootstrap/xml?environment=dev
It returns a xml document as noted in this RequestMapping:
#RequestMapping(value = "/xml", method = RequestMethod.GET,produces="application/xml")
Sample Response:
<connection_details env="dev">
<servers>
<server host="localhost" name="auth" port="9876"/>
</servers>
</connection_details>
The issue manifests itself as every request returns the same as the initial request, even if the environment variable passed into the GET request changes. This is even if requested from different browsers and soapUI.
Example of how the response above is created:
private ModelAndView bootstrap(HttpServletResponse response, String environment) {
Map<String, Object> model = new HashMap<String, Object>();
try {
DOMSource domSource = new DOMSource(documentBuilder.parse(context
.getResourceAsStream(bootstrapXmlFileName)));
model.put("xml", domSource);
model.put("requestedEnvironment", environment);
}
catch (Exception e) {
response.setHeader("ERRORS", e.getMessage());
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return null;
}
return new ModelAndView("bootstrap_connection_selector", model);
}
Then it is passed to an xslt transformation:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.xslt.XsltView" />
<property name="prefix" value="/WEB-INF/xsl/" />
<property name="suffix" value=".xslt" />
</bean>
Finally the following transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- parameter for the requested location -->
<xsl:param name="requestedlocation"/>
<!-- start template matching on the connection_details element -->
<xsl:template match="/connection_details">
<!-- duplicate the enclosing <connection_details env=xxx" element -->
<xsl:element name="connection_details">
<xsl:attribute name="env">
<xsl:value-of select="#env"/>
</xsl:attribute>
...
<!-- close the <connection_details> element -->
</xsl:element>
</xsl:template>
</xsl:stylesheet>
server.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8133" 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="8130" protocol="HTTP/1.1" redirectPort="8131"/>
<Connector port="8132" protocol="AJP/1.3" redirectPort="8131"/>
<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="em_bootstrap" path="/bootstrap" reloadable="true" source="org.eclipse.jst.jee.server:em_bootstrap">
</Context></Host>
</Engine>
</Service>
</Server>
This turned out to be a bad case of not checking the Filters. There was a caching filter applied in the web.xml, probably the only place I didn't check. It was incorrectly using the request.getRequestURI as the key for the cache, when in reality it needed the entire request string to properly place it in the cache.
Thanks