import org.onap.dmaap.dbcapi.model.DR_Sub;
import org.onap.dmaap.dbcapi.model.Feed;
import org.onap.dmaap.dbcapi.service.DmaapService;
+import org.onap.dmaap.dbcapi.util.DmaapConfig;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
private String provURL;
+ private String provApi;
+ private String behalfHeader;
+ private String feedContentType;
+ private String subContentType;
private HttpsURLConnection uc;
if ( provURL.length() < 1 ) {
errorLogger.error( DmaapbcLogMessageEnum.PREREQ_DMAAP_OBJECT, "getDrProvUrl");
}
+ DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+ provApi = p.getProperty( "DR.provApi", "ONAP" );
+ behalfHeader = p.getProperty( "DR.onBehalfHeader", "X-DR-ON-BEHALF-OF");
+ feedContentType = p.getProperty( "DR.feedContentType", "application/vnc.dr.feed");
+ subContentType = p.getProperty( "DR.subContentType", "application/vnd.dr.subscription");
+ logger.info( "provURL=" + provURL + " provApi=" + provApi + " behalfHeader=" + behalfHeader
+ + " feedContentType=" + feedContentType + " subContentType=" + subContentType );
}
try {
logger.info( "uc=" + uc );
uc.setRequestMethod("POST");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
+ uc.setRequestProperty("Content-Type", feedContentType);
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
+ uc.setRequestProperty( behalfHeader, postFeed.getOwner() );
uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
try {
uc.setRequestMethod("POST");
-// uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
+// uc.setRequestProperty("Content-Type", feedContenType );
// uc.setRequestProperty( "charset", "utf-8");
-// uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", postFeed.getOwner() );
+// uc.setRequestProperty( behalfHeader, postFeed.getOwner() );
// uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
// uc.setUseCaches(false);
// uc.setDoOutput(true);
public String doPostDr_Sub( DR_Sub postSub, ApiError err ) {
logger.info( "entry: doPostDr_Sub() " );
- byte[] postData = postSub.getBytes();
+ byte[] postData = postSub.getBytes(provApi );
logger.info( "post fields=" + postData );
String responsemessage = null;
String responseBody = null;
uc.setRequestMethod("POST");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
+ uc.setRequestProperty("Content-Type", subContentType );
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
+ uc.setRequestProperty( behalfHeader, "DGL" );
uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
try {
logger.info( "uc=" + uc );
uc.setRequestMethod("PUT");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
+ uc.setRequestProperty("Content-Type", feedContentType );
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
+ uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
}
public String doPutDr_Sub(DR_Sub postSub, ApiError err) {
logger.info( "entry: doPutDr_Sub() " );
- byte[] postData = postSub.getBytes();
+ byte[] postData = postSub.getBytes(provApi);
logger.info( "post fields=" + postData );
String responsemessage = null;
String responseBody = null;
uc.setRequestMethod("PUT");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
+ uc.setRequestProperty("Content-Type", subContentType );
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
+ uc.setRequestProperty( behalfHeader, "DGL" );
uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
uc.setRequestMethod("GET");
- //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
+ //uc.setRequestProperty("Content-Type", subContentType );
//uc.setRequestProperty( "charset", "utf-8");
- //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
+ //uc.setRequestProperty( behalfHeader, "DGL" );
//uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
//uc.setUseCaches(false);
//uc.setDoOutput(true);
uc.setRequestMethod("PUT");
- //uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
+ //uc.setRequestProperty("Content-Type", subContentType );
//uc.setRequestProperty( "charset", "utf-8");
- //uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
+ //uc.setRequestProperty( behalfHeader, "DGL" );
//uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
//uc.setDoOutput(true);
try {
logger.info( "uc=" + uc );
uc.setRequestMethod("DELETE");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.feed");
+ uc.setRequestProperty("Content-Type", feedContentType );
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", putFeed.getOwner() );
+ uc.setRequestProperty( behalfHeader, putFeed.getOwner() );
//uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
public String doDeleteDr_Sub(DR_Sub delSub, ApiError err) {
logger.info( "entry: doDeleteDr_Sub() " );
- byte[] postData = delSub.getBytes();
+ byte[] postData = delSub.getBytes(provApi);
logger.info( "post fields=" + postData );
String responsemessage = null;
String responseBody = null;
uc.setRequestMethod("DELETE");
- uc.setRequestProperty("Content-Type", "application/vnd.att-dr.subscription");
+ uc.setRequestProperty("Content-Type", subContentType);
uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "X-ATT-DR-ON-BEHALF-OF", "DGL" );
+ uc.setRequestProperty( behalfHeader, "DGL" );
//uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
uc.setUseCaches(false);
uc.setDoOutput(true);
- public byte[] getBytes() {
+ public byte[] getBytes(String provApi) {
+ if ( "AT&T".equals(provApi)) {
+ return toProvJSONforATT().getBytes(StandardCharsets.UTF_8);
+ }
return toProvJSON().getBytes(StandardCharsets.UTF_8);
}
- // returns the DR_Sub object in JSON that conforms to DR Prov Server expectations
- public String toProvJSON() {
+ // returns the DR_Sub object in JSON that conforms to ONAP DR Prov Server expectations
+ public String toProvJSON() {
+ // this is the original DR API that was contributed to ONAP
+ String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": "
+ + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": \"%s\"}"
+ + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s "
+ + "}",
+ this.suspended,
+ this.getDeliveryURL(),
+ this.getUsername(),
+ this.getUserpwd(),
+ this.isUse100(),
+ "false",
+ "0",
+ "true");
+ logger.info( postJSON );
+ return postJSON;
+ }
+ // returns the DR_Sub object in JSON that conforms to AT&T DR Prov Server expectations
+ // In Jan, 2019, the DR API used internally at AT&T diverged, so this function can be used in
+ // that runtime environment
+ public String toProvJSONforATT() {
// in DR 3.0, API v2.1 a new groupid field is added. We are not using this required field so just set it to 0.
// we send this regardless of DR Release because older versions of DR seem to safely ignore it
// and soon those versions won't be around anyway...
// We are setting it to "true" because that is the general behavior desired in OpenDCAE.
// But it is really a no-op for OpenDCAE because we've deployed DR with the SYSTEM-level parameter for FOLLOW_REDIRECTS set to true.
// In the event we abandon that, then setting the sub attribute to true will be a good thing.
+ // Update Jan, 2019: added guaranteed_delivery and guaranteed_sequence with value false for
+ // backwards compatibility
// TODO:
// - introduce Bus Controller API support for these attributes
// - store the default values in the DB
- String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": {\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": \"%s\"}, \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s }",
+ String postJSON = String.format("{\"suspend\": \"%s\", \"delivery\": "
+ + "{\"url\": \"%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\": \"%s\"}"
+ + ", \"metadataOnly\": %s, \"groupid\": \"%s\", \"follow_redirect\": %s "
+ + ", \"guaranteed_delivery\": %s, \"guaranteed_sequence\": %s "
+ + "}",
this.suspended,
this.getDeliveryURL(),
this.getUsername(),
this.isUse100(),
"false",
"0",
- "true");
+ "true",
+ "false",
+ "false");
logger.info( postJSON );
return postJSON;