Access host variable from servlet

64 views
Skip to first unread message

Nathan Maves

unread,
Oct 23, 2012, 3:58:23 PM10/23/12
to dot...@googlegroups.com
Is this possible?  I have a custom email servlet and I would love to pull a host variable from the servlet.

Nathan

Jason Tesser

unread,
Oct 23, 2012, 4:09:22 PM10/23/12
to dot...@googlegroups.com
use the HostVariableAPI and the COntentAPI to get what you need.

Thanks,
Jason S. Tesser
Director, Support Services
dotCMS, Inc.
T: 305.858.1422 x7003
http://twitter.com/dotCMS
www.dotcms.com
> --
> You received this message because you are subscribed to the Google Groups
> "dotCMS User Group" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/dotcms/-/xq1apPpZWWMJ.
> To post to this group, send email to dot...@googlegroups.com.
> To unsubscribe from this group, send email to
> dotcms+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotcms?hl=en.

Nathan Maves

unread,
Oct 23, 2012, 10:08:17 PM10/23/12
to dot...@googlegroups.com, jason....@dotcms.com
Are you suggesting using the restful API for this? or the straight Java API?

Jason Tesser

unread,
Oct 23, 2012, 10:22:46 PM10/23/12
to dot...@googlegroups.com
JavaAPI


Thanks,
Jason Tesser
dotCMS Director, Support Services
1-305-858-1422
> https://groups.google.com/d/msg/dotcms/-/x3ZCjBFg3H4J.

Nathan Maves

unread,
Dec 22, 2012, 2:03:13 PM12/22/12
to dot...@googlegroups.com
Sorry I has taken me so long to get back to this thread.

Below is what I have in my Servlet.  My issue is that I don't know how to pull the current host/user that is making the request?  For a little more background this is a Servlet that handles form submissions and emails them via Amazon's Simple Email Service (SES).

final HostAPI hostAPI = APILocator.getHostAPI();
final HostVariableAPI hostVariableAPI = APILocator.getHostVariableAPI();
final ContentletAPI contentletAPI = APILocator.getContentletAPI();

hostVariableAPI.getVariablesForHost(hostId, user, respectFrontendRoles);

Maria Ahues Bouza

unread,
Dec 23, 2012, 3:54:50 PM12/23/12
to dot...@googlegroups.com
Nathan,

On this Codeshare you'll see how to he the user and host

Maria

Sent from my iPhone
To view this discussion on the web visit https://groups.google.com/d/msg/dotcms/-/yjHTKVrVZ-gJ.

Nathan Maves

unread,
Dec 26, 2012, 12:20:09 PM12/26/12
to dot...@googlegroups.com
I tried this approach but I am getting the following exception.  My code is below the exception as well.  How with this code know which host to pull the variables from?  I need the servlet to pull a host variable for each host I have when they submit to the servlet.

[26/12/12 10:01:37:615 MST]  INFO servlet.AmazonMailerServlet: Composing email
[26/12/12 10:01:37:649 MST] ERROR servlet.AmazonMailerServlet: Error sending message. com.dotmarketing.exception.DotSecurityException: User doesn't have permission to read the host variables 
com.dotmarketing.exception.DotSecurityException: User doesn't have permission to read the host variables 
at com.dotmarketing.portlets.hostvariable.bussiness.HostVariableAPIImpl.getVariablesForHost(HostVariableAPIImpl.java:66)
at com.mindfreez.plugins.amazonmailer.servlet.AmazonMailerServlet.service(AmazonMailerServlet.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dotmarketing.filters.CMSFilter.doFilter(CMSFilter.java:128)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dotmarketing.filters.AutoLoginFilter.doFilter(AutoLoginFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dotmarketing.cms.urlmap.filters.URLMapFilter.doFilter(URLMapFilter.java:86)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dotmarketing.filters.TimeMachineFilter.doFilter(TimeMachineFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dotmarketing.filters.CharsetEncodingFilter.doFilter(CharsetEncodingFilter.java:140)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

Here is the code I am using to pull the host variables.

// User to check in as
User user = APILocator.getUserAPI().getSystemUser();

// respect CMS Anonymous permissions
boolean respectFrontendRoles = false;

// Host on which to place the content
Host host = APILocator.getHostAPI().findDefaultHost(user, respectFrontendRoles);

final List<HostVariable> variablesForHost = APILocator.getHostVariableAPI().getVariablesForHost(host.getInode(), user, respectFrontendRoles);

String to = null;
for (HostVariable hostVariable : variablesForHost) {
if (hostVariable.getKey().equalsIgnoreCase("contactEmail")) {
to = hostVariable.getValue();
}
}

AB

unread,
Jan 29, 2014, 10:21:56 AM1/29/14
to dot...@googlegroups.com
This error can be fixed by using host.getIdentifier() not host.getInode() on this line:

final List<HostVariable> variablesForHost = APILocator.getHostVariableAPI().getVariablesForHost(host.getIdentifier(), user, respectFrontendRoles);
Reply all
Reply to author
Forward
0 new messages