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;
52 private HttpsURLConnection uc;
55 public DrProvConnection() {
56 provURL = new DmaapService().getDmaap().getDrProvUrl();
57 if ( provURL.length() < 1 ) {
58 errorLogger.error( DmaapbcLogMessageEnum.PREREQ_DMAAP_OBJECT, "getDrProvUrl");
60 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
61 provApi = p.getProperty( "DR.provApi", "ONAP" );
62 behalfHeader = p.getProperty( "DR.onBehalfHeader", "X-DMAAP-DR-ON-BEHALF-OF");
63 feedContentType = p.getProperty( "DR.feedContentType", "application/vnd.dmaap-dr.feed");
64 subContentType = p.getProperty( "DR.subContentType", "application/vnd.dmaap-dr.subscription");
65 logger.info( "provURL=" + provURL + " provApi=" + provApi + " behalfHeader=" + behalfHeader
66 + " feedContentType=" + feedContentType + " subContentType=" + subContentType );
70 public boolean makeFeedConnection() {
71 return makeConnection( provURL );
73 public boolean makeFeedConnection(String feedId) {
74 return makeConnection( provURL + "/feed/" + feedId );
76 public boolean makeSubPostConnection( String subURL ) {
77 String[] parts = subURL.split("/");
78 String revisedURL = provURL + "/" + parts[3] + "/" + parts[4];
79 logger.info( "mapping " + subURL + " to " + revisedURL );
80 return makeConnection( revisedURL );
82 public boolean makeSubPutConnection( String subId ) {
83 String revisedURL = provURL + "/subs/" + subId;
84 logger.info( "mapping " + subId + " to " + revisedURL );
85 return makeConnection( revisedURL );
88 public boolean makeIngressConnection( String feed, String user, String subnet, String nodep ) {
89 String uri = String.format("/internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s",
90 feed, user, subnet, nodep );
91 return makeConnection( provURL + uri );
93 public boolean makeEgressConnection( String sub, String nodep ) {
94 String uri = String.format("/internal/route/egress/?sub=%s&node=%s",
96 return makeConnection( provURL + uri );
98 public boolean makeNodesConnection( String varName ) {
100 String uri = String.format("/internal/api/%s", varName);
101 return makeConnection( provURL + uri );
104 public boolean makeNodesConnection( String varName, String val ) {
109 String cv = val.replaceAll("\\|", "%7C");
110 String uri = String.format( "/internal/api/%s?val=%s", varName, cv );
112 return makeConnection( provURL + uri );
115 private boolean makeConnection( String pURL ) {
118 URL u = new URL( pURL );
119 uc = (HttpsURLConnection) u.openConnection();
120 uc.setInstanceFollowRedirects(false);
121 logger.info( "successful connect to " + pURL );
123 } catch (Exception e) {
124 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR, pURL, e.getMessage() );
131 public String bodyToString( InputStream is ) {
132 logger.info( "is=" + is );
133 StringBuilder sb = new StringBuilder();
134 BufferedReader br = new BufferedReader( new InputStreamReader(is));
137 while ((line = br.readLine()) != null ) {
140 } catch (IOException ex ) {
141 errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION, ex.getMessage());
144 return sb.toString();
148 public String doPostFeed( Feed postFeed, ApiError err ) {
150 byte[] postData = postFeed.getBytes();
151 logger.info( "post fields=" + Arrays.toString(postData) );
152 String responsemessage = null;
153 String responseBody = null;
156 logger.info( "uc=" + uc );
157 uc.setRequestMethod("POST");
158 uc.setRequestProperty("Content-Type", feedContentType);
159 uc.setRequestProperty( "charset", "utf-8");
160 uc.setRequestProperty( behalfHeader, postFeed.getOwner() );
161 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
162 uc.setUseCaches(false);
163 uc.setDoOutput(true);
164 OutputStream os = null;
169 os = uc.getOutputStream();
170 os.write( postData );
172 } catch (ProtocolException pe) {
173 // Rcvd error instead of 100-Continue
175 // work around glitch in Java 1.7.0.21 and likely others
176 // without this, Java will connect multiple times to the server to run the same request
177 uc.setDoOutput(false);
178 } catch (Exception e) {
181 rc = uc.getResponseCode();
182 logger.info( "http response code:" + rc );
183 responsemessage = uc.getResponseMessage();
184 logger.info( "responsemessage=" + responsemessage );
187 if (responsemessage == null) {
188 // work around for glitch in Java 1.7.0.21 and likely others
189 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
190 String h0 = uc.getHeaderField(0);
192 int i = h0.indexOf(' ');
193 int j = h0.indexOf(' ', i + 1);
194 if (i != -1 && j != -1) {
195 responsemessage = h0.substring(j + 1);
200 responseBody = bodyToString( uc.getInputStream() );
201 logger.info( "responseBody=" + responseBody );
205 err.setMessage(responsemessage);
208 } catch (ConnectException ce) {
209 errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
211 err.setMessage("Backend connection refused");
212 } catch (SocketException se) {
213 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from prov server" );
215 err.setMessage( "Unable to read response from DR");
216 } catch (Exception e) {
217 logger.warn("Unable to read response " );
220 err.setCode( uc.getResponseCode());
221 err.setMessage(uc.getResponseMessage());
222 } catch (Exception e2) {
224 err.setMessage("Unable to determine response message");
230 } catch ( Exception e ) {}
237 // the POST for /internal/route/ingress doesn't return any data, so needs a different function
238 // the POST for /internal/route/egress doesn't return any data, so needs a different function
239 public int doXgressPost( ApiError err ) {
241 String responsemessage = null;
245 uc.setRequestMethod("POST");
251 } catch (ProtocolException pe) {
252 // Rcvd error instead of 100-Continue
254 // work around glitch in Java 1.7.0.21 and likely others
255 // without this, Java will connect multiple times to the server to run the same request
256 uc.setDoOutput(false);
257 } catch (Exception e) {
258 logger.error(e.getMessage(), e);
261 rc = uc.getResponseCode();
262 logger.info( "http response code:" + rc );
263 responsemessage = uc.getResponseMessage();
264 logger.info( "responsemessage=" + responsemessage );
268 if (rc < 200 || rc >= 300 ) {
270 err.setMessage(responsemessage);
272 } catch (Exception e) {
273 logger.error("Unable to read response " );
278 } catch ( Exception e ) {
279 logger.error(e.getMessage(), e);
287 public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
288 logger.info( "entry: doPostDr_Sub() " );
289 byte[] postData = postSub.getBytes(provApi );
290 logger.info( "post fields=" + postData );
291 String responsemessage = null;
292 String responseBody = null;
296 uc.setRequestMethod("POST");
298 uc.setRequestProperty("Content-Type", subContentType );
299 uc.setRequestProperty( "charset", "utf-8");
300 uc.setRequestProperty( behalfHeader, "DGL" );
301 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
302 uc.setUseCaches(false);
303 uc.setDoOutput(true);
304 OutputStream os = null;
309 os = uc.getOutputStream();
310 os.write( postData );
312 } catch (ProtocolException pe) {
313 // Rcvd error instead of 100-Continue
315 // work around glitch in Java 1.7.0.21 and likely others
316 // without this, Java will connect multiple times to the server to run the same request
317 uc.setDoOutput(false);
318 } catch (Exception e) {
321 rc = uc.getResponseCode();
322 logger.info( "http response code:" + rc );
323 responsemessage = uc.getResponseMessage();
324 logger.info( "responsemessage=" + responsemessage );
327 if (responsemessage == null) {
328 // work around for glitch in Java 1.7.0.21 and likely others
329 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
330 String h0 = uc.getHeaderField(0);
332 int i = h0.indexOf(' ');
333 int j = h0.indexOf(' ', i + 1);
334 if (i != -1 && j != -1) {
335 responsemessage = h0.substring(j + 1);
340 responseBody = bodyToString( uc.getInputStream() );
341 logger.info( "responseBody=" + responseBody );
345 err.setMessage(responsemessage);
348 } catch (Exception e) {
349 System.err.println("Unable to read response " );
354 } catch ( Exception e ) {}
361 public String doPutFeed(Feed putFeed, ApiError err) {
362 byte[] postData = putFeed.getBytes();
363 logger.info( "post fields=" + Arrays.toString(postData) );
364 String responsemessage = null;
365 String responseBody = null;
368 logger.info( "uc=" + uc );
369 uc.setRequestMethod("PUT");
370 uc.setRequestProperty("Content-Type", feedContentType );
371 uc.setRequestProperty( "charset", "utf-8");
372 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
373 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
374 uc.setUseCaches(false);
375 uc.setDoOutput(true);
376 OutputStream os = null;
381 os = uc.getOutputStream();
382 os.write( postData );
384 } catch (ProtocolException pe) {
385 // Rcvd error instead of 100-Continue
387 // work around glitch in Java 1.7.0.21 and likely others
388 // without this, Java will connect multiple times to the server to run the same request
389 uc.setDoOutput(false);
390 } catch (Exception e) {
393 rc = uc.getResponseCode();
394 logger.info( "http response code:" + rc );
395 responsemessage = uc.getResponseMessage();
396 logger.info( "responsemessage=" + responsemessage );
399 if (responsemessage == null) {
400 // work around for glitch in Java 1.7.0.21 and likely others
401 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
402 String h0 = uc.getHeaderField(0);
404 int i = h0.indexOf(' ');
405 int j = h0.indexOf(' ', i + 1);
406 if (i != -1 && j != -1) {
407 responsemessage = h0.substring(j + 1);
411 if (rc >= 200 && rc < 300 ) {
412 responseBody = bodyToString( uc.getInputStream() );
413 logger.info( "responseBody=" + responseBody );
415 } else if ( rc == 404 ) {
417 err.setFields( "feedid");
418 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
419 err.setMessage( message );
420 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
424 err.setMessage(responsemessage);
427 } catch (ConnectException ce) {
428 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
430 err.setMessage("Backend connection refused");
431 } catch (SocketException se) {
432 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
434 err.setMessage( "Unable to read response from DR");
435 } catch (Exception e) {
436 logger.warn("Unable to read response " );
439 err.setCode( uc.getResponseCode());
440 err.setMessage(uc.getResponseMessage());
441 } catch (Exception e2) {
443 err.setMessage("Unable to determine response message");
448 } catch ( Exception e ) {}
452 public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
453 logger.info( "entry: doPutDr_Sub() " );
454 byte[] postData = postSub.getBytes(provApi);
455 logger.info( "post fields=" + postData );
456 String responsemessage = null;
457 String responseBody = null;
461 uc.setRequestMethod("PUT");
463 uc.setRequestProperty("Content-Type", subContentType );
464 uc.setRequestProperty( "charset", "utf-8");
465 uc.setRequestProperty( behalfHeader, "DGL" );
466 uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
467 uc.setUseCaches(false);
468 uc.setDoOutput(true);
469 OutputStream os = null;
474 os = uc.getOutputStream();
475 os.write( postData );
477 } catch (ProtocolException pe) {
478 // Rcvd error instead of 100-Continue
480 // work around glitch in Java 1.7.0.21 and likely others
481 // without this, Java will connect multiple times to the server to run the same request
482 uc.setDoOutput(false);
483 } catch (Exception e) {
486 rc = uc.getResponseCode();
487 logger.info( "http response code:" + rc );
488 responsemessage = uc.getResponseMessage();
489 logger.info( "responsemessage=" + responsemessage );
492 if (responsemessage == null) {
493 // work around for glitch in Java 1.7.0.21 and likely others
494 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
495 String h0 = uc.getHeaderField(0);
497 int i = h0.indexOf(' ');
498 int j = h0.indexOf(' ', i + 1);
499 if (i != -1 && j != -1) {
500 responsemessage = h0.substring(j + 1);
505 responseBody = bodyToString( uc.getInputStream() );
506 logger.info( "responseBody=" + responseBody );
510 err.setMessage(responsemessage);
513 } catch (ConnectException ce) {
514 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
516 err.setMessage("Backend connection refused");
517 } catch (Exception e) {
518 logger.error("Unable to read response " );
519 logger.error(e.getMessage(), e);
527 public String doGetNodes( ApiError err ) {
528 logger.info( "entry: doGetNodes() " );
529 //byte[] postData = postSub.getBytes();
530 //logger.info( "get fields=" + postData );
531 String responsemessage = null;
532 String responseBody = null;
533 logger.info( "templog:doGetNodes at 12.10.14.10" );
536 logger.info( "templog:doGetNodes at 12.10.14.11" );
538 uc.setRequestMethod("GET");
541 logger.info( "templog:doGetNodes at 12.10.14.12" );
544 logger.info( "templog:doGetNodes at 12.10.14.13" );
547 } catch (ProtocolException pe) {
548 logger.info( "templog:doGetNodes at 12.10.14.14" );
549 // Rcvd error instead of 100-Continue
551 // work around glitch in Java 1.7.0.21 and likely others
552 // without this, Java will connect multiple times to the server to run the same request
553 uc.setDoOutput(false);
554 } catch (Exception e) {
557 logger.info( "templog:doGetNodes at 12.10.14.15" );
558 rc = uc.getResponseCode();
559 logger.info( "http response code:" + rc );
560 responsemessage = uc.getResponseMessage();
561 logger.info( "responsemessage=" + responsemessage );
562 logger.info( "templog:doGetNodes at 12.10.14.16" );
565 if (responsemessage == null) {
566 logger.info( "templog:doGetNodes at 12.10.14.17" );
567 // work around for glitch in Java 1.7.0.21 and likely others
568 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
569 String h0 = uc.getHeaderField(0);
571 int i = h0.indexOf(' ');
572 int j = h0.indexOf(' ', i + 1);
573 if (i != -1 && j != -1) {
574 responsemessage = h0.substring(j + 1);
578 logger.info( "templog:doGetNodes at 12.10.14.18" );
579 err.setCode(rc); // may not really be an error, but we save rc
581 responseBody = bodyToString( uc.getInputStream() );
582 logger.info( "responseBody=" + responseBody );
584 err.setMessage(responsemessage);
587 logger.info( "templog:doGetNodes at 12.10.14.19" );
588 } catch (ConnectException ce) {
589 logger.info( "templog:doGetNodes at 12.10.14.20" );
590 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
592 err.setMessage("Backend connection refused");
593 } catch (Exception e) {
594 logger.info( "templog:doGetNodes at 12.10.14.21" );
595 System.err.println("Unable to read response " );
598 logger.info( "templog:doGetNodes at 12.10.14.22" );
599 if ( uc != null ) uc.disconnect();
601 logger.info( "templog:doGetNodes at 12.10.14.23" );
605 public String doPutNodes( ApiError err ) {
606 logger.info( "entry: doPutNodes() " );
607 //byte[] postData = nodeList.getBytes();
608 //logger.info( "get fields=" + postData );
609 String responsemessage = null;
610 String responseBody = null;
614 uc.setRequestMethod("PUT");
616 //uc.setRequestProperty("Content-Type", subContentType );
617 //uc.setRequestProperty( "charset", "utf-8");
618 //uc.setRequestProperty( behalfHeader, "DGL" );
619 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
620 uc.setUseCaches(false);
621 //uc.setDoOutput(true);
622 OutputStream os = null;
627 //os = uc.getOutputStream();
628 //os.write( postData );
630 } catch (ProtocolException pe) {
631 // Rcvd error instead of 100-Continue
633 // work around glitch in Java 1.7.0.21 and likely others
634 // without this, Java will connect multiple times to the server to run the same request
635 uc.setDoOutput(false);
636 } catch (Exception e) {
639 rc = uc.getResponseCode();
640 logger.info( "http response code:" + rc );
641 responsemessage = uc.getResponseMessage();
642 logger.info( "responsemessage=" + responsemessage );
645 if (responsemessage == null) {
646 // work around for glitch in Java 1.7.0.21 and likely others
647 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
648 String h0 = uc.getHeaderField(0);
650 int i = h0.indexOf(' ');
651 int j = h0.indexOf(' ', i + 1);
652 if (i != -1 && j != -1) {
653 responsemessage = h0.substring(j + 1);
659 responseBody = bodyToString( uc.getInputStream() );
660 logger.info( "responseBody=" + responseBody );
664 err.setMessage(responsemessage);
667 } catch (Exception e) {
668 System.err.println("Unable to read response " + e.getMessage() );
679 public String doDeleteFeed(Feed putFeed, ApiError err) {
680 //byte[] postData = putFeed.getBytes();
681 //logger.info( "post fields=" + postData.toString() );
682 String responsemessage = null;
683 String responseBody = null;
686 logger.info( "uc=" + uc );
687 uc.setRequestMethod("DELETE");
688 uc.setRequestProperty("Content-Type", feedContentType );
689 uc.setRequestProperty( "charset", "utf-8");
690 uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
691 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
692 uc.setUseCaches(false);
693 uc.setDoOutput(true);
694 OutputStream os = null;
699 os = uc.getOutputStream();
700 //os.write( postData );
702 } catch (ProtocolException pe) {
703 // Rcvd error instead of 100-Continue
705 // work around glitch in Java 1.7.0.21 and likely others
706 // without this, Java will connect multiple times to the server to run the same request
707 uc.setDoOutput(false);
708 } catch (Exception e) {
711 rc = uc.getResponseCode();
712 logger.info( "http response code:" + rc );
713 responsemessage = uc.getResponseMessage();
714 logger.info( "responsemessage=" + responsemessage );
717 if (responsemessage == null) {
718 // work around for glitch in Java 1.7.0.21 and likely others
719 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
720 String h0 = uc.getHeaderField(0);
722 int i = h0.indexOf(' ');
723 int j = h0.indexOf(' ', i + 1);
724 if (i != -1 && j != -1) {
725 responsemessage = h0.substring(j + 1);
729 if (rc >= 200 && rc < 300 ) {
730 responseBody = bodyToString( uc.getInputStream() );
731 logger.info( "responseBody=" + responseBody );
733 } else if ( rc == 404 ) {
735 err.setFields( "feedid");
736 String message = "FeedId " + putFeed.getFeedId() + " not found on DR to update. Out-of-sync condition?";
737 err.setMessage( message );
738 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
742 err.setMessage(responsemessage);
745 } catch (ConnectException ce) {
746 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
748 err.setMessage("Backend connection refused");
749 } catch (SocketException se) {
750 errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
752 err.setMessage( "Unable to read response from DR");
753 } catch (Exception e) {
754 logger.warn("Unable to read response " );
757 err.setCode( uc.getResponseCode());
758 err.setMessage(uc.getResponseMessage());
759 } catch (Exception e2) {
761 err.setMessage("Unable to determine response message");
766 } catch ( Exception e ) {}
771 public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
772 logger.info( "entry: doDeleteDr_Sub() " );
773 byte[] postData = delSub.getBytes(provApi);
774 logger.info( "post fields=" + postData );
775 String responsemessage = null;
776 String responseBody = null;
780 uc.setRequestMethod("DELETE");
782 uc.setRequestProperty("Content-Type", subContentType);
783 uc.setRequestProperty( "charset", "utf-8");
784 uc.setRequestProperty( behalfHeader, "DGL" );
785 //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
786 uc.setUseCaches(false);
787 uc.setDoOutput(true);
788 OutputStream os = null;
793 os = uc.getOutputStream();
794 //os.write( postData );
796 } catch (ProtocolException pe) {
797 // Rcvd error instead of 100-Continue
799 // work around glitch in Java 1.7.0.21 and likely others
800 // without this, Java will connect multiple times to the server to run the same request
801 uc.setDoOutput(false);
802 } catch (Exception e) {
805 rc = uc.getResponseCode();
806 logger.info( "http response code:" + rc );
807 responsemessage = uc.getResponseMessage();
808 logger.info( "responsemessage=" + responsemessage );
811 if (responsemessage == null) {
812 // work around for glitch in Java 1.7.0.21 and likely others
813 // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
814 String h0 = uc.getHeaderField(0);
816 int i = h0.indexOf(' ');
817 int j = h0.indexOf(' ', i + 1);
818 if (i != -1 && j != -1) {
819 responsemessage = h0.substring(j + 1);
825 responseBody = bodyToString( uc.getInputStream() );
826 logger.info( "responseBody=" + responseBody );
828 err.setMessage(responsemessage);
831 } catch (ConnectException ce) {
832 errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
834 err.setMessage("Backend connection refused");
835 } catch (Exception e) {
836 System.err.println("Unable to read response " );
845 public static void main( String[] args ) throws Exception {
846 PropertyConfigurator.configure("log4j.properties");
847 logger.info("Started.");
849 RandomInteger ri = new RandomInteger(10000);
850 //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()) ;
852 Feed tst = new Feed( "dgl feed " + i,
854 "dgl feed " + i + "for testing",
858 ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>();
859 pubs.add( new DR_Pub( "centralLocation" ) );
863 DrProvConnection context = new DrProvConnection();
864 rc = context.makeFeedConnection();
865 logger.info( "makeFeedConnection returns " + rc);
866 ApiError err = new ApiError();
868 String tmp = context.doPostFeed( tst, err );
869 logger.info( "doPostFeed returns " + tmp);