- /*
- public static void main( String[] args ) throws Exception {
- PropertyConfigurator.configure("log4j.properties");
- logger.info("Started.");
-
- RandomInteger ri = new RandomInteger(10000);
- //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()) ;
- int i = ri.next();
- Feed tst = new Feed( "dgl feed " + i,
- "v1.0",
- "dgl feed " + i + "for testing",
- "TEST",
- "unclassified"
- );
- ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>();
- pubs.add( new DR_Pub( "centralLocation" ) );
- tst.setPubs(pubs);
-
- boolean rc;
- DrProvConnection context = new DrProvConnection();
- rc = context.makeFeedConnection();
- logger.info( "makeFeedConnection returns " + rc);
- ApiError err = new ApiError();
- if ( rc ) {
- String tmp = context.doPostFeed( tst, err );
- logger.info( "doPostFeed returns " + tmp);
- }
-
- }
- */
+ public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
+ logger.info( "entry: doDeleteDr_Sub() " );
+ byte[] postData = delSub.getBytes(provApi);
+ logger.info( "post fields=" + postData );
+ String responsemessage = null;
+ String responseBody = null;
+
+ try {
+
+ uc.setRequestMethod("DELETE");
+
+ uc.setRequestProperty("Content-Type", subContentType);
+ uc.setRequestProperty( "charset", "utf-8");
+ uc.setRequestProperty( behalfHeader, "DGL" );
+ //uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
+ uc.setUseCaches(false);
+ uc.setDoOutput(true);
+ OutputStream os = null;
+ int rc = -1;
+
+ try {
+ uc.connect();
+ os = uc.getOutputStream();
+ //os.write( postData );
+
+ } catch (ProtocolException pe) {
+ // Rcvd error instead of 100-Continue
+ try {
+ // work around glitch in Java 1.7.0.21 and likely others
+ // without this, Java will connect multiple times to the server to run the same request
+ uc.setDoOutput(false);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ rc = uc.getResponseCode();
+ logger.info( "http response code:" + rc );
+ responsemessage = uc.getResponseMessage();
+ logger.info( "responsemessage=" + responsemessage );
+
+
+ if (responsemessage == null) {
+ // work around for glitch in Java 1.7.0.21 and likely others
+ // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is
+ String h0 = uc.getHeaderField(0);
+ if (h0 != null) {
+ int i = h0.indexOf(' ');
+ int j = h0.indexOf(' ', i + 1);
+ if (i != -1 && j != -1) {
+ responsemessage = h0.substring(j + 1);
+ }
+ }
+ }
+ err.setCode(rc);
+ if (rc == 204 ) {
+ responseBody = bodyToString( uc.getInputStream() );
+ logger.info( "responseBody=" + responseBody );
+ } else {
+ err.setMessage(responsemessage);
+ }
+
+ } catch (ConnectException ce) {
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
+ } else {
+ errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
+ err.setCode( 500 );
+ err.setMessage("Backend connection refused");
+ }
+ } catch (Exception e) {
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
+ } else {
+ logger.error("Unable to read response ", e.getMessage());
+ }
+ } finally {
+ if(uc != null){
+ uc.disconnect();
+ }
+ }
+ return responseBody;
+
+ }