airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject svn commit: r1411313 [1/2] - in /airavata/trunk/modules: airavata-client/src/main/java/org/apache/airavata/client/ airavata-client/src/main/java/org/apache/airavata/client/api/ airavata-client/src/main/java/org/apache/airavata/client/impl/ gfac-core/sr...
Date Mon, 19 Nov 2012 17:13:59 GMT
Author: chathuri
Date: Mon Nov 19 17:13:56 2012
New Revision: 1411313

URL: http://svn.apache.org/viewvc?rev=1411313&view=rev
Log:
integrating security with REST client

Added:
    airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/PasswordCallBackImpl.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/utils/Callback.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/utils/ClientConstant.java
Removed:
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/AllRegistryResourceClients.java
    airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/a.java
Modified:
    airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
    airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClientUtils.java
    airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java
    airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/Test.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/BasicRegistryResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ConfigurationResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ExperimentResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ProjectResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ProvenanceResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/PublishedWorkflowResourceClient.java
    airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/UserWorkflowResourceClient.java
    airavata/trunk/modules/rest/mappings/src/main/java/org/apache/airavata/rest/mappings/utils/ResourcePathConstants.java

Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClient.java Mon Nov 19 17:13:56 2012
@@ -55,12 +55,7 @@ import org.apache.airavata.client.api.Ex
 import org.apache.airavata.client.api.ProvenanceManager;
 import org.apache.airavata.client.api.UserManager;
 import org.apache.airavata.client.api.WorkflowManager;
-import org.apache.airavata.client.impl.AiravataManagerImpl;
-import org.apache.airavata.client.impl.ApplicationManagerImpl;
-import org.apache.airavata.client.impl.ExecutionManagerImpl;
-import org.apache.airavata.client.impl.ProvenanceManagerImpl;
-import org.apache.airavata.client.impl.UserManagerImpl;
-import org.apache.airavata.client.impl.WorkflowManagerImpl;
+import org.apache.airavata.client.impl.*;
 import org.apache.airavata.client.stub.interpretor.NameValue;
 import org.apache.airavata.client.stub.interpretor.WorkflowInterpretorStub;
 import org.apache.airavata.common.utils.Version;
@@ -110,6 +105,9 @@ public class AiravataClient implements A
 	private static String workflow = "";
 	private static WorkflowContextHeaderBuilder builder;
 	private String currentUser;
+    private String password;
+    private URI regitryURI;
+    private PasswordCallBackImpl passwordCallBack;
 
 	private AiravataRegistry2 registry;
 
@@ -507,48 +505,51 @@ public class AiravataClient implements A
 		AiravataClient.workflow = workflow;
 	}
 
-    public AllRegistryResourceClients getRegistryResourceClient(){
-        AllRegistryResourceClients allRegistryResourceClients = new AllRegistryResourceClients();
-        return allRegistryResourceClients;
-    }
-
 	public ConfigurationResourceClient getConfigurationResourceClient (){
-       ConfigurationResourceClient configurationResourceClient = new ConfigurationResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        ConfigurationResourceClient configurationResourceClient = new ConfigurationResourceClient(getCurrentUser(), passwordCallBack);
         return configurationResourceClient;
     }
 
     public DescriptorResourceClient getDescriptorResourceClient (){
-        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient(getCurrentUser(), passwordCallBack);
         return descriptorResourceClient;
     }
 
     public ExperimentResourceClient getExperimentResourceClient (){
-        ExperimentResourceClient experimentResourceClient = new ExperimentResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        ExperimentResourceClient experimentResourceClient = new ExperimentResourceClient(getCurrentUser(), passwordCallBack);
         return experimentResourceClient;
     }
 
     public ProvenanceResourceClient getProvenanceResouceClient (){
-        ProvenanceResourceClient provenanceResourceClient = new ProvenanceResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        ProvenanceResourceClient provenanceResourceClient = new ProvenanceResourceClient(getCurrentUser(), passwordCallBack);
         return provenanceResourceClient;
     }
 
     public ProjectResourceClient getProjectResourceClient (){
-        ProjectResourceClient projectResourceClient = new ProjectResourceClient();
+        PasswordCallBackImpl passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        ProjectResourceClient projectResourceClient = new ProjectResourceClient(getCurrentUser(), passwordCallBack);
         return projectResourceClient;
     }
 
     public PublishedWorkflowResourceClient getPublishedWFResourceClient (){
-        PublishedWorkflowResourceClient publishedWorkflowResourceClient = new PublishedWorkflowResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        PublishedWorkflowResourceClient publishedWorkflowResourceClient = new PublishedWorkflowResourceClient(getCurrentUser(), passwordCallBack);
         return publishedWorkflowResourceClient;
     }
 
     public UserWorkflowResourceClient getUserWFResourceClient () {
-        UserWorkflowResourceClient userWorkflowResourceClient = new UserWorkflowResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        UserWorkflowResourceClient userWorkflowResourceClient = new UserWorkflowResourceClient(getCurrentUser(), passwordCallBack);
         return userWorkflowResourceClient;
     }
 
     public BasicRegistryResourceClient getBasicResourceClient (){
-        BasicRegistryResourceClient basicRegistryResourceClient = new BasicRegistryResourceClient();
+        passwordCallBack = new PasswordCallBackImpl(getCurrentUser(), getPassword());
+        BasicRegistryResourceClient basicRegistryResourceClient = new BasicRegistryResourceClient(getCurrentUser(), passwordCallBack);
         return basicRegistryResourceClient;
     }
 
@@ -1021,4 +1022,19 @@ public class AiravataClient implements A
 		}
 	}
 
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public void setRegitryURI(URI regitryURI) {
+        this.regitryURI = regitryURI;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public URI getRegitryURI() {
+        return regitryURI;
+    }
 }

Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClientUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClientUtils.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClientUtils.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/AiravataClientUtils.java Mon Nov 19 17:13:56 2012
@@ -39,14 +39,18 @@ public class AiravataClientUtils {
 	public static AiravataAPI getAPI(URI registryURL, String username, String password, String alternateUsername) throws MalformedURLException, RepositoryException, RegistryException{
 		AiravataClient apiObj = new AiravataClient();
 		apiObj.setCurrentUser(alternateUsername);
+        apiObj.setPassword(password);
+        apiObj.setRegitryURI(registryURL);
 		return apiObj;
 	}
 
+    @Deprecated
 	public static AiravataAPI getAPI(Map<String,String> configuration) throws MalformedURLException{
 		AiravataClient apiObj = new AiravataClient(configuration);
 		return apiObj;
 	}
 
+    @Deprecated
 	public static AiravataAPI getAPI(String filename) throws MalformedURLException, RegistryException, IOException{
 		AiravataClient apiObj = new AiravataClient(filename);
 		return apiObj;

Modified: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java (original)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/api/AiravataAPI.java Mon Nov 19 17:13:56 2012
@@ -23,6 +23,8 @@ package org.apache.airavata.client.api;
 
 import org.apache.airavata.common.utils.Version;
 
+import java.util.Observable;
+
 
 /**
  * This is the base interface for AiravataAPI which contains all the base methods for Airavata API

Added: airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/PasswordCallBackImpl.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/PasswordCallBackImpl.java?rev=1411313&view=auto
==============================================================================
--- airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/PasswordCallBackImpl.java (added)
+++ airavata/trunk/modules/airavata-client/src/main/java/org/apache/airavata/client/impl/PasswordCallBackImpl.java Mon Nov 19 17:13:56 2012
@@ -0,0 +1,39 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.client.impl;
+
+import org.apache.airavata.rest.utils.Callback;
+
+public class PasswordCallBackImpl implements Callback {
+    private String username;
+    private String password;
+
+    public PasswordCallBackImpl(String username, String password){
+        this.username = username;
+        this.password = password;
+    }
+
+    @Override
+    public String getPassword(String username) {
+       return password;
+    }
+}

Modified: airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java (original)
+++ airavata/trunk/modules/gfac-core/src/main/java/org/apache/airavata/core/gfac/context/GFacConfiguration.java Mon Nov 19 17:13:56 2012
@@ -38,7 +38,12 @@ public class GFacConfiguration {
 
     private String trustedCertLocation;
 
-    public GFacConfiguration(String myProxyServer, String myProxyUser, String myProxyPassphrase, int myProxyLifeCycle, AiravataRegistry2 axis2Registry, String trustedCertLocation) {
+    public GFacConfiguration(String myProxyServer,
+                             String myProxyUser,
+                             String myProxyPassphrase,
+                             int myProxyLifeCycle,
+                             AiravataRegistry2 axis2Registry,
+                             String trustedCertLocation) {
         this.myProxyServer = myProxyServer;
         this.myProxyUser = myProxyUser;
         this.myProxyPassphrase = myProxyPassphrase;

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/Test.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/Test.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/Test.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/Test.java Mon Nov 19 17:13:56 2012
@@ -40,7 +40,7 @@ public class Test {
 
     public static void configurationResourceClientTest(){
         //configuration resource test
-        ConfigurationResourceClient configurationResourceClient = new ConfigurationResourceClient();
+//        ConfigurationResourceClient configurationResourceClient = new ConfigurationResourceClient();
 
 //        System.out.println("###############getConfiguration###############");
 //        Object configuration = configurationResourceClient.getConfiguration("interpreter.url");
@@ -125,7 +125,7 @@ public class Test {
     }
 
     public static void hostDescriptorClientTest(){
-        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient();
+//        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient();
 
 //        boolean localHost = descriptorResourceClient.isHostDescriptorExists("LocalHost");
 //        System.out.println(localHost);
@@ -147,7 +147,7 @@ public class Test {
 //            System.out.println(hostName);
 //        }
 
-        descriptorResourceClient.removeHostDescriptor("testHost");
+//        descriptorResourceClient.removeHostDescriptor("testHost");
 
 //        System.out.println(localHost.getType().getHostName());
 //        System.out.println(localHost.getType().getHostAddress());
@@ -155,7 +155,7 @@ public class Test {
     }
 
     public static void serviceDescriptorClientTest (){
-        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient();
+//        DescriptorResourceClient descriptorResourceClient = new DescriptorResourceClient();
         //service descriptor exists
 //        boolean exists = descriptorResourceClient.isServiceDescriptorExists("echo");
 //        System.out.println(exists);
@@ -323,7 +323,7 @@ public class Test {
     }
 
     public static void projectRegistryClientTest(){
-        ProjectResourceClient projectResourceClient = new ProjectResourceClient();
+//        ProjectResourceClient projectResourceClient = new ProjectResourceClient();
         //isWorkspaceProjectExists
 //        boolean projectExists = projectResourceClient.isWorkspaceProjectExists("default");
 //        System.out.println(projectExists);
@@ -351,7 +351,7 @@ public class Test {
     }
 
     public static void experimentRegistryClient(){
-        ExperimentResourceClient experimentResourceClient = new ExperimentResourceClient();
+//        ExperimentResourceClient experimentResourceClient = new ExperimentResourceClient();
         //add experiment
 //        try {
 //            AiravataExperiment experiment = new AiravataExperiment();
@@ -403,7 +403,7 @@ public class Test {
     }
 
     public static void userWFClientTest (){
-        UserWorkflowResourceClient userWorkflowResourceClient = new UserWorkflowResourceClient();
+//        UserWorkflowResourceClient userWorkflowResourceClient = new UserWorkflowResourceClient();
 //        boolean exists = userWorkflowResourceClient.isWorkflowExists("Workflow1");
 //        System.out.println(exists);
 //         userWorkflowResourceClient.addWorkflow("workflow5", "testworlflowcontent");
@@ -416,7 +416,7 @@ public class Test {
     }
 
     public static void publishWFClientTest () {
-        PublishedWorkflowResourceClient publishedWorkflowResourceClient = new PublishedWorkflowResourceClient();
+//        PublishedWorkflowResourceClient publishedWorkflowResourceClient = new PublishedWorkflowResourceClient();
 //        boolean exists = publishedWorkflowResourceClient.isPublishedWorkflowExists("Workflow2");
 //        System.out.println(exists);
 

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/BasicRegistryResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/BasicRegistryResourceClient.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/BasicRegistryResourceClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/BasicRegistryResourceClient.java Mon Nov 19 17:13:56 2012
@@ -30,6 +30,9 @@ import com.sun.jersey.api.json.JSONConfi
 import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.rest.utils.BasicAuthHeaderUtil;
+import org.apache.airavata.rest.utils.Callback;
+import org.apache.airavata.rest.utils.ClientConstant;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,6 +43,13 @@ import java.net.URI;
 public class BasicRegistryResourceClient {
     private WebResource webResource;
     private final static Logger logger = LoggerFactory.getLogger(BasicRegistryResourceClient.class);
+    private String userName;
+    private Callback callback;
+
+    public BasicRegistryResourceClient(String userName, Callback callback) {
+        this.userName = userName;
+        this.callback = callback;
+    }
 
     private URI getBaseURI() {
         logger.info("Creating Base URI");
@@ -61,12 +71,23 @@ public class BasicRegistryResourceClient
         ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        }else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
+
         Gateway gateway = response.getEntity(Gateway.class);
         return gateway;
     }
@@ -76,10 +97,20 @@ public class BasicRegistryResourceClient
         ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         AiravataUser airavataUser = response.getEntity(AiravataUser.class);
@@ -91,10 +122,20 @@ public class BasicRegistryResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, gateway);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, gateway);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -103,10 +144,20 @@ public class BasicRegistryResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, user);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, user);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 }

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ConfigurationResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ConfigurationResourceClient.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ConfigurationResourceClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/ConfigurationResourceClient.java Mon Nov 19 17:13:56 2012
@@ -31,6 +31,9 @@ import com.sun.jersey.core.util.Multival
 import org.apache.airavata.rest.mappings.resourcemappings.ConfigurationList;
 import org.apache.airavata.rest.mappings.resourcemappings.URLList;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.rest.utils.BasicAuthHeaderUtil;
+import org.apache.airavata.rest.utils.Callback;
+import org.apache.airavata.rest.utils.ClientConstant;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,6 +48,13 @@ import java.util.List;
 public class ConfigurationResourceClient {
     private WebResource webResource;
     private final static Logger logger = LoggerFactory.getLogger(ConfigurationResourceClient.class);
+    private String userName;
+    private Callback callback;
+
+    public ConfigurationResourceClient(String userName, Callback callback) {
+        this.userName = userName;
+        this.callback = callback;
+    }
 
     private URI getBaseURI() {
         logger.info("Creating Base URI");
@@ -69,10 +79,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
         String output = response.getEntity(String.class);
         return output;
@@ -85,10 +105,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
         ConfigurationList configurationList = response.getEntity(ConfigurationList.class);
         List<Object> configurationValueList = new ArrayList<Object>();
@@ -110,10 +140,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -127,10 +167,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -141,10 +191,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
     }
@@ -157,10 +217,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -171,10 +241,20 @@ public class ConfigurationResourceClient
             ClientResponse response = webResource.get(ClientResponse.class);
             int status = response.getStatus();
 
-            if (status != 200) {
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
+            } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+                webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+                response = webResource.get(ClientResponse.class);
+                status = response.getStatus();
+
+                if (status != ClientConstant.HTTP_OK) {
+                    logger.error(response.getEntity(String.class));
+                    throw new RuntimeException("Failed : HTTP error code : "
+                            + status);
+                }
             }
 
             URLList urlList = response.getEntity(URLList.class);
@@ -197,12 +277,21 @@ public class ConfigurationResourceClient
             ClientResponse response = webResource.get(ClientResponse.class);
             int status = response.getStatus();
 
-            if (status != 200) {
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
+            } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+                webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+                response = webResource.get(ClientResponse.class);
+                status = response.getStatus();
+
+                if (status != ClientConstant.HTTP_OK ) {
+                    logger.error(response.getEntity(String.class));
+                    throw new RuntimeException("Failed : HTTP error code : "
+                            + status);
+                }
             }
-
             URLList urlList = response.getEntity(URLList.class);
             String[] uris = urlList.getUris();
             for (String url: uris){
@@ -222,10 +311,20 @@ public class ConfigurationResourceClient
             ClientResponse response = webResource.get(ClientResponse.class);
             int status = response.getStatus();
 
-            if (status != 200) {
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
+            } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+                webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+                response = webResource.get(ClientResponse.class);
+                status = response.getStatus();
+
+                if (status != ClientConstant.HTTP_OK ) {
+                    logger.error(response.getEntity(String.class));
+                    throw new RuntimeException("Failed : HTTP error code : "
+                            + status);
+                }
             }
 
             String uri = response.getEntity(String.class);
@@ -242,10 +341,20 @@ public class ConfigurationResourceClient
             ClientResponse response = webResource.get(ClientResponse.class);
             int status = response.getStatus();
 
-            if (status != 200) {
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
                 logger.error(response.getEntity(String.class));
                 throw new RuntimeException("Failed : HTTP error code : "
                         + status);
+            } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+                webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+                response = webResource.get(ClientResponse.class);
+                status = response.getStatus();
+
+                if (status != ClientConstant.HTTP_OK) {
+                    logger.error(response.getEntity(String.class));
+                    throw new RuntimeException("Failed : HTTP error code : "
+                            + status);
+                }
             }
 
             String uri = response.getEntity(String.class);
@@ -264,10 +373,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -279,10 +398,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -294,10 +423,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -309,10 +448,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -325,10 +474,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -341,10 +500,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -357,10 +526,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -373,10 +552,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, formData);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -387,10 +576,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -399,10 +598,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -413,10 +622,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -425,10 +644,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -437,10 +666,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -449,10 +688,20 @@ public class ConfigurationResourceClient
         ClientResponse response = webResource.delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 

Modified: airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java?rev=1411313&r1=1411312&r2=1411313&view=diff
==============================================================================
--- airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java (original)
+++ airavata/trunk/modules/rest/client/src/main/java/org/apache/airavata/rest/client/DescriptorResourceClient.java Mon Nov 19 17:13:56 2012
@@ -34,6 +34,9 @@ import org.apache.airavata.commons.gfac.
 import org.apache.airavata.rest.mappings.resourcemappings.*;
 import org.apache.airavata.rest.mappings.utils.DescriptorUtil;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
+import org.apache.airavata.rest.utils.BasicAuthHeaderUtil;
+import org.apache.airavata.rest.utils.Callback;
+import org.apache.airavata.rest.utils.ClientConstant;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,6 +52,13 @@ import java.util.Map;
 public class DescriptorResourceClient {
     private WebResource webResource;
     private final static Logger logger = LoggerFactory.getLogger(DescriptorResourceClient.class);
+    private String userName;
+    private Callback callback;
+
+    public DescriptorResourceClient(String userName, Callback callback) {
+        this.userName = userName;
+        this.callback = callback;
+    }
 
     private URI getBaseURI() {
         logger.info("Creating Base URI");
@@ -72,10 +82,22 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }else{
+                return true;
+            }
         } else {
             return true;
         }
@@ -88,10 +110,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, hostDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -102,10 +135,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, hostDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -117,10 +161,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         HostDescriptor hostDescriptor = response.getEntity(HostDescriptor.class);
@@ -135,10 +190,20 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -148,12 +213,22 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
-        }
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
 
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
+        }
         HostDescriptionList hostDescriptionList = response.getEntity(HostDescriptionList.class);
         HostDescriptor[] hostDescriptors = hostDescriptionList.getHostDescriptions();
         List<HostDescription> hostDescriptions = new ArrayList<HostDescription>();
@@ -171,10 +246,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         DescriptorNameList descriptorNameList = response.getEntity(DescriptorNameList.class);
@@ -188,11 +274,23 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
-        } else {
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }else {
+                return true;
+            }
+        }else {
             return true;
         }
     }
@@ -204,10 +302,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, serviceDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -218,10 +327,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, serviceDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -233,10 +353,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ServiceDescriptor serviceDescriptor = response.getEntity(ServiceDescriptor.class);
@@ -251,10 +382,20 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -264,10 +405,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ServiceDescriptionList serviceDescriptionList = response.getEntity(ServiceDescriptionList.class);
@@ -289,10 +441,22 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }else {
+                return true;
+            }
         } else {
             return true;
         }
@@ -311,10 +475,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -330,10 +505,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -350,10 +536,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -369,10 +566,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, applicationDescriptor);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 
@@ -389,10 +597,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ApplicationDescriptor applicationDescriptor = response.getEntity(ApplicationDescriptor.class);
@@ -410,10 +629,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ApplicationDescriptor applicationDescriptor = response.getEntity(ApplicationDescriptor.class);
@@ -429,10 +659,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ApplicationDescriptorList applicationDescriptorList = response.getEntity(ApplicationDescriptorList.class);
@@ -452,10 +693,21 @@ public class DescriptorResourceClient {
 
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         ApplicationDescriptorList applicationDescriptorList = response.getEntity(ApplicationDescriptorList.class);
@@ -473,10 +725,20 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
 
         DescriptorNameList descriptorNameList = response.getEntity(DescriptorNameList.class);
@@ -492,10 +754,20 @@ public class DescriptorResourceClient {
         ClientResponse response = webResource.queryParams(queryParams).accept(MediaType.TEXT_PLAIN).delete(ClientResponse.class);
         int status = response.getStatus();
 
-        if (status != 200) {
+        if (status != ClientConstant.HTTP_OK && status != ClientConstant.HTTP_UNAUTHORIZED) {
             logger.error(response.getEntity(String.class));
             throw new RuntimeException("Failed : HTTP error code : "
                     + status);
+        } else if (status == ClientConstant.HTTP_UNAUTHORIZED){
+            webResource.header("Authorization", BasicAuthHeaderUtil.getBasicAuthHeader(userName, callback.getPassword(userName)));
+            response = webResource.queryParams(queryParams).accept(MediaType.TEXT_PLAIN).delete(ClientResponse.class);
+            status = response.getStatus();
+
+            if (status != ClientConstant.HTTP_OK ) {
+                logger.error(response.getEntity(String.class));
+                throw new RuntimeException("Failed : HTTP error code : "
+                        + status);
+            }
         }
     }
 }



Mime
View raw message