Results 1 to 4 of 4

Thread: [SOLVED] Getting at Zimbra Data from JSP

  1. #1
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    374
    Rep Power
    9

    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

  2. #2
    Join Date
    Nov 2008
    Posts
    6
    Rep Power
    7

    Default

    I was having the same problem yesterday, I discovered that you also have to include
    <&#37;@ 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());

  3. #3
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    374
    Rep Power
    9

    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

  4. #4
    Join Date
    Sep 2006
    Location
    Illinois
    Posts
    374
    Rep Power
    9

    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());

Similar Threads

  1. Replies: 12
    Last Post: 02-25-2008, 07:28 PM
  2. Replies: 22
    Last Post: 12-02-2007, 05:05 PM
  3. [SOLVED] Error Installing Zimbra on RHEL 5
    By harris7139 in forum Installation
    Replies: 10
    Last Post: 09-25-2007, 12:39 PM
  4. svn version still won't start
    By kinaole in forum Developers
    Replies: 0
    Last Post: 10-04-2006, 07:47 AM
  5. Replies: 16
    Last Post: 09-07-2006, 07:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •