Search in sources :

Example 6 with ResponseObject

use of org.apache.cloudstack.api.ResponseObject in project cloudstack by apache.

the class ApiSerializerHelper method toSerializedString.

public static String toSerializedString(Object result) {
    if (result != null) {
        Class<?> clz = result.getClass();
        Gson gson = ApiGsonHelper.getBuilder().create();
        if (result instanceof ResponseObject) {
            return clz.getName() + token + ((ResponseObject) result).getObjectName() + token + gson.toJson(result);
        } else {
            return clz.getName() + token + gson.toJson(result);
        }
    }
    return null;
}
Also used : Gson(com.google.gson.Gson) ResponseObject(org.apache.cloudstack.api.ResponseObject)

Example 7 with ResponseObject

use of org.apache.cloudstack.api.ResponseObject in project cloudstack by apache.

the class ApiServer method createLoginResponse.

private ResponseObject createLoginResponse(HttpSession session) {
    LoginCmdResponse response = new LoginCmdResponse();
    response.setTimeout(session.getMaxInactiveInterval());
    final String user_UUID = (String) session.getAttribute("user_UUID");
    response.setUserId(user_UUID);
    final String domain_UUID = (String) session.getAttribute("domain_UUID");
    response.setDomainId(domain_UUID);
    synchronized (session) {
        session.removeAttribute("user_UUID");
        session.removeAttribute("domain_UUID");
    }
    final Enumeration attrNames = session.getAttributeNames();
    if (attrNames != null) {
        while (attrNames.hasMoreElements()) {
            final String attrName = (String) attrNames.nextElement();
            final Object attrObj = session.getAttribute(attrName);
            if (ApiConstants.USERNAME.equalsIgnoreCase(attrName)) {
                response.setUsername(attrObj.toString());
            }
            if (ApiConstants.ACCOUNT.equalsIgnoreCase(attrName)) {
                response.setAccount(attrObj.toString());
            }
            if (ApiConstants.FIRSTNAME.equalsIgnoreCase(attrName)) {
                response.setFirstName(attrObj.toString());
            }
            if (ApiConstants.LASTNAME.equalsIgnoreCase(attrName)) {
                response.setLastName(attrObj.toString());
            }
            if (ApiConstants.TYPE.equalsIgnoreCase(attrName)) {
                response.setType((attrObj.toString()));
            }
            if (ApiConstants.TIMEZONE.equalsIgnoreCase(attrName)) {
                response.setTimeZone(attrObj.toString());
            }
            if (ApiConstants.TIMEZONEOFFSET.equalsIgnoreCase(attrName)) {
                response.setTimeZoneOffset(attrObj.toString());
            }
            if (ApiConstants.REGISTERED.equalsIgnoreCase(attrName)) {
                response.setRegistered(attrObj.toString());
            }
            if (ApiConstants.SESSIONKEY.equalsIgnoreCase(attrName)) {
                response.setSessionKey(attrObj.toString());
            }
        }
    }
    response.setResponseName("loginresponse");
    return response;
}
Also used : Enumeration(java.util.Enumeration) ExceptionProxyObject(com.cloud.utils.exception.ExceptionProxyObject) ResponseObject(org.apache.cloudstack.api.ResponseObject) LoginCmdResponse(org.apache.cloudstack.api.response.LoginCmdResponse)

Aggregations

ResponseObject (org.apache.cloudstack.api.ResponseObject)7 AsyncJobResponse (org.apache.cloudstack.api.response.AsyncJobResponse)3 ExceptionProxyObject (com.cloud.utils.exception.ExceptionProxyObject)2 Gson (com.google.gson.Gson)2 Date (java.util.Date)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 Param (com.cloud.serializer.Param)1 Account (com.cloud.user.Account)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 SerializedName (com.google.gson.annotations.SerializedName)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 RoleType (org.apache.cloudstack.acl.RoleType)1 AuthenticationCmdResponse (org.apache.cloudstack.api.response.AuthenticationCmdResponse)1 CreateCmdResponse (org.apache.cloudstack.api.response.CreateCmdResponse)1 ExceptionResponse (org.apache.cloudstack.api.response.ExceptionResponse)1 LoginCmdResponse (org.apache.cloudstack.api.response.LoginCmdResponse)1 AsyncJob (org.apache.cloudstack.framework.jobs.AsyncJob)1