mResponseProtocol = mRequestProtocol = requestProtocol; Element eFormat = ctxt == null ? null : ctxt.getOptionalElement(E_FORMAT); if (eFormat != null) { String format = eFormat.getAttribute(A_TYPE, TYPE_XML); if (format.equals(TYPE_XML) && requestProtocol == SoapProtocol.SoapJS) mResponseProtocol = SoapProtocol.Soap12; else if (format.equals(TYPE_JAVASCRIPT)) mResponseProtocol = SoapProtocol.SoapJS; }
mSessionSuppressed = true; mUnqualifiedItemIds = lc.mUnqualifiedItemIds;
	public ZimbraSoapContext(Element ctxt, Map context, SoapProtocol requestProtocol) throws ServiceException {	    if (ctxt != null && !ctxt.getQName().equals(CONTEXT)) 	        throw new IllegalArgumentException("expected ctxt, got: " + ctxt.getQualifiedName());        Provisioning prov = Provisioning.getInstance();        // figure out if we're explicitly asking for a return format        mResponseProtocol = mRequestProtocol = requestProtocol;        Element eFormat = ctxt == null ? null : ctxt.getOptionalElement(E_FORMAT);        if (eFormat != null) {            String format = eFormat.getAttribute(A_TYPE, TYPE_XML);            if (format.equals(TYPE_XML) && requestProtocol == SoapProtocol.SoapJS)                mResponseProtocol = SoapProtocol.Soap12;            else if (format.equals(TYPE_JAVASCRIPT))                mResponseProtocol = SoapProtocol.SoapJS;        }        // find out if we're executing in another user's context        Account account = null;        Element eAccount = ctxt == null ? null : ctxt.getOptionalElement(E_ACCOUNT);		if (eAccount != null) {		    String key = eAccount.getAttribute(A_BY, null);		    String value = eAccount.getText();            if (key == null) {                mRequestedAccountId = null;            } else if (key.equals(BY_NAME)) {	            account = prov.get(AccountBy.name, value);	            if (account == null)                    throw AccountServiceException.NO_SUCH_ACCOUNT(value);	            mRequestedAccountId = account.getId();	        } else if (key.equals(BY_ID)) {	            mRequestedAccountId = value;            } else {	            throw ServiceException.INVALID_REQUEST("unknown value for by: " + key, null);            }            // while we're here, check the hop count to detect loops            mHopCount = (int) Math.max(eAccount.getAttributeLong(A_HOPCOUNT, 0), 0);            if (mHopCount > MAX_HOP_COUNT)                throw ServiceException.TOO_MANY_HOPS();            mMountpointTraversed = eAccount.getAttributeBool(A_MOUNTPOINT, false);		} else {		    mRequestedAccountId = null;		}        // check for auth token in engine context if not in header  		mRawAuthToken = (ctxt == null ? null : ctxt.getAttribute(E_AUTH_TOKEN, null));		if (mRawAuthToken == null)		    mRawAuthToken = (String) context.get(SoapServlet.ZIMBRA_AUTH_TOKEN);        // parse auth token and check validity		if (mRawAuthToken != null && !mRawAuthToken.equals("")) {			try {				mAuthToken = AuthToken.getAuthToken(mRawAuthToken);				if (mAuthToken.isExpired())					throw ServiceException.AUTH_EXPIRED();				mAuthTokenAccountId = mAuthToken.getAccountId();			} catch (AuthTokenException e) {				// ignore and leave null				mAuthToken = null;				if (sLog.isDebugEnabled())					sLog.debug("ZimbraContext AuthToken error: " + e.getMessage(), e);			}		}                // look for the notification sequence id, for notification reliability        // <notify seq="nn">		Element notify = (ctxt == null ? null : ctxt.getOptionalElement(E_NOTIFY));        if (notify != null)             mNotificationSeqNo = (int) notify.getAttributeLong(A_SEQNO, 0);        // constrain operations if we know the max change number the client knows about        Element change = (ctxt == null ? null : ctxt.getOptionalElement(E_CHANGE));        if (change != null) {            try {                String token = change.getAttribute(A_CHANGE_ID, "-1");                int delimiter = token.indexOf('-');                mMaximumChangeId = Integer.parseInt(delimiter < 1 ? token : token.substring(0, delimiter));                if (change.getAttribute(A_TYPE, CHANGE_MODIFIED).equals(CHANGE_MODIFIED))                    mChangeConstraintType = OperationContext.CHECK_MODIFIED;                else                    mChangeConstraintType = OperationContext.CHECK_CREATED;            } catch (NumberFormatException nfe) { }        }        // if the caller specifies an execution host or if we're on the wrong host, proxy        mIsProxyRequest = false;        String targetServerId = ctxt == null ? null : ctxt.getAttribute(E_TARGET_SERVER, null);        if (targetServerId != null) {            HttpServletRequest req = (HttpServletRequest) context.get(SoapServlet.SERVLET_REQUEST);            if (req != null) {            	mProxyTarget = new ProxyTarget(targetServerId, mRawAuthToken, req);                mIsProxyRequest = !mProxyTarget.isTargetLocal();            } else {                sLog.warn("Missing SERVLET_REQUEST key in request context");            }        }        // record session-related info and validate any specified sessions        //   (don't create new sessions yet)        if (ctxt != null) {            mHaltNotifications = ctxt.getOptionalElement(E_NO_NOTIFY) != null;            for (Iterator it = ctxt.elementIterator(E_SESSION_ID); it.hasNext(); ) {                // they specified it, so create a SessionInfo and thereby ping the session as a keepalive                parseSessionElement((Element) it.next());            }            mSessionSuppressed = ctxt.getOptionalElement(E_NO_SESSION) != null;        }        // temporary hack: don't qualify item ids in reponses, if so requested        mUnqualifiedItemIds = (ctxt != null && ctxt.getOptionalElement(E_NO_QUALIFY) != null);                // Handle user agent if specified by the client.  The user agent string is formatted        // as "name/version".        Element userAgent = (ctxt == null ? null : ctxt.getOptionalElement(E_USER_AGENT));        if (userAgent != null) {            String name = userAgent.getAttribute(A_NAME, null);            String version = userAgent.getAttribute(A_VERSION, null);            if (!StringUtil.isNullOrEmpty(name)) {                mUserAgent = name;                if (!StringUtil.isNullOrEmpty(version))                    mUserAgent = mUserAgent + "/" + version;            }        }    }