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() );
132 public String bodyToString( InputStream is ) {
133 logger.info( "is=" + is );
134 StringBuilder sb = new StringBuilder();
135 BufferedReader br = new BufferedReader( new InputStreamReader(is));
138 while ((line = br.readLine()) != null ) {
141 } catch (IOException ex ) {
142 errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION, ex.getMessage());
145 return sb.toString();
149 public String doPostFeed( Feed postFeed, ApiError err ) {
151 byte[] postData = postFeed.getBytes();
152 logger.info( "post fields=" + Arrays.toString(postData) );
153 String responsemessage = null;
154 String responseBody = null;
157 logger.info( "uc=" + uc );
158 uc.setRequestMethod("POST");
159 uc.setRequestProperty("Content-Type", feedContentType);
160 uc.setRequestProperty( "charset", "utf-8");
161 uc.setRequestProperty( behalfHeader, postFeed.getOwner() );
162 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
163 uc.setUseCaches(false);
164 uc.setDoOutput(true);
165 OutputStream os = null;
170 os = uc.getOutputStream();
171 os.write( postData );
173 } catch (ProtocolException pe) {
174 // Rcvd error instead of 100-Continue
176 // work around glitch in Java 1.7.0.21 and likely others
177 // without this, Java will connect multiple times to the server to run the same request
178 uc.setDoOutput(false);
179 } catch (Exception e) {
182 rc = uc.getResponseCode();
183 logger.info( "http response code:" + rc );
184 responsemessage = uc.getResponseMessage();
185 logger.info( "responsemessage=" + responsemessage );
188 if (responsemessage == null) {
189 // work around for glitch in Java 1.7.0.21 and likely others
190 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
191 String h0 = uc.getHeaderField(0);
193 int i = h0.indexOf(' ');
194 int j = h0.indexOf(' ', i + 1);
195 if (i != -1 && j != -1) {
196 responsemessage = h0.substring(j + 1);
201 responseBody = bodyToString( uc.getInputStream() );
202 logger.info( "responseBody=" + responseBody );
206 err.setMessage(responsemessage);
209 } catch (ConnectException ce) {
210 errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
212 err.setMessage("Backend connection refused");
213 } catch (SocketException se) {
214 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from prov server" );
216 err.setMessage( "Unable to read response from DR");
217 } catch (Exception e) {
218 if ( unit_test.equals( "Yes" ) ) {
220 err.setMessage( "simulated response");
221 logger.info( "artificial 200 response from doPostFeed because unit_test =" + unit_test );
223 logger.warn("Unable to read response " );
224 errorLogger.error("Unable to read response ", e.getMessage());
226 err.setCode( uc.getResponseCode());
227 err.setMessage(uc.getResponseMessage());
228 } catch (Exception e2) {
230 err.setMessage("Unable to determine response message");
237 } catch ( Exception e ) {
238 logger.error(e.getMessage(), e);
246 // the POST for /internal/route/ingress doesn't return any data, so needs a different function
247 // the POST for /internal/route/egress doesn't return any data, so needs a different function
248 public int doXgressPost( ApiError err ) {
250 String responsemessage = null;
254 uc.setRequestMethod("POST");
260 } catch (ProtocolException pe) {
261 // Rcvd error instead of 100-Continue
263 // work around glitch in Java 1.7.0.21 and likely others
264 // without this, Java will connect multiple times to the server to run the same request
265 uc.setDoOutput(false);
266 } catch (Exception e) {
267 logger.error(e.getMessage(), e);
270 rc = uc.getResponseCode();
271 logger.info( "http response code:" + rc );
272 responsemessage = uc.getResponseMessage();
273 logger.info( "responsemessage=" + responsemessage );
277 if (rc < 200 || rc >= 300 ) {
279 err.setMessage(responsemessage);
281 } catch (Exception e) {
282 if ( unit_test.equals( "Yes" ) ) {
284 err.setMessage( "simulated response");
285 logger.info( "artificial 200 response from doXgressPost because unit_test =" + unit_test );
287 logger.error("Unable to read response " );
288 logger.error(e.getMessage(), e);
294 } catch ( Exception e ) {
295 logger.error(e.getMessage(), e);
303 public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
304 logger.info( "entry: doPostDr_Sub() " );
305 byte[] postData = postSub.getBytes(provApi );
306 logger.info( "post fields=" + postData );
307 String responsemessage = null;
308 String responseBody = null;
312 uc.setRequestMethod("POST");
314 uc.setRequestProperty("Content-Type", subContentType );
315 uc.setRequestProperty( "charset", "utf-8");
316 uc.setRequestProperty( behalfHeader, "DGL" );
317 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
318 uc.setUseCaches(false);
319 uc.setDoOutput(true);
320 OutputStream os = null;
325 os = uc.getOutputStream();
326 os.write( postData );
328 } catch (ProtocolException pe) {
329 // Rcvd error instead of 100-Continue
331 // work around glitch in Java 1.7.0.21 and likely others
332 // without this, Java will connect multiple times to the server to run the same request
333 uc.setDoOutput(false);
334 } catch (Exception e) {
335 logger.error(e.getMessage(), e);
338 rc = uc.getResponseCode();
339 logger.info( "http response code:" + rc );
340 responsemessage = uc.getResponseMessage();
341 logger.info( "responsemessage=" + responsemessage );
344 if (responsemessage == null) {
345 // work around for glitch in Java 1.7.0.21 and likely others
346 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
347 String h0 = uc.getHeaderField(0);
349 int i = h0.indexOf(' ');
350 int j = h0.indexOf(' ', i + 1);
351 if (i != -1 && j != -1) {
352 responsemessage = h0.substring(j + 1);
357 responseBody = bodyToString( uc.getInputStream() );
358 logger.info( "responseBody=" + responseBody );
362 err.setMessage(responsemessage);
365 } catch (Exception e) {
366 if ( unit_test.equals( "Yes" ) ) {
368 err.setMessage( "simulated response");
369 logger.info( "artificial 200 response from doPostDr_Sub because unit_test =" + unit_test );
371 logger.error("Unable to read response ", e.getMessage());
377 } catch ( Exception e ) {
378 logger.error(e.getMessage(), e);
386 public String doPutFeed(Feed putFeed, ApiError err) {
387 byte[] postData = putFeed.getBytes();
388 logger.info( "post fields=" + Arrays.toString(postData) );
389 String responsemessage = null;
390 String responseBody = null;
393 logger.info( "uc=" + uc );
394 uc.setRequestMethod("PUT");
395 uc.setRequestProperty("Content-Type", feedContentType );
396 uc.setRequestProperty( "charset", "utf-8");
397 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
398 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
399 uc.setUseCaches(false);
400 uc.setDoOutput(true);
401 OutputStream os = null;
406 os = uc.getOutputStream();
407 os.write( postData );
409 } catch (ProtocolException pe) {
410 // Rcvd error instead of 100-Continue
412 // work around glitch in Java 1.7.0.21 and likely others
413 // without this, Java will connect multiple times to the server to run the same request
414 uc.setDoOutput(false);
415 } catch (Exception e) {
416 logger.error(e.getMessage(), e);
419 rc = uc.getResponseCode();
420 logger.info( "http response code:" + rc );
421 responsemessage = uc.getResponseMessage();
422 logger.info( "responsemessage=" + responsemessage );
425 if (responsemessage == null) {
426 // work around for glitch in Java 1.7.0.21 and likely others
427 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
428 String h0 = uc.getHeaderField(0);
430 int i = h0.indexOf(' ');
431 int j = h0.indexOf(' ', i + 1);
432 if (i != -1 && j != -1) {
433 responsemessage = h0.substring(j + 1);
437 if (rc >= 200 && rc < 300 ) {
438 responseBody = bodyToString( uc.getInputStream() );
439 logger.info( "responseBody=" + responseBody );
441 } else if ( rc == 404 ) {
443 err.setFields( "feedid");
444 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
445 err.setMessage( message );
446 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
450 err.setMessage(responsemessage);
453 } catch (ConnectException ce) {
454 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
456 err.setMessage("Backend connection refused");
457 } catch (SocketException se) {
458 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
460 err.setMessage( "Unable to read response from DR");
461 } catch (Exception e) {
462 if ( unit_test.equals( "Yes" ) ) {
464 err.setMessage( "simulated response");
465 logger.info( "artificial 200 response from doPutFeed because unit_test =" + unit_test );
467 logger.warn("Unable to read response " );
468 logger.error(e.getMessage(), e);
471 err.setCode( uc.getResponseCode());
472 err.setMessage(uc.getResponseMessage());
473 } catch (Exception e2) {
475 err.setMessage("Unable to determine response message");
476 logger.error(e2.getMessage(), e2);
481 } catch ( Exception e ) {
482 logger.error(e.getMessage(), e);
487 public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
488 logger.info( "entry: doPutDr_Sub() " );
489 byte[] postData = postSub.getBytes(provApi);
490 logger.info( "post fields=" + postData );
491 String responsemessage = null;
492 String responseBody = null;
496 uc.setRequestMethod("PUT");
498 uc.setRequestProperty("Content-Type", subContentType );
499 uc.setRequestProperty( "charset", "utf-8");
500 uc.setRequestProperty( behalfHeader, "DGL" );
501 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
502 uc.setUseCaches(false);
503 uc.setDoOutput(true);
504 OutputStream os = null;
509 os = uc.getOutputStream();
510 os.write( postData );
512 } catch (ProtocolException pe) {
513 // Rcvd error instead of 100-Continue
515 // work around glitch in Java 1.7.0.21 and likely others
516 // without this, Java will connect multiple times to the server to run the same request
517 uc.setDoOutput(false);
518 } catch (Exception e) {
519 logger.error(e.getMessage(), e);
522 rc = uc.getResponseCode();
523 logger.info( "http response code:" + rc );
524 responsemessage = uc.getResponseMessage();
525 logger.info( "responsemessage=" + responsemessage );
528 if (responsemessage == null) {
529 // work around for glitch in Java 1.7.0.21 and likely others
530 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
531 String h0 = uc.getHeaderField(0);
533 int i = h0.indexOf(' ');
534 int j = h0.indexOf(' ', i + 1);
535 if (i != -1 && j != -1) {
536 responsemessage = h0.substring(j + 1);
541 responseBody = bodyToString( uc.getInputStream() );
542 logger.info( "responseBody=" + responseBody );
546 err.setMessage(responsemessage);
549 } catch (ConnectException ce) {
550 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
552 err.setMessage("Backend connection refused");
553 logger.error(ce.getMessage(), ce);
554 } catch (Exception e) {
555 if ( unit_test.equals( "Yes" ) ) {
557 err.setMessage( "simulated response");
558 logger.info( "artificial 200 response from doPutDr_Sub because unit_test =" + unit_test );
560 logger.error("Unable to read response " );
561 logger.error(e.getMessage(), e);
572 public String doGetNodes( ApiError err ) {
573 logger.info( "entry: doGetNodes() " );
574 //byte[] postData = postSub.getBytes();
575 //logger.info( "get fields=" + postData );
576 String responsemessage = null;
577 String responseBody = null;
581 uc.setRequestMethod("GET");
589 } catch (ProtocolException pe) {
591 // Rcvd error instead of 100-Continue
593 // work around glitch in Java 1.7.0.21 and likely others
594 // without this, Java will connect multiple times to the server to run the same request
595 uc.setDoOutput(false);
596 } catch (Exception e) {
597 logger.error(e.getMessage(), e);
601 rc = uc.getResponseCode();
602 logger.info( "http response code:" + rc );
603 responsemessage = uc.getResponseMessage();
604 logger.info( "responsemessage=" + responsemessage );
608 if (responsemessage == null) {
610 // work around for glitch in Java 1.7.0.21 and likely others
611 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
612 String h0 = uc.getHeaderField(0);
614 int i = h0.indexOf(' ');
615 int j = h0.indexOf(' ', i + 1);
616 if (i != -1 && j != -1) {
617 responsemessage = h0.substring(j + 1);
622 err.setCode(rc); // may not really be an error, but we save rc
624 responseBody = bodyToString( uc.getInputStream() );
625 logger.info( "responseBody=" + responseBody );
627 err.setMessage(responsemessage);
631 } catch (ConnectException ce) {
633 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
635 err.setMessage("Backend connection refused");
636 logger.error(ce.getMessage(), ce);
637 } catch (Exception e) {
638 if ( unit_test.equals( "Yes" ) ) {
640 err.setMessage( "simulated response");
641 logger.info( "artificial 200 response from doGetNodes because unit_test =" + unit_test );
643 logger.error("Unable to read response ", e.getMessage());
647 if ( uc != null ) uc.disconnect();
653 public String doPutNodes( ApiError err ) {
654 logger.info( "entry: doPutNodes() " );
655 //byte[] postData = nodeList.getBytes();
656 //logger.info( "get fields=" + postData );
657 String responsemessage = null;
658 String responseBody = null;
662 uc.setRequestMethod("PUT");
664 //uc.setRequestProperty("Content-Type", subContentType );
665 //uc.setRequestProperty( "charset", "utf-8");
666 //uc.setRequestProperty( behalfHeader, "DGL" );
667 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
668 uc.setUseCaches(false);
669 //uc.setDoOutput(true);
670 OutputStream os = null;
675 //os = uc.getOutputStream();
676 //os.write( postData );
678 } catch (ProtocolException pe) {
679 // Rcvd error instead of 100-Continue
681 // work around glitch in Java 1.7.0.21 and likely others
682 // without this, Java will connect multiple times to the server to run the same request
683 uc.setDoOutput(false);
684 } catch (Exception e) {
687 rc = uc.getResponseCode();
688 logger.info( "http response code:" + rc );
689 responsemessage = uc.getResponseMessage();
690 logger.info( "responsemessage=" + responsemessage );
693 if (responsemessage == null) {
694 // work around for glitch in Java 1.7.0.21 and likely others
695 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
696 String h0 = uc.getHeaderField(0);
698 int i = h0.indexOf(' ');
699 int j = h0.indexOf(' ', i + 1);
700 if (i != -1 && j != -1) {
701 responsemessage = h0.substring(j + 1);
707 responseBody = bodyToString( uc.getInputStream() );
708 logger.info( "responseBody=" + responseBody );
712 err.setMessage(responsemessage);
715 } catch (Exception e) {
716 if ( unit_test.equals( "Yes" ) ) {
718 err.setMessage( "simulated response");
719 logger.info( "artificial 200 response from doPutNodes because unit_test =" + unit_test );
721 logger.error("Unable to read response ", e.getMessage());
732 public String doDeleteFeed(Feed putFeed, ApiError err) {
733 //byte[] postData = putFeed.getBytes();
734 //logger.info( "post fields=" + postData.toString() );
735 String responsemessage = null;
736 String responseBody = null;
739 logger.info( "uc=" + uc );
740 uc.setRequestMethod("DELETE");
741 uc.setRequestProperty("Content-Type", feedContentType );
742 uc.setRequestProperty( "charset", "utf-8");
743 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
744 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
745 uc.setUseCaches(false);
746 uc.setDoOutput(true);
747 OutputStream os = null;
752 os = uc.getOutputStream();
753 //os.write( postData );
755 } catch (ProtocolException pe) {
756 // Rcvd error instead of 100-Continue
758 // work around glitch in Java 1.7.0.21 and likely others
759 // without this, Java will connect multiple times to the server to run the same request
760 uc.setDoOutput(false);
761 } catch (Exception e) {
762 logger.error(e.getMessage(), e);
765 rc = uc.getResponseCode();
766 logger.info( "http response code:" + rc );
767 responsemessage = uc.getResponseMessage();
768 logger.info( "responsemessage=" + responsemessage );
771 if (responsemessage == null) {
772 // work around for glitch in Java 1.7.0.21 and likely others
773 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
774 String h0 = uc.getHeaderField(0);
776 int i = h0.indexOf(' ');
777 int j = h0.indexOf(' ', i + 1);
778 if (i != -1 && j != -1) {
779 responsemessage = h0.substring(j + 1);
783 if (rc >= 200 && rc < 300 ) {
784 responseBody = bodyToString( uc.getInputStream() );
785 logger.info( "responseBody=" + responseBody );
787 } else if ( rc == 404 ) {
789 err.setFields( "feedid");
790 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
791 err.setMessage( message );
792 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
796 err.setMessage(responsemessage);
799 } catch (ConnectException ce) {
800 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
802 err.setMessage("Backend connection refused");
803 logger.error(ce.getMessage(), ce);
804 } catch (SocketException se) {
805 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
807 err.setMessage( "Unable to read response from DR");
808 logger.error(se.getMessage(), se);
809 } catch (Exception e) {
810 if ( unit_test.equals( "Yes" ) ) {
812 err.setMessage( "simulated response");
813 logger.info( "artificial 200 response from doDeleteFeed because unit_test =" + unit_test );
815 logger.warn("Unable to read response " );
816 logger.error(e.getMessage(), e);
818 err.setCode( uc.getResponseCode());
819 err.setMessage(uc.getResponseMessage());
820 } catch (Exception e2) {
822 err.setMessage("Unable to determine response message");
823 logger.error(e2.getMessage(), e2);
831 } catch ( Exception e ) {
832 logger.error(e.getMessage(), e);
838 public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
839 logger.info( "entry: doDeleteDr_Sub() " );
840 byte[] postData = delSub.getBytes(provApi);
841 logger.info( "post fields=" + postData );
842 String responsemessage = null;
843 String responseBody = null;
847 uc.setRequestMethod("DELETE");
849 uc.setRequestProperty("Content-Type", subContentType);
850 uc.setRequestProperty( "charset", "utf-8");
851 uc.setRequestProperty( behalfHeader, "DGL" );
852 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
853 uc.setUseCaches(false);
854 uc.setDoOutput(true);
855 OutputStream os = null;
860 os = uc.getOutputStream();
861 //os.write( postData );
863 } catch (ProtocolException pe) {
864 // Rcvd error instead of 100-Continue
866 // work around glitch in Java 1.7.0.21 and likely others
867 // without this, Java will connect multiple times to the server to run the same request
868 uc.setDoOutput(false);
869 } catch (Exception e) {
870 logger.error(e.getMessage(), e);
873 rc = uc.getResponseCode();
874 logger.info( "http response code:" + rc );
875 responsemessage = uc.getResponseMessage();
876 logger.info( "responsemessage=" + responsemessage );
879 if (responsemessage == null) {
880 // work around for glitch in Java 1.7.0.21 and likely others
881 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
882 String h0 = uc.getHeaderField(0);
884 int i = h0.indexOf(' ');
885 int j = h0.indexOf(' ', i + 1);
886 if (i != -1 && j != -1) {
887 responsemessage = h0.substring(j + 1);
893 responseBody = bodyToString( uc.getInputStream() );
894 logger.info( "responseBody=" + responseBody );
896 err.setMessage(responsemessage);
899 } catch (ConnectException ce) {
900 if ( unit_test.equals( "Yes" ) ) {
902 err.setMessage( "simulated response");
903 logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
905 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
907 err.setMessage("Backend connection refused");
909 } catch (Exception e) {
910 if ( unit_test.equals( "Yes" ) ) {
912 err.setMessage( "simulated response");
913 logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
915 logger.error("Unable to read response ", e.getMessage());