You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by "Mariangela Hills (JIRA)" <ji...@apache.org> on 2014/11/14 06:44:33 UTC

[jira] [Created] (STRATOS-964) Some REST API are not returning response codes

Mariangela Hills created STRATOS-964:
----------------------------------------

             Summary: Some REST API are not returning response codes
                 Key: STRATOS-964
                 URL: https://issues.apache.org/jira/browse/STRATOS-964
             Project: Stratos
          Issue Type: Bug
          Components: REST API
    Affects Versions: 4.0.0 M4
            Reporter: Mariangela Hills


When looking though the code, I noticed that some of the REST APIs do not return a response code. All HTTP requests sent in REST API  should return a response code. The following code is one such example:

@GET
    @Path("/tenant/{tenantDomain}")
    @Consumes("application/json")
    @Produces("application/json")
    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
    @SuperTenantService(true)
    public TenantInfoBean getTenant(@PathParam("tenantDomain") String tenantDomain) throws RestAPIException {

        try {
            return getTenantForDomain(tenantDomain);
        } catch (Exception e) {
            String msg = "Error in getting tenant information for tenant " + tenantDomain;
            log.error(msg, e);
            throw new RestAPIException(msg);
        }
    }

    private TenantInfoBean getTenantForDomain(String tenantDomain) throws Exception {

        TenantManager tenantManager = ServiceHolder.getTenantManager();

        int tenantId;
        try {
            tenantId = tenantManager.getTenantId(tenantDomain);
        } catch (UserStoreException e) {
            String msg = "Error in retrieving the tenant id for the tenant domain: " +
                    tenantDomain + ".";
            log.error(msg);
            throw new Exception(msg, e);
        }
        Tenant tenant;
        try {
            tenant = (Tenant) tenantManager.getTenant(tenantId);
        } catch (UserStoreException e) {
            String msg = "Error in retrieving the tenant from the tenant manager.";
            log.error(msg);
            throw new Exception(msg, e);
        }

        TenantInfoBean bean = TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant);

        // retrieve first and last names from the UserStoreManager
        bean.setFirstname(ClaimsMgtUtil.getFirstNamefromUserStoreManager(
                ServiceHolder.getRealmService(), tenantId));
        bean.setLastname(ClaimsMgtUtil.getLastNamefromUserStoreManager(
                ServiceHolder.getRealmService(), tenantId));

        //getting the subscription plan
        String activePlan = "";
        //TODO: usage plan using billing service

        if (activePlan != null && activePlan.trim().length() > 0) {
            bean.setUsagePlan(activePlan);
        } else {
            bean.setUsagePlan("");
        }

        return bean;
    }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Re: [jira] [Created] (STRATOS-964) Some REST API are not returning response codes

Posted by Udara Liyanage <ud...@wso2.com>.
Hi Mari,

Yes we may need to fix them as other endpoints. As I remember those were
already fixed, may be we have lose them in merge process. Will have a look.

Thank you for finding this.

On Fri, Nov 14, 2014 at 11:14 AM, Mariangela Hills (JIRA) <ji...@apache.org>
wrote:

> Mariangela Hills created STRATOS-964:
> ----------------------------------------
>
>              Summary: Some REST API are not returning response codes
>                  Key: STRATOS-964
>                  URL: https://issues.apache.org/jira/browse/STRATOS-964
>              Project: Stratos
>           Issue Type: Bug
>           Components: REST API
>     Affects Versions: 4.0.0 M4
>             Reporter: Mariangela Hills
>
>
> When looking though the code, I noticed that some of the REST APIs do not
> return a response code. All HTTP requests sent in REST API  should return a
> response code. The following code is one such example:
>
> @GET
>     @Path("/tenant/{tenantDomain}")
>     @Consumes("application/json")
>     @Produces("application/json")
>     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
>     @SuperTenantService(true)
>     public TenantInfoBean getTenant(@PathParam("tenantDomain") String
> tenantDomain) throws RestAPIException {
>
>         try {
>             return getTenantForDomain(tenantDomain);
>         } catch (Exception e) {
>             String msg = "Error in getting tenant information for tenant "
> + tenantDomain;
>             log.error(msg, e);
>             throw new RestAPIException(msg);
>         }
>     }
>
>     private TenantInfoBean getTenantForDomain(String tenantDomain) throws
> Exception {
>
>         TenantManager tenantManager = ServiceHolder.getTenantManager();
>
>         int tenantId;
>         try {
>             tenantId = tenantManager.getTenantId(tenantDomain);
>         } catch (UserStoreException e) {
>             String msg = "Error in retrieving the tenant id for the tenant
> domain: " +
>                     tenantDomain + ".";
>             log.error(msg);
>             throw new Exception(msg, e);
>         }
>         Tenant tenant;
>         try {
>             tenant = (Tenant) tenantManager.getTenant(tenantId);
>         } catch (UserStoreException e) {
>             String msg = "Error in retrieving the tenant from the tenant
> manager.";
>             log.error(msg);
>             throw new Exception(msg, e);
>         }
>
>         TenantInfoBean bean =
> TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant);
>
>         // retrieve first and last names from the UserStoreManager
>         bean.setFirstname(ClaimsMgtUtil.getFirstNamefromUserStoreManager(
>                 ServiceHolder.getRealmService(), tenantId));
>         bean.setLastname(ClaimsMgtUtil.getLastNamefromUserStoreManager(
>                 ServiceHolder.getRealmService(), tenantId));
>
>         //getting the subscription plan
>         String activePlan = "";
>         //TODO: usage plan using billing service
>
>         if (activePlan != null && activePlan.trim().length() > 0) {
>             bean.setUsagePlan(activePlan);
>         } else {
>             bean.setUsagePlan("");
>         }
>
>         return bean;
>     }
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.3.4#6332)
>



-- 

Udara Liyanage
Software Engineer
WSO2, Inc.: http://wso2.com
lean. enterprise. middleware

web: http://udaraliyanage.wordpress.com
phone: +94 71 443 6897