Commit 0f12ee8c by 龙明普

优化日志

(cherry picked from commit ea746b40)
parent 3b4df289
...@@ -57,11 +57,11 @@ public class AESUtil { ...@@ -57,11 +57,11 @@ public class AESUtil {
String originalString = new String(original,"utf-8"); String originalString = new String(original,"utf-8");
return originalString; return originalString;
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.toString()); System.out.println(e.getMessage());
return null; return null;
} }
} catch (Exception ex) { } catch (Exception ex) {
System.out.println(ex.toString()); System.out.println(ex.getMessage());
return null; return null;
} }
} }
......
...@@ -21,11 +21,11 @@ public class XBMqttDataUtil { ...@@ -21,11 +21,11 @@ public class XBMqttDataUtil {
private MqttClient mqttClient; private MqttClient mqttClient;
private Map<String, String> configParams; private Map<String, String> configParams;
public XBMqttDataUtil( Map<String, String> configParams) { public XBMqttDataUtil(Map<String, String> configParams) {
this.configParams = configParams; this.configParams = configParams;
try { try {
getMqttClient(configParams); getMqttClient(configParams);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -52,7 +52,7 @@ public class XBMqttDataUtil { ...@@ -52,7 +52,7 @@ public class XBMqttDataUtil {
//使用ssl方式连接 //使用ssl方式连接
InputStream crt = null; InputStream crt = null;
if (host.startsWith("ssl")) { if (host.startsWith("ssl")) {
String urlPath=System.getProperty("user.dir")+ "/cacert/cacert.cer"; String urlPath = System.getProperty("user.dir") + "/cacert/cacert.cer";
crt = new FileInputStream(urlPath); crt = new FileInputStream(urlPath);
options.setSocketFactory(new SSL().getSSLSocktet(crt)); options.setSocketFactory(new SSL().getSSLSocktet(crt));
} }
...@@ -79,7 +79,7 @@ public class XBMqttDataUtil { ...@@ -79,7 +79,7 @@ public class XBMqttDataUtil {
try { try {
mqttClient.close(); mqttClient.close();
} catch (MqttException e) { } catch (MqttException e) {
logger.error(e.getMessage()); logger.error("--------close-------->:", e);
} }
} }
...@@ -90,14 +90,14 @@ public class XBMqttDataUtil { ...@@ -90,14 +90,14 @@ public class XBMqttDataUtil {
* @param data * @param data
* @throws Exception * @throws Exception
*/ */
public synchronized void publish( String data) { public synchronized void publish(String data) {
try { try {
if (!mqttClient.isConnected()){ if (!mqttClient.isConnected()) {
getMqttClient(configParams); getMqttClient(configParams);
} }
MqttMessage mqttMessage = new MqttMessage(); MqttMessage mqttMessage = new MqttMessage();
// mqttMessage.setPayload(new Gson().toJson ( data ).getBytes ( "UTF-8" )); // mqttMessage.setPayload(new Gson().toJson ( data ).getBytes ( "UTF-8" ));
mqttMessage.setPayload(data.getBytes( "UTF-8")); mqttMessage.setPayload(data.getBytes("UTF-8"));
// QoS:发布消息的服务质量,即:保证消息传递的次数(消费者收到的次数) // QoS:发布消息的服务质量,即:保证消息传递的次数(消费者收到的次数)
// 0:最多一次,即:<=1;每个消息只发一次,也不会缓存下来。 // 0:最多一次,即:<=1;每个消息只发一次,也不会缓存下来。
// 1:至少一次,即:>=1;一直发送确保消费者至少收到一次,发送失败会缓存下来。 // 1:至少一次,即:>=1;一直发送确保消费者至少收到一次,发送失败会缓存下来。
...@@ -109,13 +109,13 @@ public class XBMqttDataUtil { ...@@ -109,13 +109,13 @@ public class XBMqttDataUtil {
mqttClient.publish(topic, mqttMessage); mqttClient.publish(topic, mqttMessage);
logger.info("MQTT发布主题:" + topic + ":数据成功" + mqttMessage); logger.info("MQTT发布主题:" + topic + ":数据成功" + mqttMessage);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error("--------publish-------->:", e);
} finally { } finally {
try { // try {
mqttClient.close(); // mqttClient.close();
} catch (MqttException e) { // } catch (MqttException e) {
logger.error(e.getMessage()); // logger.error(e.getMessage());
} // }
} }
} }
......
...@@ -101,8 +101,8 @@ public class MqttTCPConn { ...@@ -101,8 +101,8 @@ public class MqttTCPConn {
// } // }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error("--------publish-------->:", e);
e.printStackTrace(); //e.printStackTrace();
return false; return false;
} }
} }
......
...@@ -57,11 +57,11 @@ public class AESUtil { ...@@ -57,11 +57,11 @@ public class AESUtil {
String originalString = new String(original,"utf-8"); String originalString = new String(original,"utf-8");
return originalString; return originalString;
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.toString()); System.out.println(e.getMessage());
return null; return null;
} }
} catch (Exception ex) { } catch (Exception ex) {
System.out.println(ex.toString()); System.out.println(ex.getMessage());
return null; return null;
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论