2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * Modifications Copyright (C) 2019 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.dmaap.dbcapi.client;
25 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
26 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
27 import org.onap.dmaap.dbcapi.model.ApiError;
28 import org.onap.dmaap.dbcapi.model.DR_Sub;
29 import org.onap.dmaap.dbcapi.model.Feed;
30 import org.onap.dmaap.dbcapi.service.DmaapService;
31 import org.onap.dmaap.dbcapi.util.DmaapConfig;
33 import javax.net.ssl.HttpsURLConnection;
35 import java.net.ConnectException;
36 import java.net.ProtocolException;
37 import java.net.SocketException;
39 import java.util.Arrays;
43 public class DrProvConnection extends BaseLoggingClass {
46 private String provURL;
47 private String provApi;
48 private String behalfHeader;
49 private String feedContentType;
50 private String subContentType;
51 private String unit_test;
53 private HttpsURLConnection uc;
56 public DrProvConnection() {
57 provURL = new DmaapService().getDmaap().getDrProvUrl();
58 if ( provURL.length() < 1 ) {
59 errorLogger.error( DmaapbcLogMessageEnum.PREREQ_DMAAP_OBJECT, "getDrProvUrl");
61 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
62 provApi = p.getProperty( "DR.provApi", "ONAP" );
63 behalfHeader = p.getProperty( "DR.onBehalfHeader", "X-DMAAP-DR-ON-BEHALF-OF");
64 feedContentType = p.getProperty( "DR.feedContentType", "application/vnd.dmaap-dr.feed");
65 subContentType = p.getProperty( "DR.subContentType", "application/vnd.dmaap-dr.subscription");
66 logger.info( "provURL=" + provURL + " provApi=" + provApi + " behalfHeader=" + behalfHeader
67 + " feedContentType=" + feedContentType + " subContentType=" + subContentType );
68 unit_test = p.getProperty( "UnitTest", "No" );
72 public boolean makeFeedConnection() {
73 return makeConnection( provURL );
75 public boolean makeFeedConnection(String feedId) {
76 return makeConnection( provURL + "/feed/" + feedId );
78 public boolean makeSubPostConnection( String subURL ) {
79 String[] parts = subURL.split("/");
80 String revisedURL = provURL + "/" + parts[3] + "/" + parts[4];
81 logger.info( "mapping " + subURL + " to " + revisedURL );
82 return makeConnection( revisedURL );
84 public boolean makeSubPutConnection( String subId ) {
85 String revisedURL = provURL + "/subs/" + subId;
86 logger.info( "mapping " + subId + " to " + revisedURL );
87 return makeConnection( revisedURL );
90 public boolean makeIngressConnection( String feed, String user, String subnet, String nodep ) {
91 String uri = String.format("/internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s",
92 feed, user, subnet, nodep );
93 return makeConnection( provURL + uri );
95 public boolean makeEgressConnection( String sub, String nodep ) {
96 String uri = String.format("/internal/route/egress/?sub=%s&node=%s",
98 return makeConnection( provURL + uri );
100 public boolean makeNodesConnection( String varName ) {
102 String uri = String.format("/internal/api/%s", varName);
103 return makeConnection( provURL + uri );
106 public boolean makeNodesConnection( String varName, String val ) {
111 String cv = val.replaceAll("\\|", "%7C");
112 String uri = String.format( "/internal/api/%s?val=%s", varName, cv );
114 return makeConnection( provURL + uri );
117 private boolean makeConnection( String pURL ) {
120 URL u = new URL( pURL );
121 uc = (HttpsURLConnection) u.openConnection();
122 uc.setInstanceFollowRedirects(false);
123 logger.info( "successful connect to " + pURL );
125 } catch (Exception e) {
126 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR, pURL, e.getMessage() );
133 public String bodyToString( InputStream is ) {
134 logger.info( "is=" + is );
135 StringBuilder sb = new StringBuilder();
136 BufferedReader br = new BufferedReader( new InputStreamReader(is));
139 while ((line = br.readLine()) != null ) {
142 } catch (IOException ex ) {
143 errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION, ex.getMessage());
146 return sb.toString();
150 public String doPostFeed( Feed postFeed, ApiError err ) {
152 byte[] postData = postFeed.getBytes();
153 logger.info( "post fields=" + Arrays.toString(postData) );
154 String responsemessage = null;
155 String responseBody = null;
158 logger.info( "uc=" + uc );
159 uc.setRequestMethod("POST");
160 uc.setRequestProperty("Content-Type", feedContentType);
161 uc.setRequestProperty( "charset", "utf-8");
162 uc.setRequestProperty( behalfHeader, postFeed.getOwner() );
163 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
164 uc.setUseCaches(false);
165 uc.setDoOutput(true);
166 OutputStream os = null;
171 os = uc.getOutputStream();
172 os.write( postData );
174 } catch (ProtocolException pe) {
175 // Rcvd error instead of 100-Continue
177 // work around glitch in Java 1.7.0.21 and likely others
178 // without this, Java will connect multiple times to the server to run the same request
179 uc.setDoOutput(false);
180 } catch (Exception e) {
183 rc = uc.getResponseCode();
184 logger.info( "http response code:" + rc );
185 responsemessage = uc.getResponseMessage();
186 logger.info( "responsemessage=" + responsemessage );
189 if (responsemessage == null) {
190 // work around for glitch in Java 1.7.0.21 and likely others
191 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
192 String h0 = uc.getHeaderField(0);
194 int i = h0.indexOf(' ');
195 int j = h0.indexOf(' ', i + 1);
196 if (i != -1 && j != -1) {
197 responsemessage = h0.substring(j + 1);
202 responseBody = bodyToString( uc.getInputStream() );
203 logger.info( "responseBody=" + responseBody );
207 err.setMessage(responsemessage);
210 } catch (ConnectException ce) {
211 errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
213 err.setMessage("Backend connection refused");
214 } catch (SocketException se) {
215 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from prov server" );
217 err.setMessage( "Unable to read response from DR");
218 } catch (Exception e) {
219 if ( unit_test.equals( "Yes" ) ) {
221 err.setMessage( "simulated response");
222 logger.info( "artificial 200 response from doPostFeed because unit_test =" + unit_test );
224 logger.warn("Unable to read response " );
227 err.setCode( uc.getResponseCode());
228 err.setMessage(uc.getResponseMessage());
229 } catch (Exception e2) {
231 err.setMessage("Unable to determine response message");
238 } catch ( Exception e ) {}
245 // the POST for /internal/route/ingress doesn't return any data, so needs a different function
246 // the POST for /internal/route/egress doesn't return any data, so needs a different function
247 public int doXgressPost( ApiError err ) {
249 String responsemessage = null;
253 uc.setRequestMethod("POST");
259 } catch (ProtocolException pe) {
260 // Rcvd error instead of 100-Continue
262 // work around glitch in Java 1.7.0.21 and likely others
263 // without this, Java will connect multiple times to the server to run the same request
264 uc.setDoOutput(false);
265 } catch (Exception e) {
266 logger.error(e.getMessage(), e);
269 rc = uc.getResponseCode();
270 logger.info( "http response code:" + rc );
271 responsemessage = uc.getResponseMessage();
272 logger.info( "responsemessage=" + responsemessage );
276 if (rc < 200 || rc >= 300 ) {
278 err.setMessage(responsemessage);
280 } catch (Exception e) {
281 if ( unit_test.equals( "Yes" ) ) {
283 err.setMessage( "simulated response");
284 logger.info( "artificial 200 response from doXgressPost because unit_test =" + unit_test );
286 logger.error("Unable to read response " );
293 } catch ( Exception e ) {
294 logger.error(e.getMessage(), e);
302 public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
303 logger.info( "entry: doPostDr_Sub() " );
304 byte[] postData = postSub.getBytes(provApi );
305 logger.info( "post fields=" + postData );
306 String responsemessage = null;
307 String responseBody = null;
311 uc.setRequestMethod("POST");
313 uc.setRequestProperty("Content-Type", subContentType );
314 uc.setRequestProperty( "charset", "utf-8");
315 uc.setRequestProperty( behalfHeader, "DGL" );
316 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
317 uc.setUseCaches(false);
318 uc.setDoOutput(true);
319 OutputStream os = null;
324 os = uc.getOutputStream();
325 os.write( postData );
327 } catch (ProtocolException pe) {
328 // Rcvd error instead of 100-Continue
330 // work around glitch in Java 1.7.0.21 and likely others
331 // without this, Java will connect multiple times to the server to run the same request
332 uc.setDoOutput(false);
333 } catch (Exception e) {
336 rc = uc.getResponseCode();
337 logger.info( "http response code:" + rc );
338 responsemessage = uc.getResponseMessage();
339 logger.info( "responsemessage=" + responsemessage );
342 if (responsemessage == null) {
343 // work around for glitch in Java 1.7.0.21 and likely others
344 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
345 String h0 = uc.getHeaderField(0);
347 int i = h0.indexOf(' ');
348 int j = h0.indexOf(' ', i + 1);
349 if (i != -1 && j != -1) {
350 responsemessage = h0.substring(j + 1);
355 responseBody = bodyToString( uc.getInputStream() );
356 logger.info( "responseBody=" + responseBody );
360 err.setMessage(responsemessage);
363 } catch (Exception e) {
364 if ( unit_test.equals( "Yes" ) ) {
366 err.setMessage( "simulated response");
367 logger.info( "artificial 200 response from doPostDr_Sub because unit_test =" + unit_test );
369 System.err.println("Unable to read response " );
376 } catch ( Exception e ) {}
383 public String doPutFeed(Feed putFeed, ApiError err) {
384 byte[] postData = putFeed.getBytes();
385 logger.info( "post fields=" + Arrays.toString(postData) );
386 String responsemessage = null;
387 String responseBody = null;
390 logger.info( "uc=" + uc );
391 uc.setRequestMethod("PUT");
392 uc.setRequestProperty("Content-Type", feedContentType );
393 uc.setRequestProperty( "charset", "utf-8");
394 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
395 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
396 uc.setUseCaches(false);
397 uc.setDoOutput(true);
398 OutputStream os = null;
403 os = uc.getOutputStream();
404 os.write( postData );
406 } catch (ProtocolException pe) {
407 // Rcvd error instead of 100-Continue
409 // work around glitch in Java 1.7.0.21 and likely others
410 // without this, Java will connect multiple times to the server to run the same request
411 uc.setDoOutput(false);
412 } catch (Exception e) {
415 rc = uc.getResponseCode();
416 logger.info( "http response code:" + rc );
417 responsemessage = uc.getResponseMessage();
418 logger.info( "responsemessage=" + responsemessage );
421 if (responsemessage == null) {
422 // work around for glitch in Java 1.7.0.21 and likely others
423 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
424 String h0 = uc.getHeaderField(0);
426 int i = h0.indexOf(' ');
427 int j = h0.indexOf(' ', i + 1);
428 if (i != -1 && j != -1) {
429 responsemessage = h0.substring(j + 1);
433 if (rc >= 200 && rc < 300 ) {
434 responseBody = bodyToString( uc.getInputStream() );
435 logger.info( "responseBody=" + responseBody );
437 } else if ( rc == 404 ) {
439 err.setFields( "feedid");
440 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
441 err.setMessage( message );
442 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
446 err.setMessage(responsemessage);
449 } catch (ConnectException ce) {
450 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
452 err.setMessage("Backend connection refused");
453 } catch (SocketException se) {
454 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
456 err.setMessage( "Unable to read response from DR");
457 } catch (Exception e) {
458 if ( unit_test.equals( "Yes" ) ) {
460 err.setMessage( "simulated response");
461 logger.info( "artificial 200 response from doPutFeed because unit_test =" + unit_test );
463 logger.warn("Unable to read response " );
467 err.setCode( uc.getResponseCode());
468 err.setMessage(uc.getResponseMessage());
469 } catch (Exception e2) {
471 err.setMessage("Unable to determine response message");
476 } catch ( Exception e ) {}
480 public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
481 logger.info( "entry: doPutDr_Sub() " );
482 byte[] postData = postSub.getBytes(provApi);
483 logger.info( "post fields=" + postData );
484 String responsemessage = null;
485 String responseBody = null;
489 uc.setRequestMethod("PUT");
491 uc.setRequestProperty("Content-Type", subContentType );
492 uc.setRequestProperty( "charset", "utf-8");
493 uc.setRequestProperty( behalfHeader, "DGL" );
494 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
495 uc.setUseCaches(false);
496 uc.setDoOutput(true);
497 OutputStream os = null;
502 os = uc.getOutputStream();
503 os.write( postData );
505 } catch (ProtocolException pe) {
506 // Rcvd error instead of 100-Continue
508 // work around glitch in Java 1.7.0.21 and likely others
509 // without this, Java will connect multiple times to the server to run the same request
510 uc.setDoOutput(false);
511 } catch (Exception e) {
514 rc = uc.getResponseCode();
515 logger.info( "http response code:" + rc );
516 responsemessage = uc.getResponseMessage();
517 logger.info( "responsemessage=" + responsemessage );
520 if (responsemessage == null) {
521 // work around for glitch in Java 1.7.0.21 and likely others
522 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
523 String h0 = uc.getHeaderField(0);
525 int i = h0.indexOf(' ');
526 int j = h0.indexOf(' ', i + 1);
527 if (i != -1 && j != -1) {
528 responsemessage = h0.substring(j + 1);
533 responseBody = bodyToString( uc.getInputStream() );
534 logger.info( "responseBody=" + responseBody );
538 err.setMessage(responsemessage);
541 } catch (ConnectException ce) {
542 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
544 err.setMessage("Backend connection refused");
545 } catch (Exception e) {
546 if ( unit_test.equals( "Yes" ) ) {
548 err.setMessage( "simulated response");
549 logger.info( "artificial 200 response from doPutDr_Sub because unit_test =" + unit_test );
551 logger.error("Unable to read response " );
552 logger.error(e.getMessage(), e);
561 public String doGetNodes( ApiError err ) {
562 logger.info( "entry: doGetNodes() " );
563 //byte[] postData = postSub.getBytes();
564 //logger.info( "get fields=" + postData );
565 String responsemessage = null;
566 String responseBody = null;
570 uc.setRequestMethod("GET");
578 } catch (ProtocolException pe) {
580 // Rcvd error instead of 100-Continue
582 // work around glitch in Java 1.7.0.21 and likely others
583 // without this, Java will connect multiple times to the server to run the same request
584 uc.setDoOutput(false);
585 } catch (Exception e) {
589 rc = uc.getResponseCode();
590 logger.info( "http response code:" + rc );
591 responsemessage = uc.getResponseMessage();
592 logger.info( "responsemessage=" + responsemessage );
596 if (responsemessage == null) {
598 // work around for glitch in Java 1.7.0.21 and likely others
599 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
600 String h0 = uc.getHeaderField(0);
602 int i = h0.indexOf(' ');
603 int j = h0.indexOf(' ', i + 1);
604 if (i != -1 && j != -1) {
605 responsemessage = h0.substring(j + 1);
610 err.setCode(rc); // may not really be an error, but we save rc
612 responseBody = bodyToString( uc.getInputStream() );
613 logger.info( "responseBody=" + responseBody );
615 err.setMessage(responsemessage);
619 } catch (ConnectException ce) {
621 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
623 err.setMessage("Backend connection refused");
624 } catch (Exception e) {
625 if ( unit_test.equals( "Yes" ) ) {
627 err.setMessage( "simulated response");
628 logger.info( "artificial 200 response from doGetNodes because unit_test =" + unit_test );
630 System.err.println("Unable to read response " );
635 if ( uc != null ) uc.disconnect();
641 public String doPutNodes( ApiError err ) {
642 logger.info( "entry: doPutNodes() " );
643 //byte[] postData = nodeList.getBytes();
644 //logger.info( "get fields=" + postData );
645 String responsemessage = null;
646 String responseBody = null;
650 uc.setRequestMethod("PUT");
652 //uc.setRequestProperty("Content-Type", subContentType );
653 //uc.setRequestProperty( "charset", "utf-8");
654 //uc.setRequestProperty( behalfHeader, "DGL" );
655 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
656 uc.setUseCaches(false);
657 //uc.setDoOutput(true);
658 OutputStream os = null;
663 //os = uc.getOutputStream();
664 //os.write( postData );
666 } catch (ProtocolException pe) {
667 // Rcvd error instead of 100-Continue
669 // work around glitch in Java 1.7.0.21 and likely others
670 // without this, Java will connect multiple times to the server to run the same request
671 uc.setDoOutput(false);
672 } catch (Exception e) {
675 rc = uc.getResponseCode();
676 logger.info( "http response code:" + rc );
677 responsemessage = uc.getResponseMessage();
678 logger.info( "responsemessage=" + responsemessage );
681 if (responsemessage == null) {
682 // work around for glitch in Java 1.7.0.21 and likely others
683 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
684 String h0 = uc.getHeaderField(0);
686 int i = h0.indexOf(' ');
687 int j = h0.indexOf(' ', i + 1);
688 if (i != -1 && j != -1) {
689 responsemessage = h0.substring(j + 1);
695 responseBody = bodyToString( uc.getInputStream() );
696 logger.info( "responseBody=" + responseBody );
700 err.setMessage(responsemessage);
703 } catch (Exception e) {
704 if ( unit_test.equals( "Yes" ) ) {
706 err.setMessage( "simulated response");
707 logger.info( "artificial 200 response from doPutNodes because unit_test =" + unit_test );
709 System.err.println("Unable to read response " + e.getMessage() );
721 public String doDeleteFeed(Feed putFeed, ApiError err) {
722 //byte[] postData = putFeed.getBytes();
723 //logger.info( "post fields=" + postData.toString() );
724 String responsemessage = null;
725 String responseBody = null;
728 logger.info( "uc=" + uc );
729 uc.setRequestMethod("DELETE");
730 uc.setRequestProperty("Content-Type", feedContentType );
731 uc.setRequestProperty( "charset", "utf-8");
732 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
733 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
734 uc.setUseCaches(false);
735 uc.setDoOutput(true);
736 OutputStream os = null;
741 os = uc.getOutputStream();
742 //os.write( postData );
744 } catch (ProtocolException pe) {
745 // Rcvd error instead of 100-Continue
747 // work around glitch in Java 1.7.0.21 and likely others
748 // without this, Java will connect multiple times to the server to run the same request
749 uc.setDoOutput(false);
750 } catch (Exception e) {
753 rc = uc.getResponseCode();
754 logger.info( "http response code:" + rc );
755 responsemessage = uc.getResponseMessage();
756 logger.info( "responsemessage=" + responsemessage );
759 if (responsemessage == null) {
760 // work around for glitch in Java 1.7.0.21 and likely others
761 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
762 String h0 = uc.getHeaderField(0);
764 int i = h0.indexOf(' ');
765 int j = h0.indexOf(' ', i + 1);
766 if (i != -1 && j != -1) {
767 responsemessage = h0.substring(j + 1);
771 if (rc >= 200 && rc < 300 ) {
772 responseBody = bodyToString( uc.getInputStream() );
773 logger.info( "responseBody=" + responseBody );
775 } else if ( rc == 404 ) {
777 err.setFields( "feedid");
778 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
779 err.setMessage( message );
780 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
784 err.setMessage(responsemessage);
787 } catch (ConnectException ce) {
788 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
790 err.setMessage("Backend connection refused");
791 } catch (SocketException se) {
792 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
794 err.setMessage( "Unable to read response from DR");
795 } catch (Exception e) {
796 if ( unit_test.equals( "Yes" ) ) {
798 err.setMessage( "simulated response");
799 logger.info( "artificial 200 response from doDeleteFeed because unit_test =" + unit_test );
801 logger.warn("Unable to read response " );
804 err.setCode( uc.getResponseCode());
805 err.setMessage(uc.getResponseMessage());
806 } catch (Exception e2) {
808 err.setMessage("Unable to determine response message");
814 } catch ( Exception e ) {}
819 public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
820 logger.info( "entry: doDeleteDr_Sub() " );
821 byte[] postData = delSub.getBytes(provApi);
822 logger.info( "post fields=" + postData );
823 String responsemessage = null;
824 String responseBody = null;
828 uc.setRequestMethod("DELETE");
830 uc.setRequestProperty("Content-Type", subContentType);
831 uc.setRequestProperty( "charset", "utf-8");
832 uc.setRequestProperty( behalfHeader, "DGL" );
833 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
834 uc.setUseCaches(false);
835 uc.setDoOutput(true);
836 OutputStream os = null;
841 os = uc.getOutputStream();
842 //os.write( postData );
844 } catch (ProtocolException pe) {
845 // Rcvd error instead of 100-Continue
847 // work around glitch in Java 1.7.0.21 and likely others
848 // without this, Java will connect multiple times to the server to run the same request
849 uc.setDoOutput(false);
850 } catch (Exception e) {
853 rc = uc.getResponseCode();
854 logger.info( "http response code:" + rc );
855 responsemessage = uc.getResponseMessage();
856 logger.info( "responsemessage=" + responsemessage );
859 if (responsemessage == null) {
860 // work around for glitch in Java 1.7.0.21 and likely others
861 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
862 String h0 = uc.getHeaderField(0);
864 int i = h0.indexOf(' ');
865 int j = h0.indexOf(' ', i + 1);
866 if (i != -1 && j != -1) {
867 responsemessage = h0.substring(j + 1);
873 responseBody = bodyToString( uc.getInputStream() );
874 logger.info( "responseBody=" + responseBody );
876 err.setMessage(responsemessage);
879 } catch (ConnectException ce) {
880 if ( unit_test.equals( "Yes" ) ) {
882 err.setMessage( "simulated response");
883 logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
885 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
887 err.setMessage("Backend connection refused");
889 } catch (Exception e) {
890 if ( unit_test.equals( "Yes" ) ) {
892 err.setMessage( "simulated response");
893 logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
895 System.err.println("Unable to read response " );