DMAAP-83 Initial code import
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / aaf / client / DrProvConnection.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.dbcapi.aaf.client;
22
23 import java.io.BufferedReader;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.OutputStream;
28 import java.net.ConnectException;
29 import java.net.ProtocolException;
30 import java.net.SocketException;
31 import java.net.URL;
32 import java.util.ArrayList;
33
34 import javax.net.ssl.HttpsURLConnection;
35
36 import org.apache.log4j.Logger;
37 import org.apache.log4j.PropertyConfigurator;
38 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
39 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
40 import org.onap.dmaap.dbcapi.model.ApiError;
41 import org.onap.dmaap.dbcapi.model.DR_Pub;
42 import org.onap.dmaap.dbcapi.model.DR_Sub;
43 import org.onap.dmaap.dbcapi.model.Feed;
44 import org.onap.dmaap.dbcapi.service.DmaapService;
45 import org.onap.dmaap.dbcapi.util.RandomInteger;
46
47
48
49 public class DrProvConnection extends BaseLoggingClass {
50            
51    
52         private String provURL;
53         
54         private HttpsURLConnection uc;
55
56
57         public DrProvConnection() {
58                 provURL = new DmaapService().getDmaap().getDrProvUrl();
59                 if ( provURL.length() < 1 ) {
60                         errorLogger.error( DmaapbcLogMessageEnum.PREREQ_DMAAP_OBJECT, "getDrProvUrl");
61                 }
62                         
63         }
64         
65         public boolean makeFeedConnection() {
66                 return makeConnection( provURL );
67         }
68         public boolean makeFeedConnection(String feedId) {
69                 return makeConnection( provURL + "/feed/" + feedId );   
70         }
71         public boolean makeSubPostConnection( String subURL ) {
72                 String[] parts = subURL.split("/");
73                 String revisedURL = provURL + "/" + parts[3] + "/" + parts[4];
74                 logger.info( "mapping " + subURL + " to " + revisedURL );
75                 return makeConnection( revisedURL );
76         }
77         public boolean makeSubPutConnection( String subId ) {
78                 String revisedURL = provURL + "/subs/" + subId;
79                 logger.info( "mapping " + subId + " to " + revisedURL );
80                 return makeConnection( revisedURL );
81         }
82
83         public boolean makeIngressConnection( String feed, String user, String subnet, String nodep ) {
84                 String uri = String.format("/internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s", 
85                                         feed, user, subnet, nodep );
86                 return makeConnection( provURL + uri );
87         }
88         public boolean makeEgressConnection( String sub, String nodep ) {
89                 String uri = String.format("/internal/route/egress/?sub=%s&node=%s", 
90                                         sub,  nodep );
91                 return makeConnection( provURL + uri );
92         }
93         public boolean makeNodesConnection( String varName ) {
94                 
95                 String uri = String.format("/internal/api/%s", varName);
96                 return makeConnection( provURL + uri );
97         }
98         
99         public boolean makeNodesConnection( String varName, String val ) {
100
101                 if ( val == null ) {
102                         return false;
103                 } 
104                 String cv = val.replaceAll("\\|", "%7C");
105                 String uri = String.format( "/internal/api/%s?val=%s", varName, cv );
106
107                 return makeConnection( provURL + uri );
108         }
109         
110         private boolean makeConnection( String pURL ) {
111         
112                 try {
113                         URL u = new URL( pURL );
114                         uc = (HttpsURLConnection) u.openConnection();
115                         uc.setInstanceFollowRedirects(false);
116                         logger.info( "successful connect to " + pURL );
117                         return(true);
118                 } catch (Exception e) {
119                         errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR,  pURL, e.getMessage() );
120             e.printStackTrace();
121             return(false);
122         }
123
124         }
125         
126         private String bodyToString( InputStream is ) {
127                 logger.info( "is=" + is );
128                 StringBuilder sb = new StringBuilder();
129                 BufferedReader br = new BufferedReader( new InputStreamReader(is));
130                 String line;
131                 try {
132                         while ((line = br.readLine()) != null ) {
133                                 sb.append( line );
134                         }
135                 } catch (IOException ex ) {
136                         errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION, ex.getMessage());
137                 }
138                         
139                 return sb.toString();
140         }
141         
142
143         public  String doPostFeed( Feed postFeed, ApiError err ) {
144
145                 byte[] postData = postFeed.getBytes();
146                 logger.info( "post fields=" + postData.toString() );
147                 String responsemessage = null;
148                 String responseBody = null;
149
150                 try {
151                         logger.info( "uc=" + uc );
152                         uc.setRequestMethod("POST");
153                         uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
154                         uc.setRequestProperty( "charset", "utf-8");
155                         uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
156                         uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
157                         uc.setUseCaches(false);
158                         uc.setDoOutput(true);
159                         OutputStream os = null;
160                         int rc = -1;
161                         
162                         try {
163                  uc.connect();
164                  os = uc.getOutputStream();
165                  os.write( postData );
166
167             } catch (ProtocolException pe) {
168                  // Rcvd error instead of 100-Continue
169                  try {
170                      // work around glitch in Java 1.7.0.21 and likely others
171                      // without this, Java will connect multiple times to the server to run the same request
172                      uc.setDoOutput(false);
173                  } catch (Exception e) {
174                  }
175             }
176                         rc = uc.getResponseCode();
177                         logger.info( "http response code:" + rc );
178             responsemessage = uc.getResponseMessage();
179             logger.info( "responsemessage=" + responsemessage );
180
181
182             if (responsemessage == null) {
183                  // work around for glitch in Java 1.7.0.21 and likely others
184                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
185                  String h0 = uc.getHeaderField(0);
186                  if (h0 != null) {
187                      int i = h0.indexOf(' ');
188                      int j = h0.indexOf(' ', i + 1);
189                      if (i != -1 && j != -1) {
190                          responsemessage = h0.substring(j + 1);
191                      }
192                  }
193             }
194             if (rc == 201 ) {
195                         responseBody = bodyToString( uc.getInputStream() );
196                         logger.info( "responseBody=" + responseBody );
197
198             } else {
199                 err.setCode( rc );
200                 err.setMessage(responsemessage);
201             }
202             
203                 } catch (ConnectException ce) {
204                         errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
205             err.setCode( 500 );
206                 err.setMessage("Backend connection refused");
207                 } catch (SocketException se) {
208                         errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from prov server" );
209                         err.setCode( 500 );
210                         err.setMessage( "Unable to read response from DR");
211         } catch (Exception e) {
212             logger.warn("Unable to read response  " );
213             e.printStackTrace();
214             try {
215                     err.setCode( uc.getResponseCode());
216                     err.setMessage(uc.getResponseMessage());
217             } catch (Exception e2) {
218                 err.setCode( 500 );
219                 err.setMessage("Unable to determine response message");
220             }
221         } 
222                 finally {
223                         try {
224                                 uc.disconnect();
225                         } catch ( Exception e ) {}
226                 }
227                 return responseBody;
228
229         }
230
231         
232         // the POST for /internal/route/ingress doesn't return any data, so needs a different function
233         // the POST for /internal/route/egress doesn't return any data, so needs a different function   
234         public int doXgressPost( ApiError err ) {
235                 
236                 String responsemessage = null;
237                 int rc = -1;
238
239                 try {
240                         uc.setRequestMethod("POST");
241 //                      uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
242 //                      uc.setRequestProperty( "charset", "utf-8");
243 //                      uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
244 //                      uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
245 //                      uc.setUseCaches(false);
246 //                      uc.setDoOutput(true);   
247                         OutputStream os = null;
248         
249                         
250                         try {
251                  uc.connect();
252                  os = uc.getOutputStream();
253
254
255             } catch (ProtocolException pe) {
256                  // Rcvd error instead of 100-Continue
257                  try {
258                      // work around glitch in Java 1.7.0.21 and likely others
259                      // without this, Java will connect multiple times to the server to run the same request
260                      uc.setDoOutput(false);
261                  } catch (Exception e) {
262                  }
263             }
264                         rc = uc.getResponseCode();
265                         logger.info( "http response code:" + rc );
266             responsemessage = uc.getResponseMessage();
267             logger.info( "responsemessage=" + responsemessage );
268
269
270
271             if (rc < 200 || rc >= 300 ) {
272                 err.setCode( rc );
273                 err.setMessage(responsemessage);
274             }
275                 } catch (Exception e) {
276             System.err.println("Unable to read response  " );
277             e.printStackTrace();
278         }               finally {
279                         try {
280                                 uc.disconnect();
281                         } catch ( Exception e ) {}
282                 }
283         
284                 return rc;
285
286         }
287         
288         public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
289                 logger.info( "entry: doPostDr_Sub() "  );
290                 byte[] postData = postSub.getBytes();
291                 logger.info( "post fields=" + postData );
292                 String responsemessage = null;
293                 String responseBody = null;
294
295                 try {
296         
297                         uc.setRequestMethod("POST");
298                 
299                         uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
300                         uc.setRequestProperty( "charset", "utf-8");
301                         uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
302                         uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
303                         uc.setUseCaches(false);
304                         uc.setDoOutput(true);
305                         OutputStream os = null;
306                         int rc = -1;
307                         
308                         try {
309                  uc.connect();
310                  os = uc.getOutputStream();
311                  os.write( postData );
312
313             } catch (ProtocolException pe) {
314                  // Rcvd error instead of 100-Continue
315                  try {
316                      // work around glitch in Java 1.7.0.21 and likely others
317                      // without this, Java will connect multiple times to the server to run the same request
318                      uc.setDoOutput(false);
319                  } catch (Exception e) {
320                  }
321             }
322                         rc = uc.getResponseCode();
323                         logger.info( "http response code:" + rc );
324             responsemessage = uc.getResponseMessage();
325             logger.info( "responsemessage=" + responsemessage );
326
327
328             if (responsemessage == null) {
329                  // work around for glitch in Java 1.7.0.21 and likely others
330                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
331                  String h0 = uc.getHeaderField(0);
332                  if (h0 != null) {
333                      int i = h0.indexOf(' ');
334                      int j = h0.indexOf(' ', i + 1);
335                      if (i != -1 && j != -1) {
336                          responsemessage = h0.substring(j + 1);
337                      }
338                  }
339             }
340             if (rc == 201 ) {
341                         responseBody = bodyToString( uc.getInputStream() );
342                         logger.info( "responseBody=" + responseBody );
343
344             } else {
345                 err.setCode(rc);
346                 err.setMessage(responsemessage);
347             }
348             
349                 } catch (Exception e) {
350             System.err.println("Unable to read response  " );
351             e.printStackTrace();
352         }               finally {
353                         try {
354                                 uc.disconnect();
355                         } catch ( Exception e ) {}
356                 }
357                 return responseBody;
358
359         }
360         
361
362         public String doPutFeed(Feed putFeed, ApiError err) {
363                 byte[] postData = putFeed.getBytes();
364                 logger.info( "post fields=" + postData.toString() );
365                 String responsemessage = null;
366                 String responseBody = null;
367
368                 try {
369                         logger.info( "uc=" + uc );
370                         uc.setRequestMethod("PUT");
371                         uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
372                         uc.setRequestProperty( "charset", "utf-8");
373                         uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
374                         uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
375                         uc.setUseCaches(false);
376                         uc.setDoOutput(true);
377                         OutputStream os = null;
378                         int rc = -1;
379                         
380                         try {
381                  uc.connect();
382                  os = uc.getOutputStream();
383                  os.write( postData );
384
385             } catch (ProtocolException pe) {
386                  // Rcvd error instead of 100-Continue
387                  try {
388                      // work around glitch in Java 1.7.0.21 and likely others
389                      // without this, Java will connect multiple times to the server to run the same request
390                      uc.setDoOutput(false);
391                  } catch (Exception e) {
392                  }
393             }
394                         rc = uc.getResponseCode();
395                         logger.info( "http response code:" + rc );
396             responsemessage = uc.getResponseMessage();
397             logger.info( "responsemessage=" + responsemessage );
398
399
400             if (responsemessage == null) {
401                  // work around for glitch in Java 1.7.0.21 and likely others
402                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
403                  String h0 = uc.getHeaderField(0);
404                  if (h0 != null) {
405                      int i = h0.indexOf(' ');
406                      int j = h0.indexOf(' ', i + 1);
407                      if (i != -1 && j != -1) {
408                          responsemessage = h0.substring(j + 1);
409                      }
410                  }
411             }
412             if (rc >= 200 && rc < 300 ) {
413                         responseBody = bodyToString( uc.getInputStream() );
414                         logger.info( "responseBody=" + responseBody );
415
416             } else if ( rc == 404 ) {
417                 err.setCode( rc );
418                 err.setFields( "feedid");
419                 String message =  "FeedId " + putFeed.getFeedId() + " not found on DR to update.  Out-of-sync condition?";
420                 err.setMessage( message );
421                 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
422                 
423             } else {
424                 err.setCode( rc );
425                 err.setMessage(responsemessage);
426             }
427             
428                 } catch (ConnectException ce) {
429                         errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
430             err.setCode( 500 );
431                 err.setMessage("Backend connection refused");
432                 } catch (SocketException se) {
433                         errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
434                         err.setCode( 500 );
435                         err.setMessage( "Unable to read response from DR");
436         } catch (Exception e) {
437             logger.warn("Unable to read response  " );
438             e.printStackTrace();
439             try {
440                     err.setCode( uc.getResponseCode());
441                     err.setMessage(uc.getResponseMessage());
442             } catch (Exception e2) {
443                 err.setCode( 500 );
444                 err.setMessage("Unable to determine response message");
445             }
446         }               finally {
447                         try {
448                                 uc.disconnect();
449                         } catch ( Exception e ) {}
450                 }
451                 return responseBody;
452         }
453         public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
454                 logger.info( "entry: doPutDr_Sub() "  );
455                 byte[] postData = postSub.getBytes();
456                 logger.info( "post fields=" + postData );
457                 String responsemessage = null;
458                 String responseBody = null;
459
460                 try {
461         
462                         uc.setRequestMethod("PUT");
463                 
464                         uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
465                         uc.setRequestProperty( "charset", "utf-8");
466                         uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
467                         uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
468                         uc.setUseCaches(false);
469                         uc.setDoOutput(true);
470                         OutputStream os = null;
471                         int rc = -1;
472                         
473                         try {
474                  uc.connect();
475                  os = uc.getOutputStream();
476                  os.write( postData );
477
478             } catch (ProtocolException pe) {
479                  // Rcvd error instead of 100-Continue
480                  try {
481                      // work around glitch in Java 1.7.0.21 and likely others
482                      // without this, Java will connect multiple times to the server to run the same request
483                      uc.setDoOutput(false);
484                  } catch (Exception e) {
485                  }
486             }
487                         rc = uc.getResponseCode();
488                         logger.info( "http response code:" + rc );
489             responsemessage = uc.getResponseMessage();
490             logger.info( "responsemessage=" + responsemessage );
491
492
493             if (responsemessage == null) {
494                  // work around for glitch in Java 1.7.0.21 and likely others
495                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
496                  String h0 = uc.getHeaderField(0);
497                  if (h0 != null) {
498                      int i = h0.indexOf(' ');
499                      int j = h0.indexOf(' ', i + 1);
500                      if (i != -1 && j != -1) {
501                          responsemessage = h0.substring(j + 1);
502                      }
503                  }
504             }
505             if (rc == 200 ) {
506                         responseBody = bodyToString( uc.getInputStream() );
507                         logger.info( "responseBody=" + responseBody );
508
509             } else {
510                 err.setCode(rc);
511                 err.setMessage(responsemessage);
512             }
513             
514                 } catch (ConnectException ce) {
515             errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
516             err.setCode( 500 );
517                 err.setMessage("Backend connection refused");
518                 } catch (Exception e) {
519             System.err.println("Unable to read response  " );
520             e.printStackTrace();
521         } finally {
522                 uc.disconnect();
523         }
524                 return responseBody;
525
526         }
527         
528         public String doGetNodes( ApiError err ) {
529                 logger.info( "entry: doGetNodes() "  );
530                 //byte[] postData = postSub.getBytes();
531                 //logger.info( "get fields=" + postData );
532                 String responsemessage = null;
533                 String responseBody = null;
534
535                 try {
536         
537                         uc.setRequestMethod("GET");
538                 
539                         //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
540                         //uc.setRequestProperty( "charset", "utf-8");
541                         //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
542                         //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
543                         //uc.setUseCaches(false);
544                         //uc.setDoOutput(true);
545                         OutputStream os = null;
546                         int rc = -1;
547                         
548                         try {
549                  uc.connect();
550                  //os = uc.getOutputStream();
551                  //os.write( postData );
552
553             } catch (ProtocolException pe) {
554                  // Rcvd error instead of 100-Continue
555                  try {
556                      // work around glitch in Java 1.7.0.21 and likely others
557                      // without this, Java will connect multiple times to the server to run the same request
558                      uc.setDoOutput(false);
559                  } catch (Exception e) {
560                  }
561             } 
562                         rc = uc.getResponseCode();
563                         logger.info( "http response code:" + rc );
564             responsemessage = uc.getResponseMessage();
565             logger.info( "responsemessage=" + responsemessage );
566
567
568             if (responsemessage == null) {
569                  // work around for glitch in Java 1.7.0.21 and likely others
570                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
571                  String h0 = uc.getHeaderField(0);
572                  if (h0 != null) {
573                      int i = h0.indexOf(' ');
574                      int j = h0.indexOf(' ', i + 1);
575                      if (i != -1 && j != -1) {
576                          responsemessage = h0.substring(j + 1);
577                      }
578                  }
579             }
580                 err.setCode(rc);  // may not really be an error, but we save rc
581             if (rc == 200 ) {
582                         responseBody = bodyToString( uc.getInputStream() );
583                         logger.info( "responseBody=" + responseBody );
584             } else {
585                 err.setMessage(responsemessage);
586             }
587             
588                 } catch (ConnectException ce) {
589             errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
590             err.setCode( 500 );
591                 err.setMessage("Backend connection refused");
592                 } catch (Exception e) {
593             System.err.println("Unable to read response  " );
594             e.printStackTrace();
595         } finally {
596                 uc.disconnect();
597         }
598                 return responseBody;
599
600         }
601         public String doPutNodes( ApiError err ) {
602                 logger.info( "entry: doPutNodes() "  );
603                 //byte[] postData = nodeList.getBytes();
604                 //logger.info( "get fields=" + postData );
605                 String responsemessage = null;
606                 String responseBody = null;
607
608                 try {
609         
610                         uc.setRequestMethod("PUT");
611                 
612                         //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
613                         //uc.setRequestProperty( "charset", "utf-8");
614                         //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
615                         //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
616                         uc.setUseCaches(false);
617                         //uc.setDoOutput(true);
618                         OutputStream os = null;
619                         int rc = -1;
620                         
621                         try {
622                  uc.connect();
623                  //os = uc.getOutputStream();
624                  //os.write( postData );
625
626             } catch (ProtocolException pe) {
627                  // Rcvd error instead of 100-Continue
628                  try {
629                      // work around glitch in Java 1.7.0.21 and likely others
630                      // without this, Java will connect multiple times to the server to run the same request
631                      uc.setDoOutput(false);
632                  } catch (Exception e) {
633                  }
634             }
635                         rc = uc.getResponseCode();
636                         logger.info( "http response code:" + rc );
637             responsemessage = uc.getResponseMessage();
638             logger.info( "responsemessage=" + responsemessage );
639
640
641             if (responsemessage == null) {
642                  // work around for glitch in Java 1.7.0.21 and likely others
643                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
644                  String h0 = uc.getHeaderField(0);
645                  if (h0 != null) {
646                      int i = h0.indexOf(' ');
647                      int j = h0.indexOf(' ', i + 1);
648                      if (i != -1 && j != -1) {
649                          responsemessage = h0.substring(j + 1);
650                      }
651                  }
652             }
653                 err.setCode(rc);
654             if (rc == 200 ) {
655                         responseBody = bodyToString( uc.getInputStream() );
656                         logger.info( "responseBody=" + responseBody );
657
658             } else {
659   
660                 err.setMessage(responsemessage);
661             }
662             
663                 } catch (Exception e) {
664             System.err.println("Unable to read response  " );
665             e.printStackTrace();
666         } finally {
667                 uc.disconnect();
668         }
669                 return responseBody;
670
671         }
672         
673         public String doDeleteFeed(Feed putFeed, ApiError err) {
674                 //byte[] postData = putFeed.getBytes();
675                 //logger.info( "post fields=" + postData.toString() );
676                 String responsemessage = null;
677                 String responseBody = null;
678
679                 try {
680                         logger.info( "uc=" + uc );
681                         uc.setRequestMethod("DELETE");
682                         uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
683                         uc.setRequestProperty( "charset", "utf-8");
684                         uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
685                         //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
686                         uc.setUseCaches(false);
687                         uc.setDoOutput(true);
688                         OutputStream os = null;
689                         int rc = -1;
690                         
691                         try {
692                  uc.connect();
693                  os = uc.getOutputStream();
694                  //os.write( postData );
695
696             } catch (ProtocolException pe) {
697                  // Rcvd error instead of 100-Continue
698                  try {
699                      // work around glitch in Java 1.7.0.21 and likely others
700                      // without this, Java will connect multiple times to the server to run the same request
701                      uc.setDoOutput(false);
702                  } catch (Exception e) {
703                  }
704             }
705                         rc = uc.getResponseCode();
706                         logger.info( "http response code:" + rc );
707             responsemessage = uc.getResponseMessage();
708             logger.info( "responsemessage=" + responsemessage );
709
710
711             if (responsemessage == null) {
712                  // work around for glitch in Java 1.7.0.21 and likely others
713                  // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
714                  String h0 = uc.getHeaderField(0);
715                  if (h0 != null) {
716                      int i = h0.indexOf(' ');
717                      int j = h0.indexOf(' ', i + 1);
718                      if (i != -1 && j != -1) {
719                          responsemessage = h0.substring(j + 1);
720                      }
721                  }
722             }
723             if (rc >= 200 && rc < 300 ) {
724                         responseBody = bodyToString( uc.getInputStream() );
725                         logger.info( "responseBody=" + responseBody );
726
727             } else if ( rc == 404 ) {
728                 err.setCode( rc );
729                 err.setFields( "feedid");
730                 String message =  "FeedId " + putFeed.getFeedId() + " not found on DR to update.  Out-of-sync condition?";
731                 err.setMessage( message );
732                 errorLogger.error( DmaapbcLogMessageEnum.PROV_OUT_OF_SYNC, "Feed", putFeed.getFeedId() );
733                 
734             } else {
735                 err.setCode( rc );
736                 err.setMessage(responsemessage);
737             }
738             
739                 } catch (ConnectException ce) {
740                         errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
741             err.setCode( 500 );
742                 err.setMessage("Backend connection refused");
743                 } catch (SocketException se) {
744                         errorLogger.error( DmaapbcLogMessageEnum.SOCKET_EXCEPTION, se.getMessage(), "response from Prov server" );
745                         err.setCode( 500 );
746                         err.setMessage( "Unable to read response from DR");
747         } catch (Exception e) {
748             logger.warn("Unable to read response  " );
749             e.printStackTrace();
750             try {
751                     err.setCode( uc.getResponseCode());
752                     err.setMessage(uc.getResponseMessage());
753             } catch (Exception e2) {
754                 err.setCode( 500 );
755                 err.setMessage("Unable to determine response message");
756             }
757         }               finally {
758                         try {
759                                 uc.disconnect();
760                         } catch ( Exception e ) {}
761                 }
762                 return responseBody;
763         }
764         
765         /*
766          public static void main( String[] args ) throws Exception {
767                 PropertyConfigurator.configure("log4j.properties");
768                 logger.info("Started.");
769                 
770                 RandomInteger ri = new RandomInteger(10000);
771                         //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()) ;
772                         int i = ri.next();
773                         Feed tst = new Feed( "dgl feed " + i,
774                                                                 "v1.0",
775                                                                 "dgl feed " + i + "for testing",
776                                                                 "TEST",
777                                                                 "unclassified"
778                                         );
779                         ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>();
780                         pubs.add( new DR_Pub( "centralLocation" ) ); 
781                         tst.setPubs(pubs);
782
783                 boolean rc;
784                 DrProvConnection context = new DrProvConnection();
785                 rc = context.makeFeedConnection();
786                 logger.info( "makeFeedConnection returns " + rc);
787                 ApiError err = new ApiError();
788                 if ( rc ) {
789                         String tmp  = context.doPostFeed( tst, err );
790                         logger.info( "doPostFeed returns " + tmp);
791                 }
792     
793          }
794  */
795         
796                 
797 }