<artifactId>dmaapClient</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
- <name>dmaapClient</name>
+ <name>dmaap-messagerouter-dmaapclient</name>
<description>Client library for MR event routing API</description>
<url>https://github.com/att/dmaap-framework</url>
protected MRBaseClient ( Collection<String> hosts ) throws MalformedURLException
{
super ( ConnectionType.HTTP, hosts, MRConstants.kStdMRServicePort );
+
+ fLog = LoggerFactory.getLogger ( this.getClass().getName () );
}
protected MRBaseClient ( Collection<String> hosts, int stdSvcPort ) throws MalformedURLException {
import java.io.InputStream;
import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class MRClientVersionInfo
{
+ private static final Logger logger = LoggerFactory.getLogger(MRClientVersionInfo.class);
public static String getVersion ()
{
return version;
}
catch ( IOException e )
{
+ logger.error("exception: ", e);
}
version = use;
}
private static final String SUCCESS_MESSAGE = "Success";
- private Logger fLog = LoggerFactory.getLogger ( this.getClass().getName () );
+ private Logger log = LoggerFactory.getLogger ( this.getClass().getName () );
public static List<String> stringToList ( String str )
{
final LinkedList<String> set = new LinkedList<String> ();
{
// unexpected response
reportProblemWithResponse ();
+ log.error("exception: ", e);
}
catch ( HttpException e )
{
{
// unexpected response
reportProblemWithResponse ();
+ log.error("exception: ", e);
}
catch ( HttpException e )
{
{
// unexpected response
reportProblemWithResponse ();
+ log.error("exception: ", e);
}
catch ( HttpException e )
{
} catch ( JSONException e ) {
// unexpected response
reportProblemWithResponse ();
+ log.error("exception: ", e);
} catch (HttpException e) {
throw new IOException(e);
} catch (Exception e ) {
try {
- //fLog.info("DMAAP response status: " + response.getStatus());
+ //log.info("DMAAP response status: " + response.getStatus());
// final String responseData = response.readEntity(String.class);
JSONTokener jsonTokener = new JSONTokener(response);
return jsonObject;
} catch (JSONException excp) {
- // fLog.error("DMAAP - Error reading response data.", excp);
+ // log.error("DMAAP - Error reading response data.", excp);
return null;
}
private Properties props;
private HashMap<String, String> DMETimeOuts;
private String handlers;
- public static String routerFilePath;
+ public static final String routerFilePath = null;
public static String getRouterFilePath() {
return routerFilePath;
}
url = protocol + "://"+serviceName+"?version="+version+"&envContext="+env+"&routeoffer="+routeOffer;
}
- //fLog.info("url :"+url);
+ //log.info("url :"+url);
if(timeoutMs != -1 )url=url+"&timeout="+timeoutMs;
if(limit != -1 )url=url+"&limit="+limit;
MRClientFactory.prop.load(new FileReader(new File (MRClientFactory.routeFilePath)));
} catch (Exception ex) {
- fLog.error("Reply Router Error " + ex.toString() );
+ log.error("Reply Router Error " + ex.toString() );
}
String routeOffer = MRClientFactory.prop.getProperty(routeKey);
return routeOffer;
} catch (JSONException e) {
mrConsumerResponse.setResponseMessage(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
mrConsumerResponse.setResponseMessage(e.getMessage());
+ log.error("json exception: ", e);
} catch (HttpException e) {
mrConsumerResponse.setResponseMessage(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
mrConsumerResponse.setResponseMessage(e.getMessage());
+ log.error("http exception: ", e);
}catch(DME2Exception e){
mrConsumerResponse.setResponseCode(e.getErrorCode());
mrConsumerResponse.setResponseMessage(e.getErrorMessage());
+ log.error("DME2 exception: ", e);
}catch (Exception e) {
mrConsumerResponse.setResponseMessage(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
mrConsumerResponse.setResponseMessage(e.getMessage());
+ log.error("exception: ", e);
}
mrConsumerResponse.setActualMessages(msgs);
return mrConsumerResponse;
*/
CAMBRIA
{
+ @Override
public String toString() { return "application/cambria"; }
},
*/
CAMBRIA_ZIP
{
+ @Override
public String toString() { return "application/cambria-zip"; }
},
*/
JSON
{
+ @Override
public String toString() { return "application/json"; }
}
}
import org.json.JSONException;
import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.apiClient.credentials.ApiCredential;
import com.att.nsa.apiClient.http.HttpException;
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
public class MRMetaClient extends MRBaseClient implements MRTopicManager, MRIdentityManager
{
+ private static final Logger logger = LoggerFactory.getLogger(MRMetaClient.class);
public MRMetaClient ( Collection<String> baseUrls ) throws MalformedURLException
{
super ( baseUrls );
catch ( HttpObjectNotFoundException e )
{
getLog().warn ( "No /topics endpoint on service." );
+ logger.error("HttpObjectNotFoundException: ", e);
}
catch ( JSONException e )
{
getLog().warn ( "Bad /topics result from service." );
+ logger.error("JSONException: ", e);
}
catch ( HttpException e )
{
import javax.ws.rs.core.MultivaluedMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.http.HttpException;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingPublisher
{
+ private static final Logger logger = LoggerFactory.getLogger(MRSimplerBatchPublisher.class);
+
public static class Builder
{
public Builder ()
pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
pubResponse.setResponseMessage(x.getMessage());
+ logger.error("exception: ", x);
}
private String handlers;
private Properties props;
public static String routerFilePath;
- public static Map<String, String> headers=new HashMap<String, String>();
+ protected static final Map<String, String> headers=new HashMap<String, String>();
public static MultivaluedMap<String, Object> headersMap;
this.pendingMsgs = pendingMsgs;
}
+ @Override
public String toString() {
return "Response Code:" + this.responseCode + ","
+ "Response Message:" + this.responseMessage + "," + "Pending Messages Count"
//import com.att.aft.dme2.api.util.LogMessage;
//import com.att.aft.dme2.api.util.LogUtil;
public class DefaultLoggingFailoverFaultHandler /*implements DME2FailoverFaultHandler*/ {
+ //TODO: This code may be enable in the future when we implement DME2FailoverFaultHandler interface
/** The logger. */
//private static Logger logger = DME2Constants.getLogger(DefaultLoggingFailoverFaultHandler.class.getName());
// //noop
//
// }
-}
\ No newline at end of file
+}
+
import com.att.nsa.mr.client.MRClientFactory;
public class PreferredRouteRequestHandler implements DME2ExchangeRequestHandler {
- private Logger fLog = LoggerFactory.getLogger(this.getClass().getName());
+ private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Override
public void handleRequest(DME2ExchangeRequestContext requestData) {
MRClientFactory.prop.load(MRClientFactory.routeReader);
} catch (Exception ex) {
- fLog.error("Request Router Error " + ex.toString());
+ logger.error("Request Router Error " + ex.toString());
}
return MRClientFactory.prop.getProperty(routeKey);
}
import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.ws.rs.core.MultivaluedMap;
import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.MRConsumer;
+import java.util.List;
+
public class SimpleExampleConsumer {
+ private static final Logger logger = LoggerFactory.getLogger(SimpleExampleConsumer.class);
+
+ private SimpleExampleConsumer() {
+ }
+
public static void main(String[] args) {
long count = 0;
long nextReport = 5000;
+ String key;
final long startMs = System.currentTimeMillis();
final MRConsumer cc = MRClientFactory.createConsumer("D:\\SG\\consumer.properties");
while (true) {
for (String msg : cc.fetch()) {
-
- System.out.println("Message Received: " + msg);
+ logger.debug("Message Received: " + msg);
}
// Header for DME2 Call.
MultivaluedMap<String, Object> headersMap = MRClientFactory.HTTPHeadersMap;
- for (String key : headersMap.keySet()) {
- System.out.println("Header Key " + key);
- System.out.println("Header Value " + headersMap.get(key));
+ for (MultivaluedMap.Entry<String,List<Object>> entry: headersMap.entrySet()) {
+ key = entry.getKey();
+ logger.debug("Header Key " + key);
+ logger.debug("Header Value " + headersMap.get(key));
}
// Header for HTTP Call.
- Map<String, String>
- dme2headersMap=MRClientFactory.DME2HeadersMap; for(String key
- : dme2headersMap.keySet()) { System.out.println("Header Key "
- + key); System.out.println("Header Value " +
- dme2headersMap.get(key)); }
+ Map<String, String> dme2headersMap=MRClientFactory.DME2HeadersMap;
+ for(Map.Entry<String,String> entry: dme2headersMap.entrySet()) {
+ key = entry.getKey();
+ logger.debug("Header Key " + key);
+ logger.debug("Header Value " + dme2headersMap.get(key));
+ }
if (count > nextReport) {
nextReport += 5000;
final long elapsedMs = endMs - startMs;
final double elapsedSec = elapsedMs / 1000.0;
final double eps = count / elapsedSec;
- System.out.println("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps");
+ logger.error("Consumed " + count + " in " + elapsedSec + "; " + eps + " eps");
}
}
} catch (Exception x) {
- System.err.println(x.getClass().getName() + ": " + x.getMessage());
+ logger.error(x.getClass().getName() + ": " + x.getMessage());
}
}
}
import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.spi.LoggingEvent;
import com.att.nsa.mr.client.MRClientFactory;
*/
public class MRAppender extends AppenderSkeleton {
+ private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
+
private MRPublisher fPublisher;
//Provided through log4j configuration
try {
fPublisher.send(partition, message);
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("IOException: ", e);
}
}
+ @Override
public void activateOptions() {
if (hosts != null && topic != null && partition != null) {
fPublisher = MRClientFactory.createBatchingPublisher(hosts.split(","), topic, maxBatchSize, maxAgeMs, compress);
} else {
- LogLog.error("The Hosts, Topic, and Partition parameter are required to create a MR Log4J Appender");
+ logger.error("The Hosts, Topic, and Partition parameter are required to create a MR Log4J Appender");
}
}
public String getTopic() {
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.mr.client.MRBatchingPublisher;
import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.MRPublisher.message;
*/
public class ConsolePublisher
{
+
+ private static final Logger logger = LoggerFactory.getLogger(ConsolePublisher.class);
+ private ConsolePublisher() {
+ }
public static void main ( String[] args ) throws IOException //throws IOException, InterruptedException
{
// read the hosts(s) from the command line
- final String hosts = ( args.length > 0 ? args[0] : "aaa.it.att.com,bbb.it.att.com,ccc.it.att.com" );
+ final String hosts = args.length > 0 ? args[0] : "aaa.it.att.com,bbb.it.att.com,ccc.it.att.com";
// read the topic name from the command line
- final String topic = ( args.length > 1 ? args[1] : "TEST-TOPIC" );
+ final String topic = args.length > 1 ? args[1] : "TEST-TOPIC";
// read the topic name from the command line
- final String partition = ( args.length > 2 ? args[2] : UUID.randomUUID ().toString () );
+ final String partition = args.length > 2 ? args[2] : UUID.randomUUID ().toString ();
// set up some batch limits and the compression flag
final int maxBatchSize = 100;
}
catch ( InterruptedException e )
{
- System.err.println ( "Send on close interrupted." );
+ logger.error( "Send on close interrupted." );
}
for ( message m : leftovers )
{
- System.err.println ( "Unsent message: " + m.fMsg );
+ logger.error( "Unsent message: " + m.fMsg );
}
}
}
*******************************************************************************/
package com.att.nsa.mr.test.clients;
-import java.io.IOException;
import java.util.LinkedList;
import org.slf4j.Logger;
import com.att.nsa.mr.client.MRConsumer;
public class SampleConsumer {
+ private SampleConsumer() {
+ }
public static void main ( String[] args )
{
- final Logger LOG = LoggerFactory.getLogger(SampleConsumer.class);
+ final Logger log = LoggerFactory.getLogger(SampleConsumer.class);
- LOG.info("Sample Consumer Class executing");
+ log.info("Sample Consumer Class executing");
final String topic = "com.att.app.dmaap.mr.testingTopic";
final String url = ( args.length > 1 ? args[1] : "localhost:8181" );
final String group = ( args.length > 2 ? args[2] :"grp" );
{
for ( String msg : cc.fetch () )
{
- //System.out.println ( "" + (++count) + ": " + msg );
- LOG.info ( "" + (++count) + ": " + msg );
+ log.info ( "" + (++count) + ": " + msg );
}
if ( count > nextReport )
final long elapsedMs = endMs - startMs;
final double elapsedSec = elapsedMs / 1000.0;
final double eps = count / elapsedSec;
- //System.out.println ( "Consumed " + count + " in " + elapsedSec + "; " + eps + " eps" );
- LOG.info ( "Consumed " + count + " in " + elapsedSec + "; " + eps + " eps" );
+ log.info ( "Consumed " + count + " in " + elapsedSec + "; " + eps + " eps" );
}
- LOG.info ( "" + (++count) + ": consumed message" );
+ log.info ( "" + (++count) + ": consumed message" );
}
}
catch ( Exception x )
{
- System.err.println ( x.getClass().getName () + ": " + x.getMessage () );
+ log.error( x.getClass().getName () + ": " + x.getMessage () );
}
}
}
package com.att.nsa.mr.test.clients;
-
-
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.MRConsumer;
static FileReader routeReader=null;
public static void main ( String[] args )
{
+ final Logger LOG = LoggerFactory.getLogger(SimpleExampleConsumer.class);
long count = 0;
long nextReport = 5000;
catch ( Exception x )
{
System.err.println ( x.getClass().getName () + ": " + x.getMessage () );
+ LOG.error("exception: ", x);
}
}
}
import java.io.FileWriter;
import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.MRConsumer;
import com.att.nsa.mr.client.response.MRConsumerResponse;
public class SimpleExampleConsumerWithReturnResponse {
+ private static final Logger LOG = LoggerFactory.getLogger(SimpleExampleConsumerWithReturnResponse.class);
static FileWriter routeWriter= null;
static Properties props=null;
catch ( Exception x )
{
System.err.println ( x.getClass().getName () + ": " + x.getMessage () );
+ LOG.error("exception: ", x);
}
}
import java.io.IOException;
import java.io.PrintStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.apiClient.credentials.ApiCredential;
import com.att.nsa.apiClient.http.HttpException;
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
public class ApiKeyCommand implements Command<MRCommandContext>
{
-
+ final Logger log = LoggerFactory.getLogger(ApiKeyCommand.class);
@Override
public String[] getMatches ()
{
catch ( HttpObjectNotFoundException e )
{
out.println ( "Object not found: " + e.getMessage () );
+ log.error("HttpObjectNotFoundException: ", e);
}
catch ( HttpException e )
{
out.println ( "HTTP exception: " + e.getMessage () );
+ log.error("HttpException: ", e);
}
catch ( MRApiException e )
{
out.println ( "API exception: " + e.getMessage () );
+ log.error("MRApiException: ", e);
}
catch ( IOException e )
{
out.println ( "IO exception: " + e.getMessage () );
+ log.error("IOException: ", e);
}
finally
{
import java.util.List;
import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.cmdtool.Command;
import com.att.nsa.cmdtool.CommandNotReadyException;
import com.att.nsa.mr.client.MRBatchingPublisher;
public class MessageCommand implements Command<MRCommandContext>
{
-
+ final Logger logger = LoggerFactory.getLogger(ApiKeyCommand.class);
@Override
public String[] getMatches ()
{
catch ( Exception e )
{
out.println ( "Problem fetching messages: " + e.getMessage() );
+ logger.error("Problem fetching messages: ", e);
}
finally
{
catch ( IOException e )
{
out.println ( "Problem sending message: " + e.getMessage() );
+ logger.error("Problem sending message: ", e);
}
finally
{
catch ( IOException e )
{
out.println ( "Problem sending message: " + e.getMessage() );
+ logger.error("Problem sending message: ", e);
}
catch ( InterruptedException e )
{
out.println ( "Problem sending message: " + e.getMessage() );
+ logger.error("Problem sending message: ", e);
}
if ( left != null && left.size () > 0 )
{
import java.io.PrintStream;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.apiClient.http.HttpException;
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
import com.att.nsa.cmdtool.Command;
public class TopicCommand implements Command<MRCommandContext>
{
-
+ final Logger logger = LoggerFactory.getLogger(ApiKeyCommand.class);
@Override
public String[] getMatches ()
{
catch ( IOException x )
{
out.println ( "Problem with request: " + x.getMessage () );
+ logger.error("IOException: ", x);
}
catch ( HttpObjectNotFoundException e )
{
out.println ( "Not found: " + e.getMessage () );
+ logger.error("HttpObjectNotFoundException: ", e);
}
}
else if ( parts[0].equals ( "create" ) )
catch ( HttpException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("HttpException: ", e);
}
catch ( IOException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("IOException: ", e);
}
catch ( NumberFormatException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("NumberFormatException: ", e);
}
}
else if ( parts[0].equals ( "grant" ) )
catch ( HttpException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("HttpException: ", e);
}
catch ( IOException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("IOException: ", e);
}
}
else if ( parts[0].equals ( "revoke" ) )
catch ( HttpException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("HttpException: ", e);
}
catch ( IOException e )
{
out.println ( "Problem with request: " + e.getMessage () );
+ logger.error("IOException: ", e);
}
}
}