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;
32 import javax.net.ssl.HttpsURLConnection;
34 import java.net.ConnectException;
35 import java.net.ProtocolException;
36 import java.net.SocketException;
38 import java.util.Arrays;
42 public class DrProvConnection extends BaseLoggingClass {
45 private String provURL;
47 private HttpsURLConnection uc;
50 public DrProvConnection() {
51 provURL = new DmaapService().getDmaap().getDrProvUrl();
52 if ( provURL.length() < 1 ) {
53 errorLogger.error( DmaapbcLogMessageEnum.PREREQ_DMAAP_OBJECT, "getDrProvUrl");
58 public boolean makeFeedConnection() {
59 return makeConnection( provURL );
61 public boolean makeFeedConnection(String feedId) {
62 return makeConnection( provURL + "/feed/" + feedId );
64 public boolean makeSubPostConnection( String subURL ) {
65 String[] parts = subURL.split("/");
66 String revisedURL = provURL + "/" + parts[3] + "/" + parts[4];
67 logger.info( "mapping " + subURL + " to " + revisedURL );
68 return makeConnection( revisedURL );
70 public boolean makeSubPutConnection( String subId ) {
71 String revisedURL = provURL + "/subs/" + subId;
72 logger.info( "mapping " + subId + " to " + revisedURL );
73 return makeConnection( revisedURL );
76 public boolean makeIngressConnection( String feed, String user, String subnet, String nodep ) {
77 String uri = String.format("/internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s",
78 feed, user, subnet, nodep );
79 return makeConnection( provURL + uri );
81 public boolean makeEgressConnection( String sub, String nodep ) {
82 String uri = String.format("/internal/route/egress/?sub=%s&node=%s",
84 return makeConnection( provURL + uri );
86 public boolean makeNodesConnection( String varName ) {
88 String uri = String.format("/internal/api/%s", varName);
89 return makeConnection( provURL + uri );
92 public boolean makeNodesConnection( String varName, String val ) {
97 String cv = val.replaceAll("\\|", "%7C");
98 String uri = String.format( "/internal/api/%s?val=%s", varName, cv );
100 return makeConnection( provURL + uri );
103 private boolean makeConnection( String pURL ) {
106 URL u = new URL( pURL );
107 uc = (HttpsURLConnection) u.openConnection();
108 uc.setInstanceFollowRedirects(false);
109 logger.info( "successful connect to " + pURL );
111 } catch (Exception e) {
112 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR, pURL, e.getMessage() );
119 public String bodyToString( InputStream is ) {
120 logger.info( "is=" + is );
121 StringBuilder sb = new StringBuilder();
122 BufferedReader br = new BufferedReader( new InputStreamReader(is));
125 while ((line = br.readLine()) != null ) {
128 } catch (IOException ex ) {
129 errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION, ex.getMessage());
132 return sb.toString();
136 public String doPostFeed( Feed postFeed, ApiError err ) {
138 byte[] postData = postFeed.getBytes();
139 logger.info( "post fields=" + Arrays.toString(postData) );
140 String responsemessage = null;
141 String responseBody = null;
144 logger.info( "uc=" + uc );
145 uc.setRequestMethod("POST");
146 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
147 uc.setRequestProperty( "charset", "utf-8");
148 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
149 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
150 uc.setUseCaches(false);
151 uc.setDoOutput(true);
152 OutputStream os = null;
157 os = uc.getOutputStream();
158 os.write( postData );
160 } catch (ProtocolException pe) {
161 // Rcvd error instead of 100-Continue
163 // work around glitch in Java 1.7.0.21 and likely others
164 // without this, Java will connect multiple times to the server to run the same request
165 uc.setDoOutput(false);
166 } catch (Exception e) {
169 rc = uc.getResponseCode();
170 logger.info( "http response code:" + rc );
171 responsemessage = uc.getResponseMessage();
172 logger.info( "responsemessage=" + responsemessage );
175 if (responsemessage == null) {
176 // work around for glitch in Java 1.7.0.21 and likely others
177 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
178 String h0 = uc.getHeaderField(0);
180 int i = h0.indexOf(' ');
181 int j = h0.indexOf(' ', i + 1);
182 if (i != -1 && j != -1) {
183 responsemessage = h0.substring(j + 1);
188 responseBody = bodyToString( uc.getInputStream() );
189 logger.info( "responseBody=" + responseBody );
193 err.setMessage(responsemessage);
196 } catch (ConnectException ce) {
197 errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
199 err.setMessage("Backend connection refused");
200 } catch (SocketException se) {
201 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from prov server" );
203 err.setMessage( "Unable to read response from DR");
204 } catch (Exception e) {
205 logger.warn("Unable to read response " );
208 err.setCode( uc.getResponseCode());
209 err.setMessage(uc.getResponseMessage());
210 } catch (Exception e2) {
212 err.setMessage("Unable to determine response message");
218 } catch ( Exception e ) {}
225 // the POST for /internal/route/ingress doesn't return any data, so needs a different function
226 // the POST for /internal/route/egress doesn't return any data, so needs a different function
227 public int doXgressPost( ApiError err ) {
229 String responsemessage = null;
233 uc.setRequestMethod("POST");
234 // uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
235 // uc.setRequestProperty( "charset", "utf-8");
236 // uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
237 // uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
238 // uc.setUseCaches(false);
239 // uc.setDoOutput(true);
240 OutputStream os = null;
245 os = uc.getOutputStream();
248 } catch (ProtocolException pe) {
249 // Rcvd error instead of 100-Continue
251 // work around glitch in Java 1.7.0.21 and likely others
252 // without this, Java will connect multiple times to the server to run the same request
253 uc.setDoOutput(false);
254 } catch (Exception e) {
257 rc = uc.getResponseCode();
258 logger.info( "http response code:" + rc );
259 responsemessage = uc.getResponseMessage();
260 logger.info( "responsemessage=" + responsemessage );
264 if (rc < 200 || rc >= 300 ) {
266 err.setMessage(responsemessage);
268 } catch (Exception e) {
269 System.err.println("Unable to read response " );
274 } catch ( Exception e ) {}
281 public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
282 logger.info( "entry: doPostDr_Sub() " );
283 byte[] postData = postSub.getBytes();
284 logger.info( "post fields=" + postData );
285 String responsemessage = null;
286 String responseBody = null;
290 uc.setRequestMethod("POST");
292 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
293 uc.setRequestProperty( "charset", "utf-8");
294 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
295 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
296 uc.setUseCaches(false);
297 uc.setDoOutput(true);
298 OutputStream os = null;
303 os = uc.getOutputStream();
304 os.write( postData );
306 } catch (ProtocolException pe) {
307 // Rcvd error instead of 100-Continue
309 // work around glitch in Java 1.7.0.21 and likely others
310 // without this, Java will connect multiple times to the server to run the same request
311 uc.setDoOutput(false);
312 } catch (Exception e) {
315 rc = uc.getResponseCode();
316 logger.info( "http response code:" + rc );
317 responsemessage = uc.getResponseMessage();
318 logger.info( "responsemessage=" + responsemessage );
321 if (responsemessage == null) {
322 // work around for glitch in Java 1.7.0.21 and likely others
323 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
324 String h0 = uc.getHeaderField(0);
326 int i = h0.indexOf(' ');
327 int j = h0.indexOf(' ', i + 1);
328 if (i != -1 && j != -1) {
329 responsemessage = h0.substring(j + 1);
334 responseBody = bodyToString( uc.getInputStream() );
335 logger.info( "responseBody=" + responseBody );
339 err.setMessage(responsemessage);
342 } catch (Exception e) {
343 System.err.println("Unable to read response " );
348 } catch ( Exception e ) {}
355 public String doPutFeed(Feed putFeed, ApiError err) {
356 byte[] postData = putFeed.getBytes();
357 logger.info( "post fields=" + Arrays.toString(postData) );
358 String responsemessage = null;
359 String responseBody = null;
362 logger.info( "uc=" + uc );
363 uc.setRequestMethod("PUT");
364 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
365 uc.setRequestProperty( "charset", "utf-8");
366 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
367 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
368 uc.setUseCaches(false);
369 uc.setDoOutput(true);
370 OutputStream os = null;
375 os = uc.getOutputStream();
376 os.write( postData );
378 } catch (ProtocolException pe) {
379 // Rcvd error instead of 100-Continue
381 // work around glitch in Java 1.7.0.21 and likely others
382 // without this, Java will connect multiple times to the server to run the same request
383 uc.setDoOutput(false);
384 } catch (Exception e) {
387 rc = uc.getResponseCode();
388 logger.info( "http response code:" + rc );
389 responsemessage = uc.getResponseMessage();
390 logger.info( "responsemessage=" + responsemessage );
393 if (responsemessage == null) {
394 // work around for glitch in Java 1.7.0.21 and likely others
395 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
396 String h0 = uc.getHeaderField(0);
398 int i = h0.indexOf(' ');
399 int j = h0.indexOf(' ', i + 1);
400 if (i != -1 && j != -1) {
401 responsemessage = h0.substring(j + 1);
405 if (rc >= 200 && rc < 300 ) {
406 responseBody = bodyToString( uc.getInputStream() );
407 logger.info( "responseBody=" + responseBody );
409 } else if ( rc == 404 ) {
411 err.setFields( "feedid");
412 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
413 err.setMessage( message );
414 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
418 err.setMessage(responsemessage);
421 } catch (ConnectException ce) {
422 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
424 err.setMessage("Backend connection refused");
425 } catch (SocketException se) {
426 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
428 err.setMessage( "Unable to read response from DR");
429 } catch (Exception e) {
430 logger.warn("Unable to read response " );
433 err.setCode( uc.getResponseCode());
434 err.setMessage(uc.getResponseMessage());
435 } catch (Exception e2) {
437 err.setMessage("Unable to determine response message");
442 } catch ( Exception e ) {}
446 public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
447 logger.info( "entry: doPutDr_Sub() " );
448 byte[] postData = postSub.getBytes();
449 logger.info( "post fields=" + postData );
450 String responsemessage = null;
451 String responseBody = null;
455 uc.setRequestMethod("PUT");
457 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
458 uc.setRequestProperty( "charset", "utf-8");
459 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
460 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
461 uc.setUseCaches(false);
462 uc.setDoOutput(true);
463 OutputStream os = null;
468 os = uc.getOutputStream();
469 os.write( postData );
471 } catch (ProtocolException pe) {
472 // Rcvd error instead of 100-Continue
474 // work around glitch in Java 1.7.0.21 and likely others
475 // without this, Java will connect multiple times to the server to run the same request
476 uc.setDoOutput(false);
477 } catch (Exception e) {
480 rc = uc.getResponseCode();
481 logger.info( "http response code:" + rc );
482 responsemessage = uc.getResponseMessage();
483 logger.info( "responsemessage=" + responsemessage );
486 if (responsemessage == null) {
487 // work around for glitch in Java 1.7.0.21 and likely others
488 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
489 String h0 = uc.getHeaderField(0);
491 int i = h0.indexOf(' ');
492 int j = h0.indexOf(' ', i + 1);
493 if (i != -1 && j != -1) {
494 responsemessage = h0.substring(j + 1);
499 responseBody = bodyToString( uc.getInputStream() );
500 logger.info( "responseBody=" + responseBody );
504 err.setMessage(responsemessage);
507 } catch (ConnectException ce) {
508 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
510 err.setMessage("Backend connection refused");
511 } catch (Exception e) {
512 System.err.println("Unable to read response " );
521 public String doGetNodes( ApiError err ) {
522 logger.info( "entry: doGetNodes() " );
523 //byte[] postData = postSub.getBytes();
524 //logger.info( "get fields=" + postData );
525 String responsemessage = null;
526 String responseBody = null;
527 logger.info( "templog:doGetNodes at 12.10.14.10" );
530 logger.info( "templog:doGetNodes at 12.10.14.11" );
532 uc.setRequestMethod("GET");
534 //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
535 //uc.setRequestProperty( "charset", "utf-8");
536 //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
537 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
538 //uc.setUseCaches(false);
539 //uc.setDoOutput(true);
540 OutputStream os = null;
543 logger.info( "templog:doGetNodes at 12.10.14.12" );
546 logger.info( "templog:doGetNodes at 12.10.14.13" );
547 //os = uc.getOutputStream();
548 //os.write( postData );
550 } catch (ProtocolException pe) {
551 logger.info( "templog:doGetNodes at 12.10.14.14" );
552 // Rcvd error instead of 100-Continue
554 // work around glitch in Java 1.7.0.21 and likely others
555 // without this, Java will connect multiple times to the server to run the same request
556 uc.setDoOutput(false);
557 } catch (Exception e) {
560 logger.info( "templog:doGetNodes at 12.10.14.15" );
561 rc = uc.getResponseCode();
562 logger.info( "http response code:" + rc );
563 responsemessage = uc.getResponseMessage();
564 logger.info( "responsemessage=" + responsemessage );
565 logger.info( "templog:doGetNodes at 12.10.14.16" );
568 if (responsemessage == null) {
569 logger.info( "templog:doGetNodes at 12.10.14.17" );
570 // work around for glitch in Java 1.7.0.21 and likely others
571 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
572 String h0 = uc.getHeaderField(0);
574 int i = h0.indexOf(' ');
575 int j = h0.indexOf(' ', i + 1);
576 if (i != -1 && j != -1) {
577 responsemessage = h0.substring(j + 1);
581 logger.info( "templog:doGetNodes at 12.10.14.18" );
582 err.setCode(rc); // may not really be an error, but we save rc
584 responseBody = bodyToString( uc.getInputStream() );
585 logger.info( "responseBody=" + responseBody );
587 err.setMessage(responsemessage);
590 logger.info( "templog:doGetNodes at 12.10.14.19" );
591 } catch (ConnectException ce) {
592 logger.info( "templog:doGetNodes at 12.10.14.20" );
593 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
595 err.setMessage("Backend connection refused");
596 } catch (Exception e) {
597 logger.info( "templog:doGetNodes at 12.10.14.21" );
598 System.err.println("Unable to read response " );
601 logger.info( "templog:doGetNodes at 12.10.14.22" );
602 if ( uc != null ) uc.disconnect();
604 logger.info( "templog:doGetNodes at 12.10.14.23" );
608 public String doPutNodes( ApiError err ) {
609 logger.info( "entry: doPutNodes() " );
610 //byte[] postData = nodeList.getBytes();
611 //logger.info( "get fields=" + postData );
612 String responsemessage = null;
613 String responseBody = null;
617 uc.setRequestMethod("PUT");
619 //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
620 //uc.setRequestProperty( "charset", "utf-8");
621 //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
622 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
623 uc.setUseCaches(false);
624 //uc.setDoOutput(true);
625 OutputStream os = null;
630 //os = uc.getOutputStream();
631 //os.write( postData );
633 } catch (ProtocolException pe) {
634 // Rcvd error instead of 100-Continue
636 // work around glitch in Java 1.7.0.21 and likely others
637 // without this, Java will connect multiple times to the server to run the same request
638 uc.setDoOutput(false);
639 } catch (Exception e) {
642 rc = uc.getResponseCode();
643 logger.info( "http response code:" + rc );
644 responsemessage = uc.getResponseMessage();
645 logger.info( "responsemessage=" + responsemessage );
648 if (responsemessage == null) {
649 // work around for glitch in Java 1.7.0.21 and likely others
650 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
651 String h0 = uc.getHeaderField(0);
653 int i = h0.indexOf(' ');
654 int j = h0.indexOf(' ', i + 1);
655 if (i != -1 && j != -1) {
656 responsemessage = h0.substring(j + 1);
662 responseBody = bodyToString( uc.getInputStream() );
663 logger.info( "responseBody=" + responseBody );
667 err.setMessage(responsemessage);
670 } catch (Exception e) {
671 System.err.println("Unable to read response " + e.getMessage() );
682 public String doDeleteFeed(Feed putFeed, ApiError err) {
683 //byte[] postData = putFeed.getBytes();
684 //logger.info( "post fields=" + postData.toString() );
685 String responsemessage = null;
686 String responseBody = null;
689 logger.info( "uc=" + uc );
690 uc.setRequestMethod("DELETE");
691 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
692 uc.setRequestProperty( "charset", "utf-8");
693 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
694 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
695 uc.setUseCaches(false);
696 uc.setDoOutput(true);
697 OutputStream os = null;
702 os = uc.getOutputStream();
703 //os.write( postData );
705 } catch (ProtocolException pe) {
706 // Rcvd error instead of 100-Continue
708 // work around glitch in Java 1.7.0.21 and likely others
709 // without this, Java will connect multiple times to the server to run the same request
710 uc.setDoOutput(false);
711 } catch (Exception e) {
714 rc = uc.getResponseCode();
715 logger.info( "http response code:" + rc );
716 responsemessage = uc.getResponseMessage();
717 logger.info( "responsemessage=" + responsemessage );
720 if (responsemessage == null) {
721 // work around for glitch in Java 1.7.0.21 and likely others
722 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
723 String h0 = uc.getHeaderField(0);
725 int i = h0.indexOf(' ');
726 int j = h0.indexOf(' ', i + 1);
727 if (i != -1 && j != -1) {
728 responsemessage = h0.substring(j + 1);
732 if (rc >= 200 && rc < 300 ) {
733 responseBody = bodyToString( uc.getInputStream() );
734 logger.info( "responseBody=" + responseBody );
736 } else if ( rc == 404 ) {
738 err.setFields( "feedid");
739 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
740 err.setMessage( message );
741 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
745 err.setMessage(responsemessage);
748 } catch (ConnectException ce) {
749 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
751 err.setMessage("Backend connection refused");
752 } catch (SocketException se) {
753 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
755 err.setMessage( "Unable to read response from DR");
756 } catch (Exception e) {
757 logger.warn("Unable to read response " );
760 err.setCode( uc.getResponseCode());
761 err.setMessage(uc.getResponseMessage());
762 } catch (Exception e2) {
764 err.setMessage("Unable to determine response message");
769 } catch ( Exception e ) {}
774 public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
775 logger.info( "entry: doDeleteDr_Sub() " );
776 byte[] postData = delSub.getBytes();
777 logger.info( "post fields=" + postData );
778 String responsemessage = null;
779 String responseBody = null;
783 uc.setRequestMethod("DELETE");
785 uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
786 uc.setRequestProperty( "charset", "utf-8");
787 uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
788 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
789 uc.setUseCaches(false);
790 uc.setDoOutput(true);
791 OutputStream os = null;
796 os = uc.getOutputStream();
797 //os.write( postData );
799 } catch (ProtocolException pe) {
800 // Rcvd error instead of 100-Continue
802 // work around glitch in Java 1.7.0.21 and likely others
803 // without this, Java will connect multiple times to the server to run the same request
804 uc.setDoOutput(false);
805 } catch (Exception e) {
808 rc = uc.getResponseCode();
809 logger.info( "http response code:" + rc );
810 responsemessage = uc.getResponseMessage();
811 logger.info( "responsemessage=" + responsemessage );
814 if (responsemessage == null) {
815 // work around for glitch in Java 1.7.0.21 and likely others
816 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
817 String h0 = uc.getHeaderField(0);
819 int i = h0.indexOf(' ');
820 int j = h0.indexOf(' ', i + 1);
821 if (i != -1 && j != -1) {
822 responsemessage = h0.substring(j + 1);
828 responseBody = bodyToString( uc.getInputStream() );
829 logger.info( "responseBody=" + responseBody );
831 err.setMessage(responsemessage);
834 } catch (ConnectException ce) {
835 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
837 err.setMessage("Backend connection refused");
838 } catch (Exception e) {
839 System.err.println("Unable to read response " );
848 public static void main( String[] args ) throws Exception {
849 PropertyConfigurator.configure("log4j.properties");
850 logger.info("Started.");
852 RandomInteger ri = new RandomInteger(10000);
853 //String postJSON = String.format("{\"name\": \"dgl feed %d\", \"version\": \"v1.0\", \"description\": \"dgl feed N for testing\", \"authorization\": { \"classification\": \"unclassified\", \"endpoint_addrs\": [],\"endpoint_ids\": [{\"password\": \"test\",\"id\": \"test\"}]}}", ri.next()) ;
855 Feed tst = new Feed( "dgl feed " + i,
857 "dgl feed " + i + "for testing",
861 ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>();
862 pubs.add( new DR_Pub( "centralLocation" ) );
866 DrProvConnection context = new DrProvConnection();
867 rc = context.makeFeedConnection();
868 logger.info( "makeFeedConnection returns " + rc);
869 ApiError err = new ApiError();
871 String tmp = context.doPostFeed( tst, err );
872 logger.info( "doPostFeed returns " + tmp);