none
EWS Java API 1.1.5 convertId(): Where to get required mailbox from? RRS feed

  • Question

  • Hi,

    I am new to EWS Java API and trying to integrate it in our application.

    It seems that we 've saved old formatted item id's, since I'm getting an ErrorInvalidIdMalformedEwsLegacyIdFormat exception, when trying to bind an Appointment with one of our itemIds. We are using Exchange 2007 SP1 version.

    I've found an algorithm to convert the old itemId format into the new ews required one:

    private String getConvertedEWSID(ExchangeService exchangeService, String oldItemId, String parentMailbox) throws ExchangeServerIntegrationException {
            //create a request to convert identifiers
            AlternateId objAltID = new AlternateId();
            objAltID.setFormat(IdFormat.EwsLegacyId); // EntryId);
            objAltID.setMailbox("testuser@testdomain.com"); //
            objAltID.setUniqueId(oldItemId);

            //convert old id format into to one
            AlternateIdBase objOldIDBase;
            try {
                objOldIDBase = exchangeService.convertId(objAltID , IdFormat.EwsId);
            } catch (Exception ex) {
                logger.error(ex);
                throw new ExchangeServerIntegrationException("Unable to convert ews itemId from old to new (after Exchange 2007 SP1) format", ex);
            }

            if (objOldIDBase != null) {
                AlternateId objOldIDResp = (AlternateId) objOldIDBase;
                return objOldIDResp.getUniqueId();
            } else {
                throw new ExchangeServerIntegrationException("Unable to convert ews itemId from old to new (after Exchange 2007 SP1) format");
            }
        }

    As you see, I've hardcoded the mailbox to use with "testuser@testdomain.com". Of course, I would like to overhand this information with the parameter parentMailbox, but I've no idea so far on where to get this information respectively, how the ews api is collecting this information.

    I would be very grateful for help in this matter.

    Best wishes

    Hecate84

    Tuesday, February 21, 2012 8:41 AM

All replies

  • Hi mates, finally I got a solution for this problem:

    private String getExchangeServiceAuthorizationUsersMailAddress(ExchangeService exchangeService, String username) {
            NameResolutionCollection resolvedMailAdresses;
            try {
                resolvedMailAdresses = exchangeService.resolveName(username);
            } catch (Exception ex) {
                throw new ExchangeServerIntegrationException("Failed to resolve mailaddress by exchange user's name %s in order to convert ews itemId from old to new (Exchange 2007 SP1 and later versions) format");
            }
            if (resolvedMailAdresses != null) {
                Iterator<NameResolution> nrIt = resolvedMailAdresses.iterator();
                NameResolution nameResolution = nrIt.next();
                if (nameResolution != null) {
                    EmailAddress emailAddress = nameResolution.getMailbox();
                    if (emailAddress != null) {
                        return emailAddress.getAddress();
                    }
                }
            }
            return "";
        }

    You will need the authorization user (same, you are using with the credentials of your exchangeService).

    Wednesday, February 22, 2012 10:03 AM