aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java290
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java34
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java5
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/server/Main.java2
4 files changed, 182 insertions, 149 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
index 51bad4f..6e692fa 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
@@ -36,131 +36,131 @@ import java.net.*;
import java.util.Arrays;
public class MrProvConnection extends BaseLoggingClass{
-
- private String provURL;
-
- private HttpURLConnection uc;
-
-
- private String topicMgrCred;
- private boolean useAAF;
- private String user;
- private String encPwd;
-
- public MrProvConnection() {
- String mechIdProperty = "aaf.TopicMgrUser";
- String pwdProperty = "aaf.TopicMgrPassword";
- DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
- user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
- encPwd = p.getProperty( pwdProperty, "notSet" );
- useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
- topicMgrCred = getCred();
-
- }
-
- private String getCred( ) {
-
-
- String pwd = "";
- AafDecrypt decryptor = new AafDecrypt();
- pwd = decryptor.decrypt(encPwd);
- return user + ":" + pwd;
- }
-
-
- public boolean makeTopicConnection( MR_Cluster cluster ) {
- logger.info( "connect to cluster: " + cluster.getDcaeLocationName());
-
-
- provURL = cluster.getTopicProtocol() + "://" + cluster.getFqdn() + ":" + cluster.getTopicPort() + "/topics/create";
-
- if ( cluster.getTopicProtocol().equals( "https" ) ) {
- return makeSecureConnection( provURL );
- }
- return makeConnection( provURL );
- }
-
- private boolean makeSecureConnection( String pURL ) {
- logger.info( "makeConnection to " + pURL );
-
- try {
- URL u = new URL( pURL );
- uc = (HttpsURLConnection) u.openConnection();
- uc.setInstanceFollowRedirects(false);
- logger.info( "open connect to " + pURL );
- return(true);
- } catch( UnknownHostException uhe ){
- logger.error( "Caught UnknownHostException for " + pURL);
- return(false);
+
+ private String provURL;
+
+ private HttpURLConnection uc;
+
+
+ private String topicMgrCred;
+ private boolean useAAF;
+ private String user;
+ private String encPwd;
+
+ public MrProvConnection() {
+ String mechIdProperty = "aaf.TopicMgrUser";
+ String pwdProperty = "aaf.TopicMgrPassword";
+ DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+ user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
+ encPwd = p.getProperty( pwdProperty, "notSet" );
+ useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
+ topicMgrCred = getCred();
+
+ }
+
+ private String getCred( ) {
+
+
+ String pwd = "";
+ AafDecrypt decryptor = new AafDecrypt();
+ pwd = decryptor.decrypt(encPwd);
+ return user + ":" + pwd;
+ }
+
+
+ public boolean makeTopicConnection( MR_Cluster cluster ) {
+ logger.info( "connect to cluster: " + cluster.getDcaeLocationName());
+
+
+ provURL = cluster.getTopicProtocol() + "://" + cluster.getFqdn() + ":" + cluster.getTopicPort() + "/topics/create";
+
+ if ( cluster.getTopicProtocol().equals( "https" ) ) {
+ return makeSecureConnection( provURL );
+ }
+ return makeConnection( provURL );
+ }
+
+ private boolean makeSecureConnection( String pURL ) {
+ logger.info( "makeConnection to " + pURL );
+
+ try {
+ URL u = new URL( pURL );
+ uc = (HttpsURLConnection) u.openConnection();
+ uc.setInstanceFollowRedirects(false);
+ logger.info( "open connect to " + pURL );
+ return(true);
+ } catch( UnknownHostException uhe ){
+ logger.error( "Caught UnknownHostException for " + pURL);
+ return(false);
} catch (Exception e) {
logger.error("Unexpected error during openConnection of " + pURL );
- e.printStackTrace();
+ logger.error("Unexpected error during openConnection of ",e );
return(false);
}
- }
- private boolean makeConnection( String pURL ) {
- logger.info( "makeConnection to " + pURL );
-
- try {
- URL u = new URL( pURL );
- uc = (HttpURLConnection) u.openConnection();
- uc.setInstanceFollowRedirects(false);
- logger.info( "open connect to " + pURL );
- return(true);
- } catch( UnknownHostException uhe ){
- logger.error( "Caught UnknownHostException for " + pURL);
- return(false);
+ }
+ private boolean makeConnection( String pURL ) {
+ logger.info( "makeConnection to " + pURL );
+
+ try {
+ URL u = new URL( pURL );
+ uc = (HttpURLConnection) u.openConnection();
+ uc.setInstanceFollowRedirects(false);
+ logger.info( "open connect to " + pURL );
+ return(true);
+ } catch( UnknownHostException uhe ){
+ logger.error( "Caught UnknownHostException for " + pURL);
+ return(false);
} catch (Exception e) {
logger.error("Unexpected error during openConnection of " + pURL );
- e.printStackTrace();
+ logger.error("Unexpected error during openConnection of ",e );
return(false);
}
- }
-
- static String bodyToString( InputStream is ) {
- StringBuilder sb = new StringBuilder();
- BufferedReader br = new BufferedReader( new InputStreamReader(is));
- String line;
- try {
- while ((line = br.readLine()) != null ) {
- sb.append( line );
- }
- } catch (IOException ex ) {
- errorLogger.error( "IOexception:" + ex);
- }
-
- return sb.toString();
- }
-
- public String doPostTopic( Topic postTopic, ApiError err ) {
- String auth = "Basic " + Base64.encodeBase64String(topicMgrCred.getBytes());
-
-
- String responsemessage = null;
- int rc = -1;
-
-
- try {
- byte[] postData = postTopic.getBytes();
- logger.info( "post fields=" + Arrays.toString(postData));
-
- // when not using AAF, do not attempt Basic Authentication
- if ( useAAF ) {
- uc.setRequestProperty("Authorization", auth);
- logger.info( "Authenticating with " + auth );
- }
- uc.setRequestMethod("POST");
- uc.setRequestProperty("Content-Type", "application/json");
- uc.setRequestProperty( "charset", "utf-8");
- uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
- uc.setUseCaches(false);
- uc.setDoOutput(true);
- OutputStream os = null;
-
-
- try {
+ }
+
+ static String bodyToString( InputStream is ) {
+ StringBuilder sb = new StringBuilder();
+ BufferedReader br = new BufferedReader( new InputStreamReader(is));
+ String line;
+ try {
+ while ((line = br.readLine()) != null ) {
+ sb.append( line );
+ }
+ } catch (IOException ex ) {
+ errorLogger.error( "IOexception:" + ex);
+ }
+
+ return sb.toString();
+ }
+
+ public String doPostTopic( Topic postTopic, ApiError err ) {
+ String auth = "Basic " + Base64.encodeBase64String(topicMgrCred.getBytes());
+
+
+ String responsemessage = null;
+ int rc = -1;
+
+
+ try {
+ byte[] postData = postTopic.getBytes();
+ logger.info( "post fields=" + Arrays.toString(postData));
+
+ // when not using AAF, do not attempt Basic Authentication
+ if ( useAAF ) {
+ uc.setRequestProperty("Authorization", auth);
+ logger.info( "Authenticating with " + auth );
+ }
+ uc.setRequestMethod("POST");
+ uc.setRequestProperty("Content-Type", "application/json");
+ uc.setRequestProperty( "charset", "utf-8");
+ uc.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
+ uc.setUseCaches(false);
+ uc.setDoOutput(true);
+ OutputStream os = null;
+
+
+ try {
uc.connect();
os = uc.getOutputStream();
os.write( postData );
@@ -174,21 +174,21 @@ public class MrProvConnection extends BaseLoggingClass{
} catch (Exception e) {
}
} catch ( UnknownHostException uhe ) {
- errorLogger.error( DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION , "Unknown Host Exception" , provURL );
- err.setCode(500);
- err.setMessage("Unknown Host Exception");
- err.setFields( uc.getURL().getHost());
- return new String( "500: " + uhe.getMessage());
+ errorLogger.error( DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION , "Unknown Host Exception" , provURL );
+ err.setCode(500);
+ err.setMessage("Unknown Host Exception");
+ err.setFields( uc.getURL().getHost());
+ return new String( "500: " + uhe.getMessage());
}catch ( ConnectException ce ) {
- errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, "HTTP Connection Exception" );
- err.setCode(500);
- err.setMessage("HTTP Connection Exception");
- err.setFields( uc.getURL().getHost());
- return new String( "500: " + ce.getMessage());
+ errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, "HTTP Connection Exception" );
+ err.setCode(500);
+ err.setMessage("HTTP Connection Exception");
+ err.setFields( uc.getURL().getHost());
+ return new String( "500: " + ce.getMessage());
}
- rc = uc.getResponseCode();
- logger.info( "http response code:" + rc );
- err.setCode(rc);
+ rc = uc.getResponseCode();
+ logger.info( "http response code:" + rc );
+ err.setCode(rc);
responsemessage = uc.getResponseMessage();
logger.info( "responsemessage=" + responsemessage );
err.setMessage(responsemessage);
@@ -207,29 +207,29 @@ public class MrProvConnection extends BaseLoggingClass{
}
}
if (rc >= 200 && rc < 300 ) {
- String responseBody = null;
- responseBody = bodyToString( uc.getInputStream() );
- logger.info( "responseBody=" + responseBody );
- return responseBody;
+ String responseBody = null;
+ responseBody = bodyToString( uc.getInputStream() );
+ logger.info( "responseBody=" + responseBody );
+ return responseBody;
}
- } catch (Exception e) {
- errorLogger.error("Unable to read response " );
+ } catch (Exception e) {
+ errorLogger.error("Unable to read response " );
}
- finally {
- try {
- uc.disconnect();
- } catch ( Exception e ) {
- errorLogger.error("Unable to disconnect");
- }
- }
- return new String( rc +": " + responsemessage );
+ finally {
+ try {
+ uc.disconnect();
+ } catch ( Exception e ) {
+ errorLogger.error("Unable to disconnect");
+ }
+ }
+ return new String( rc +": " + responsemessage );
- }
-
+ }
+
-
+
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
index 0d146b7..4e64089 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
@@ -24,6 +24,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.onap.dmaap.dbcapi.util.RandomString;
+import java.util.Objects;
+
@XmlRootElement
public class DR_Pub extends DmaapObject {
@@ -151,5 +153,35 @@ public class DR_Pub extends DmaapObject {
return ri.nextString();
}
-
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ DR_Pub dr_pub = (DR_Pub) o;
+ return Objects.equals(dcaeLocationName, dr_pub.dcaeLocationName) &&
+ Objects.equals(username, dr_pub.username) &&
+ Objects.equals(userpwd, dr_pub.userpwd) &&
+ Objects.equals(feedId, dr_pub.feedId) &&
+ Objects.equals(pubId, dr_pub.pubId);
+ }
+
+ @Override
+ public int hashCode() {
+
+ return Objects.hash(dcaeLocationName, username, userpwd, feedId, pubId);
+ }
+
+ @Override
+ public String toString() {
+ return "DR_Pub{" +
+ "dcaeLocationName='" + dcaeLocationName + '\'' +
+ ", username='" + username + '\'' +
+ ", userpwd='" + userpwd + '\'' +
+ ", feedId='" + feedId + '\'' +
+ ", pubId='" + pubId + '\'' +
+ ", feedName='" + feedName + '\'' +
+ ", feedVersion='" + feedVersion + '\'' +
+ '}';
+ }
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
index 928a7e2..6e652a8 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
@@ -104,8 +104,9 @@ public class DR_PubResource extends BaseLoggingClass {
}
// if we found a FeedName instead of a FeedId then try to look it up.
List<Feed> nfeeds = feeds.getAllFeeds( pub.getFeedName(), pub.getFeedVersion(), "equals");
- if ( nfeeds.size() != 1 ) {
- logger.debug( "Attempt to match "+ pub.getFeedName() + " ver="+pub.getFeedVersion() + " matched " + nfeeds.size() );
+ if ( nfeeds.isEmpty() ) {
+ apiError.setCode(Status.NOT_FOUND.getStatusCode());
+ apiError.setFields("feedName");
return responseBuilder.error(apiError);
}
fnew = nfeeds.get(0);
diff --git a/src/main/java/org/onap/dmaap/dbcapi/server/Main.java b/src/main/java/org/onap/dmaap/dbcapi/server/Main.java
index d8ee278..906337a 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/server/Main.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/server/Main.java
@@ -62,7 +62,7 @@ public class Main extends BaseLoggingClass {
MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
- e.printStackTrace();
+ errorLogger.error("Error while getting hostname or address", e);
}
MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
MDC.put(MDC_ALERT_SEVERITY, "0");