Skip to content

Commit

Permalink
Resolves #95
Browse files Browse the repository at this point in the history
  • Loading branch information
varontron committed Oct 28, 2018
1 parent 9834a6d commit 41434c5
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.javanet.NetHttpTransport;

import com.novartis.opensource.yada.ConnectionFactory;
Expand Down Expand Up @@ -145,6 +146,18 @@ public class RESTAdaptor extends Adaptor {
*/
private static final String KEYSTORE_TYPE_JKS = "jks";

/**
* Constant equal to: {@value}.
* @since 8.7.4
*/
private static final int HTTP_STATUS_401 = 401;

/**
* Constant equal to: {@value}.
* @since 8.7.4
*/
private static final int HTTP_STATUS_403 = 403;

/**
* Variable to hold the proxy server string if necessary
*/
Expand Down Expand Up @@ -465,16 +478,27 @@ protected static boolean isPostPutPatch(String method)
* @param request the request object
* @return a String containing the response data
* @throws YADAAdaptorExecutionException when reading the input stream fails
* @throws YADASecurityException when the service returns a 401 or 403
* @since 8.7.0
*/
private String processResponse(HttpRequest request) throws YADAAdaptorExecutionException
*/
private String processResponse(HttpRequest request) throws YADAAdaptorExecutionException, YADASecurityException
{
String result = "";
HttpResponse response;
HttpResponse response = null;
try
{
response = request.execute();
}
catch (HttpResponseException e)
{
int code = e.getStatusCode();
if(code == HTTP_STATUS_401 || code == HTTP_STATUS_403)
{
String msg = "Unauthorized: "+e.getStatusMessage();
throw new YADASecurityException(msg,e);
}

}
catch (IOException e)
{
String msg = "Unable to execute request.";
Expand Down

0 comments on commit 41434c5

Please sign in to comment.