Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-26-2008, 03:43 PM
Trained Alumni
 
Posts: 342
Default [SOLVED] Getting at Zimbra Data from JSP

So when some action is performed on my Zimlet (e.g. user right clicks on the icon), I want the JSP to be able to get at the users username, or email address, or some other attribute....and then return some data to the Zimlet based on who they are.

So how does one get at that Zimbra data from a JSP?

I've tried to use the SalesForce Zimlet as an example and have added some of it to my JSP app...

Code:
  
<%@ page language="java" import="com.sun.jndi.ldap.*, java.io.*, java.util.*, javax.naming.*, javax.naming.dir
ectory.*"%>
<%@ page import="com.zimbra.cs.account.Provisioning" %>
<%@ page import="com.zimbra.cs.account.Account" %>
<%@ page import="com.zimbra.cs.account.AuthToken" %>
<%@ page import="com.zimbra.cs.mailbox.Mailbox" %>
<%@ page import="com.zimbra.cs.index.MailboxIndex" %>
<%@ page import="com.zimbra.cs.account.AuthTokenException" %>
<%@ page import="com.zimbra.cs.service.ServiceException" %>
<%@ page import="com.zimbra.cs.index.queryparser.ParseException" %>
<%@ page import="com.zimbra.cs.index.ZimbraQueryResults" %>
<%@ page import="com.zimbra.cs.index.ZimbraHit" %>
<%@ page import="com.zimbra.cs.index.MessageHit" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.zimbra.cs.mailbox.Appointment" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>

....OTHER CODE IN HERE.....

    Cookie[] cookies = request.getCookies();
    String authTokenString = "";
    for (Cookie cooky : cookies) {
        if (cooky.getName().equals("ZM_AUTH_TOKEN")) {
            authTokenString = cooky.getValue();
        }
    }

    try {
        AuthToken authToken = AuthToken.getAuthToken(authTokenString);
        Account acct = Provisioning.getInstance().getAccountById(authToken.getAccountId());
        Mailbox mbox = Mailbox.getMailboxByAccount(acct);
                output.println("<br/><br/>" + acct + " " + mbox);
        } catch (AuthTokenException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
But I get errors like such....

Code:
HTTP ERROR: 500

PWC6033: Unable to compile class for JSP

PWC6199: Generated servlet error:
Only a type can be imported. com.zimbra.cs.service.ServiceException resolves to a package

PWC6197: An error occurred at line: 35 in the jsp file: /zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
PWC6199: Generated servlet error:
The method getAccountById(String) is undefined for the type Provisioning

PWC6197: An error occurred at line: 35 in the jsp file: /zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
PWC6199: Generated servlet error:
The method getMailboxByAccount(Account) is undefined for the type Mailbox

PWC6197: An error occurred at line: 35 in the jsp file: /zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
PWC6199: Generated servlet error:
ServiceException cannot be resolved to a type

PWC6197: An error occurred at line: 35 in the jsp file: /zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
PWC6199: Generated servlet error:
e cannot be resolved


RequestURI=/service/zimlet/_dev/edu_wiu_email_starnum/ldap.jsp
Any ideas?

Thanks,
Matt
Reply With Quote
  #2 (permalink)  
Old 11-26-2008, 06:37 PM
Junior Member
 
Posts: 6
Default

I was having the same problem yesterday, I discovered that you also have to include
<%@ page import="com.zimbra.cs.account.Provisioning.Account By" %>

and to get the account attributes I used this:
Account acct = Provisioning.getInstance().get(AccountBy.id, authToken.getAccountId());
Reply With Quote
  #3 (permalink)  
Old 11-26-2008, 10:50 PM
Trained Alumni
 
Posts: 342
Default

Awesome...thanks...now I get the big list with all attributes and values.

So how do I pull specific attribute values out of 'acct object'? I tried acct.ATTRID, but that gave me an error. Specifically I need to grab the account UID.

Thanks,
Matt
Reply With Quote
  #4 (permalink)  
Old 11-26-2008, 11:15 PM
Trained Alumni
 
Posts: 342
Default

Found it...'acct.getUid()'...so this is the code. If someone thinks there is a better way to do this, let me know.

Thanks,
Matt

Code:
	
<%@ page import="com.zimbra.cs.account.Provisioning" %>
<%@ page import="com.zimbra.cs.account.Provisioning.AccountBy" %>
<%@ page import="com.zimbra.cs.account.Account" %>
<%@ page import="com.zimbra.cs.account.AuthToken" %>

    Cookie[] cookies = request.getCookies();
    String authTokenString = "";
    for (Cookie cooky : cookies) {
        if (cooky.getName().equals("ZM_AUTH_TOKEN")) {
            authTokenString = cooky.getValue();
        }
    }
	AuthToken authToken = AuthToken.getAuthToken(authTokenString);
  Account acct = Provisioning.getInstance().get(AccountBy.id, authToken.getAccountId());

  output.println("<br/><br/>"+acct.getUid());
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.