X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fclient%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fhttp%2FHClient.java;h=199276bc6b6a55259b6f4115b353b1a2304b0da5;hb=bdb54b7c8a5df0e686490658067c9013ee43dd7a;hp=9255128c756fa2993f807680d5b11d541ca49b17;hpb=d087d3ddd2829ced1d2ffccc5147c377cbcc92cb;p=aaf%2Fauthz.git diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java index 9255128c..199276bc 100644 --- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java +++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -32,6 +32,8 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; +import javax.net.ssl.SSLException; +import javax.net.ssl.SSLHandshakeException; import javax.servlet.http.HttpServletResponse; import org.onap.aaf.cadi.CadiException; @@ -45,11 +47,10 @@ import org.onap.aaf.misc.env.Data; import org.onap.aaf.misc.env.Data.TYPE; import org.onap.aaf.misc.env.util.Pool.Pooled; import org.onap.aaf.misc.rosetta.env.RosettaDF; - /** * Low Level Http Client Mechanism. Chances are, you want the high level "HRcli" * for Rosetta Object Translation - * + * * @author Jonathan * */ @@ -72,7 +73,7 @@ public class HClient implements EClient { this.uri = uri; this.ss = ss; this.connectTimeout = connectTimeout; - pathinfo = query = fragment = null; + pathinfo = query = fragment = null; } @Override @@ -89,7 +90,7 @@ public class HClient implements EClient { public void setPayload(Transfer transfer) { this.transfer = transfer; } - + @Override public void addHeader(String tag, String value) { if (headers == null) @@ -121,7 +122,7 @@ public class HClient implements EClient { } pi.append(pathinfo); } - URI sendURI = null; + URI sendURI = null; try { sendURI = new URI( uri.getScheme(), @@ -133,10 +134,10 @@ public class HClient implements EClient { huc = getConnection(sendURI, pi); huc.setRequestMethod(meth); if (ss!=null) { - ss.setSecurity(huc); + ss.setSecurity(huc); } if (headers != null) - for (Header d : headers) { + for (Header d : headers) { huc.addRequestProperty(d.tag, d.value); } huc.setDoInput(true); @@ -149,13 +150,13 @@ public class HClient implements EClient { } // TODO other settings? There's a bunch here. } catch (APIException e) { - throw e; + throw e; } catch (Exception e) { - if(sendURI==null) { - throw new APIException("Cannot connect to Root URI: '" + uri.toString() + '\'',e); - } else { - throw new APIException("Cannot connect to '" + sendURI.toString() + "' (Root URI: '" + uri.toString() + "')",e); - } + if(sendURI==null) { + throw new APIException("Cannot connect to Root URI: '" + uri.toString() + '\'',e); + } else { + throw new APIException("Cannot connect to '" + sendURI.toString() + "' (Root URI: '" + uri.toString() + "')",e); + } } finally { // ensure all these are reset after sends meth=pathinfo=null; if (headers!=null) { @@ -164,43 +165,43 @@ public class HClient implements EClient { pathinfo = query = fragment = ""; } } - + public URI getURI() { return uri; } - + public void setURI(URI uri) { - this.uri = uri; + this.uri = uri; } public int timeout() { return connectTimeout; } - + protected HttpURLConnection getConnection(URI uri, StringBuilder pi) throws IOException, URISyntaxException { URL url = new URI( - uri.getScheme(), + uri.getScheme(), uri.getAuthority(), - pi==null?uri.getPath():pi.toString(), + pi==null?uri.getPath():pi.toString(), query, fragment).toURL(); return (HttpURLConnection) url.openConnection(); } - + public abstract class HFuture extends Future { protected HttpURLConnection huc; protected int respCode; protected IOException exception; protected StringBuilder errContent; - + public HFuture(final HttpURLConnection huc) { this.huc = huc; } - + protected boolean evalInfo(HttpURLConnection huc) throws APIException, IOException{ return respCode == 200; }; - + @Override public final boolean get(int timeout) throws CadiException { try { @@ -219,7 +220,7 @@ public class HClient implements EClient { close(); } } - + private void extractError() { InputStream is = huc.getErrorStream(); try { @@ -237,7 +238,7 @@ public class HClient implements EClient { exception = e; } } - + // Typically only used by Read public StringBuilder inputStreamToString(InputStream is) { // Avoids Carriage returns, and is reasonably efficient, given @@ -260,26 +261,26 @@ public class HClient implements EClient { return null; } } - - + + @Override public int code() { return respCode; } - + public HttpURLConnection huc() { return huc; } - + public IOException exception() { return exception; } - + @Override public String header(String tag) { return huc.getHeaderField(tag); } - + public void close() { if (huc!=null) { huc.disconnect(); @@ -393,9 +394,9 @@ public class HClient implements EClient { is = huc.getInputStream(); // reuse Buffers Pooled pbuff = Rcli.buffPool.get(); - try { + try { while ((read=is.read(pbuff.content))>=0) { - os.write(pbuff.content,0,read); + os.write(pbuff.content,0,read); } } finally { pbuff.done(); @@ -411,7 +412,7 @@ public class HClient implements EClient { Pooled pbuff = Rcli.buffPool.get(); try { while ((read=is.read(pbuff.content))>=0) { - os.write(pbuff.content,0,read); + os.write(pbuff.content,0,read); } } finally { pbuff.done(); @@ -436,12 +437,12 @@ public class HClient implements EClient { this.tag = t; this.value = v; } - + public String toString() { return tag + '=' + value; } } - + public String toString() { return "HttpURLConnection Client configured to " + uri.toString(); }