├── yunba-java-sdk.jar ├── libs ├── guava-17.0.jar └── jettison-1.1.jar ├── src ├── org │ └── eclipse │ │ └── paho │ │ └── client │ │ └── mqttv3 │ │ ├── util │ │ ├── package.html │ │ └── Debug.java │ │ ├── persist │ │ ├── package.html │ │ └── MemoryPersistence.java │ │ ├── internal │ │ ├── ClientDefaults.java │ │ ├── wire │ │ │ ├── MqttAck.java │ │ │ ├── MqttReceivedMessage.java │ │ │ ├── MultiByteInteger.java │ │ │ ├── MqttPingResp.java │ │ │ ├── MqttPingReq.java │ │ │ ├── MqttUnsubAck.java │ │ │ ├── MqttDisconnect.java │ │ │ ├── MqttPubAck.java │ │ │ ├── MqttPubRec.java │ │ │ ├── MqttPubComp.java │ │ │ ├── CountingInputStream.java │ │ │ ├── MultiByteArrayInputStream.java │ │ │ ├── MqttSuback.java │ │ │ ├── MqttConnack.java │ │ │ ├── MqttPubRel.java │ │ │ ├── MqttOutputStream.java │ │ │ ├── MqttPersistableWireMessage.java │ │ │ ├── MqttUnsubscribe.java │ │ │ ├── MqttInputStream.java │ │ │ ├── MqttExpandAck.java │ │ │ ├── MqttSubscribe.java │ │ │ ├── MqttExpand.java │ │ │ ├── MqttConnect.java │ │ │ ├── MqttExpandPublish.java │ │ │ └── MqttPublish.java │ │ ├── NetworkModule.java │ │ ├── DestinationProvider.java │ │ ├── ResourceBundleCatalog.java │ │ ├── nls │ │ │ ├── messages.properties │ │ │ ├── messages_it.properties │ │ │ ├── messages_fr.properties │ │ │ ├── messages_de.properties │ │ │ ├── messages_es.properties │ │ │ ├── messages_pt_BR.properties │ │ │ ├── messages_cs.properties │ │ │ ├── messages_zh_CN.properties │ │ │ ├── messages_pl.properties │ │ │ ├── messages_zh_TW.properties │ │ │ ├── messages_hu.properties │ │ │ ├── messages_ko.properties │ │ │ ├── messages_ja.properties │ │ │ ├── messages_ru.properties │ │ │ ├── logcat.properties │ │ │ ├── logcat_it.properties │ │ │ ├── logcat_pt_BR.properties │ │ │ ├── logcat_es.properties │ │ │ ├── logcat_fr.properties │ │ │ └── logcat_de.properties │ │ ├── MessageCatalog.java │ │ ├── ExceptionHelper.java │ │ ├── MqttPersistentData.java │ │ ├── SSLNetworkModule.java │ │ ├── FileLock.java │ │ ├── LocalNetworkModule.java │ │ ├── security │ │ │ └── SimpleBase64Encoder.java │ │ ├── TCPNetworkModule.java │ │ └── CommsSender.java │ │ ├── logging │ │ ├── package.html │ │ ├── SimpleLogFormatter.java │ │ ├── jsr47min.properties │ │ ├── MLogger.java │ │ └── LoggerFactory.java │ │ ├── IMqttActionListener.java │ │ ├── MqttDeliveryToken.java │ │ ├── MqttSecurityException.java │ │ ├── IMqttDeliveryToken.java │ │ ├── MqttPersistenceException.java │ │ ├── MqttToken.java │ │ ├── MqttCallback.java │ │ ├── MqttTopic.java │ │ ├── MqttPersistable.java │ │ ├── MqttClientPersistence.java │ │ └── IMqttToken.java └── io │ └── yunba │ └── java │ ├── core │ ├── event │ │ ├── IEvent.java │ │ └── MessageArrivedEvent.java │ ├── Constants.java │ ├── MessageDelivery.java │ ├── EventBusMessageDelivery.java │ └── MQTTMessage.java │ └── util │ └── CommonUtil.java ├── .gitignore ├── README.md └── .project /yunba-java-sdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunba/yunba-java-sdk/HEAD/yunba-java-sdk.jar -------------------------------------------------------------------------------- /libs/guava-17.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunba/yunba-java-sdk/HEAD/libs/guava-17.0.jar -------------------------------------------------------------------------------- /libs/jettison-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yunba/yunba-java-sdk/HEAD/libs/jettison-1.1.jar -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/util/package.html: -------------------------------------------------------------------------------- 1 |
2 | Provides helpers and utilities. 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/io/yunba/java/core/event/IEvent.java: -------------------------------------------------------------------------------- 1 | package io.yunba.java.core.event; 2 | 3 | public interface IEvent { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /dist 3 | /bin 4 | /bin1 5 | /.settings 6 | .classpath 7 | .DS_Store 8 | .opts 9 | src/org/eclipse/paho/util/YunBaDemo.javA 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 官方声明 2 | 3 | Java SDK 目前正在重构,此为第一版,用户可以试用自行下载试用,java sdk 的接口与 android 保持一致([android sdk API](https://yunba.io/docs/android_sdk_api_manual)) 4 | 5 | 对于自行修改 sdk 而导致的问题,云巴恕不提供技术支持。如果对于 sdk 有个性化需求,可以联系商务定制开发:xieting@yunba.io 6 | -------------------------------------------------------------------------------- /src/io/yunba/java/core/Constants.java: -------------------------------------------------------------------------------- 1 | package io.yunba.java.core; 2 | 3 | 4 | public interface Constants { 5 | 6 | public static final String UTF_8 = "UTF-8"; 7 | public static final String TOPIC_SET_ALIAS = ",yali"; 8 | public static final String TOPIC_GET_ALIAS = ",yaliget"; 9 | } 10 | -------------------------------------------------------------------------------- /src/io/yunba/java/core/MessageDelivery.java: -------------------------------------------------------------------------------- 1 | package io.yunba.java.core; 2 | 3 | public interface MessageDelivery { 4 | 5 | public void postReceivedMessage(String topic, String entity); 6 | 7 | public void postReceivedPresence(String topic, String presence); 8 | 9 | public void postConnected(); 10 | 11 | public void postDisConnected(); 12 | } 13 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 |5 | An MQTT client needs a persistence mechanism to store messages while they 6 | are in the process of being delivered. This package contains several 7 | implementations of the interface. If a persistence class is not 8 | specified on the constructor to an MQTT client, 9 | {@link org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence MqttDefaultFilePersistence} 10 | is used by default. 11 | 12 | -------------------------------------------------------------------------------- /src/io/yunba/java/core/event/MessageArrivedEvent.java: -------------------------------------------------------------------------------- 1 | package io.yunba.java.core.event; 2 | 3 | public class MessageArrivedEvent implements IEvent{ 4 | private String mAction; 5 | private String mTopic; 6 | private String mMsg; 7 | 8 | public MessageArrivedEvent(String action, String topic, String msg) { 9 | this.mAction = action; 10 | this.mTopic = topic; 11 | this.mMsg = msg; 12 | } 13 | 14 | public String getAction() { 15 | return mAction; 16 | } 17 | 18 | public String getTopic() { 19 | return mTopic; 20 | } 21 | 22 | public String getMessage() { 23 | return mMsg; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/ClientDefaults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal; 13 | 14 | public class ClientDefaults { 15 | public static final int MAX_MSG_SIZE = 1024 * 1024 * 256; // 256 MB 16 | } 17 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/wire/MqttAck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal.wire; 13 | 14 | 15 | /** 16 | * Abstract super-class of all acknowledgement messages. 17 | */ 18 | public abstract class MqttAck extends MqttWireMessage { 19 | public MqttAck(byte type) { 20 | super(type); 21 | } 22 | 23 | protected byte getMessageInfo() { 24 | return 0; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/NetworkModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.io.OutputStream; 17 | 18 | import org.eclipse.paho.client.mqttv3.MqttException; 19 | 20 | 21 | public interface NetworkModule { 22 | public void start() throws IOException, MqttException; 23 | 24 | public InputStream getInputStream() throws IOException; 25 | 26 | public OutputStream getOutputStream() throws IOException; 27 | 28 | public void stop() throws IOException; 29 | } 30 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/DestinationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal; 13 | 14 | import org.eclipse.paho.client.mqttv3.MqttTopic; 15 | 16 | /** 17 | * This interface exists to act as a common type for 18 | * MqttClient and MqttMIDPClient so they can be passed to 19 | * ClientComms without either client class need to know 20 | * about the other. 21 | * Specifically, this allows the MIDP client to work 22 | * without the non-MIDP MqttClient/MqttConnectOptions 23 | * classes being present. 24 | */ 25 | public interface DestinationProvider { 26 | public MqttTopic getTopic(String topic); 27 | } 28 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/logging/package.html: -------------------------------------------------------------------------------- 1 |
2 | Provides facilities to write and format log and trace to help debug problems. 3 | 4 |The default log and trace facility uses Java's build in log facility:- 5 | java.util.logging. For systems where this is not available or where 6 | an alternative logging framework is required the logging facility can be 7 | replaced using {@link org.eclipse.paho.client.mqttv3.logging.LoggerFactory#setLogger(String)} 8 | which takes an implementation of the {@link org.eclipse.paho.client.mqttv3.logging.Logger} 9 | interface. 10 | 11 |
A sample java.util.logging properties file - jsr47min.properties is provided that demonstrates
12 | how to run with a memory based trace facility that runs with minimal performance
13 | overhead. The memory buffer can be dumped when a log/trace record is written matching
14 | the MemoryHandlers trigger level or when the push method is invoked on the MemoryHandler.
15 | {@link org.eclipse.paho.client.mqttv3.util.Debug Debug} provides method to make it easy
16 | to dump the memory buffer as well as other useful debug info.
17 |
18 |
--------------------------------------------------------------------------------
/src/io/yunba/java/core/EventBusMessageDelivery.java:
--------------------------------------------------------------------------------
1 | package io.yunba.java.core;
2 |
3 | import io.yunba.java.core.event.MessageArrivedEvent;
4 | import io.yunba.java.manager.YunBaManager;
5 |
6 | public class EventBusMessageDelivery implements MessageDelivery {
7 |
8 | @Override
9 | public void postReceivedMessage(String topic, String entity) {
10 | YunBaManager.getEventBus().post(
11 | new MessageArrivedEvent(YunBaManager.MESSAGE_RECEIVED_ACTION,
12 | topic, entity));
13 | }
14 |
15 | @Override
16 | public void postReceivedPresence(String topic, String presence) {
17 | YunBaManager.getEventBus().post(
18 | new MessageArrivedEvent(YunBaManager.PRESENCE_RECEIVED_ACTION,
19 | topic, presence));
20 | }
21 |
22 | @Override
23 | public void postConnected() {
24 | YunBaManager.getEventBus().post(
25 | new MessageArrivedEvent(YunBaManager.MESSAGE_CONNECTED_ACTION,
26 | null, null));
27 | }
28 |
29 | @Override
30 | public void postDisConnected() {
31 | YunBaManager.getEventBus().post(
32 | new MessageArrivedEvent(YunBaManager.MESSAGE_DISCONNECTED_ACTION,
33 | null, null));
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/ResourceBundleCatalog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal;
13 |
14 | import java.util.MissingResourceException;
15 | import java.util.ResourceBundle;
16 |
17 | public class ResourceBundleCatalog extends MessageCatalog {
18 |
19 | private ResourceBundle bundle;
20 |
21 | public ResourceBundleCatalog() throws Exception {
22 | bundle = ResourceBundle.getBundle("org.eclipse.paho.client.mqttv3.internal.nls.messages");
23 | }
24 |
25 | protected String getLocalizedMessage(int id) {
26 | try {
27 | return bundle.getString(Integer.toString(id));
28 | } catch(Exception mre) {
29 | return "MqttException";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttReceivedMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttMessage;
15 |
16 | public class MqttReceivedMessage extends MqttMessage {
17 |
18 | //****************set msgId to long, by Quentin**//
19 | private long messageId;
20 | //****************set msgId to long, by Quentin**//
21 | public void setMessageId(long msgId) {
22 | this.messageId = msgId;
23 | }
24 |
25 | //****************set msgId to long, by Quentin**//
26 | public long getMessageId() {
27 | return messageId;
28 | }
29 |
30 | // This method exists here to get around the protected visibility of the
31 | // super class method.
32 | public void setDuplicate(boolean value) {
33 | super.setDuplicate(value);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MultiByteInteger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | /**
15 | * Represents a Multi-Byte Integer (MBI), as defined by the MQTT V3
16 | * specification.
17 | */
18 | public class MultiByteInteger {
19 | private long value;
20 | private int length;
21 |
22 | public MultiByteInteger(long value) {
23 | this(value, -1);
24 | }
25 |
26 | public MultiByteInteger(long value, int length) {
27 | this.value = value;
28 | this.length = length;
29 | }
30 |
31 | /**
32 | * Returns the number of bytes read when decoding this MBI.
33 | */
34 | public int getEncodedLength() {
35 | return length;
36 | }
37 |
38 | /**
39 | * Returns the value of this MBI.
40 | */
41 | public long getValue() {
42 | return value;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingResp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttException;
15 |
16 |
17 | /**
18 | * An on-the-wire representation of an MQTT PINGRESP.
19 | */
20 | public class MqttPingResp extends MqttAck {
21 | public MqttPingResp(byte info, byte[] variableHeader) {
22 | super(MqttWireMessage.MESSAGE_TYPE_PINGRESP);
23 | }
24 |
25 | protected byte[] getVariableHeader() throws MqttException {
26 | // Not needed, as the client never encodes a PINGRESP
27 | return new byte[0];
28 | }
29 |
30 | /**
31 | * Returns whether or not this message needs to include a message ID.
32 | */
33 | public boolean isMessageIdRequired() {
34 | return false;
35 | }
36 |
37 | public String getKey() {
38 | return new String("Ping");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/io/yunba/java/core/MQTTMessage.java:
--------------------------------------------------------------------------------
1 | package io.yunba.java.core;
2 |
3 | import org.eclipse.paho.client.mqttv3.IMqttActionListener;
4 |
5 | public class MQTTMessage {
6 |
7 | public final static int TYPE_SUBSCRIBE = 1;
8 | public final static int TYPE_PUBLISH = 2;
9 | public final static int TYPE_UNSUBSCRIBE = 3;
10 | public final static int TYPE_EXPAND = 4;
11 | /**
12 | * 1 : subscribe
13 | * 2 : publish
14 | * 3 : unsubscribe
15 | * 4 : expand
16 | */
17 | public int type;
18 |
19 | public int callbackId;
20 |
21 | public String topic; // maybe topic, alias, jsonobject
22 |
23 | public String msg;
24 |
25 | public int qos;
26 |
27 | public Object userContent;
28 |
29 | public byte EXPAND_COMMNAD;
30 |
31 | public IMqttActionListener callback;
32 |
33 | public MQTTMessage(int type, String topic, String msg, int qos, Object userContent, int callback,
34 | IMqttActionListener listener) {
35 | this.type = type;
36 | this.callbackId = callback;
37 | this.topic = topic;
38 | this.msg = msg;
39 | this.qos = qos;
40 | this.userContent = userContent;
41 | this.callback = listener;
42 | }
43 |
44 |
45 | @Override
46 | public String toString() {
47 | return "type = " + type + " topic = " + topic + " msg = " + topic + " userContent = " + userContent;
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingReq.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttException;
15 |
16 | /**
17 | * An on-the-wire representation of an MQTT PINGREQ message.
18 | */
19 | public class MqttPingReq extends MqttWireMessage {
20 | public MqttPingReq() {
21 | super(MqttWireMessage.MESSAGE_TYPE_PINGREQ);
22 | }
23 |
24 | /**
25 | * Returns false as message IDs are not required for MQTT
26 | * PINGREQ messages.
27 | */
28 | public boolean isMessageIdRequired() {
29 | return false;
30 | }
31 |
32 | protected byte[] getVariableHeader() throws MqttException {
33 | return new byte[0];
34 | }
35 |
36 | protected byte getMessageInfo() {
37 | return 0;
38 | }
39 |
40 | public String getKey() {
41 | return new String("Ping");
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttUnsubAck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 | /**
22 | * An on-the-wire representation of an MQTT UNSUBACK.
23 | */
24 | public class MqttUnsubAck extends MqttAck {
25 |
26 | public MqttUnsubAck(byte info, byte[] data) throws IOException {
27 | super(MqttWireMessage.MESSAGE_TYPE_UNSUBACK);
28 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
29 | DataInputStream dis = new DataInputStream(bais);
30 | msgId = dis.readLong();
31 | dis.close();
32 | }
33 |
34 | protected byte[] getVariableHeader() throws MqttException {
35 | // Not needed, as the client never encodes an UNSUBACK
36 | return new byte[0];
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=Invalid protocol version
15 | 2=Invalid client ID
16 | 3=Broker unavailable
17 | 4=Bad user name or password
18 | 5=Not authorized to connect
19 | 6=Unexpected error
20 | 32000=Timed out waiting for a response from the server
21 | 32100=Client is connected
22 | 32101=Client is disconnected
23 | 32102=Client is currently disconnecting
24 | 32103=Unable to connect to server
25 | 32104=Client is not connected
26 | 32105=The specified SocketFactory type does not match the broker URI
27 | 32106=SSL configuration error
28 | 32107=Disconnecting is not allowed from a callback method
29 | 32108=Unrecognized packet
30 | 32109=Connection lost
31 | 32110=Connect already in progress
32 | 32111=Client is closed
33 | 32200=Persistence already in use
34 | 32201=Token already in use
35 | 32202=Too many publishes in progress
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttDisconnect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttException;
15 |
16 | /**
17 | * An on-the-wire representation of an MQTT DISCONNECT message.
18 | */
19 | public class MqttDisconnect extends MqttWireMessage {
20 | public static String KEY="Disc";
21 |
22 | public MqttDisconnect() {
23 | super(MqttWireMessage.MESSAGE_TYPE_DISCONNECT);
24 | }
25 |
26 | protected byte getMessageInfo() {
27 | return (byte) 0;
28 | }
29 |
30 | protected byte[] getVariableHeader() throws MqttException {
31 | return new byte[0];
32 | }
33 |
34 | /**
35 | * Returns whether or not this message needs to include a message ID.
36 | */
37 | public boolean isMessageIdRequired() {
38 | return false;
39 | }
40 |
41 | public String getKey() {
42 | try {
43 | return new String(KEY);
44 | } catch (Exception e) {
45 | return "";
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_it.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=Versione di protocollo non valida
15 | 2=ID client non valido
16 | 3=Broker non disponibile
17 | 4=Nome utente o password non validi
18 | 5=Non autorizzato per la connessione
19 | 6=Errore imprevisto
20 | 32000=Scaduto in attesa di una risposta dal server
21 | 32100=Client connesso
22 | 32101=Client disconnesso
23 | 32102=Client in fase di disconnessione
24 | 32103=Impossibile effettuare la connessione al server
25 | 32104=Client non connesso
26 | 32105=Il tipo SocketFactory specificato non corrisponde all'URI del broker
27 | 32106=Errore di configurazione SSL
28 | 32107=Disconnessione non consentita da un metodo callback
29 | 32108=Pacchetto non riconosciuto
30 | 32109=Connessione persa
31 | 32110=Connessione gi\u00e0 in corso
32 | 32111=Client chiuso
33 | 32200=Persistenza gi\u00e0 in uso
34 | 32201=Token gi\u00e0 in uso
35 | 32202=Numero eccessivo di pubblicazioni in corso
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubAck.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 |
22 | /**
23 | * An on-the-wire representation of an MQTT PUBACK message.
24 | */
25 | public class MqttPubAck extends MqttAck {
26 | public MqttPubAck(byte info, byte[] data) throws IOException {
27 | super(MqttWireMessage.MESSAGE_TYPE_PUBACK);
28 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
29 | DataInputStream dis = new DataInputStream(bais);
30 | msgId = dis.readLong();
31 | dis.close();
32 | }
33 |
34 | public MqttPubAck(MqttPublish publish) {
35 | super(MqttWireMessage.MESSAGE_TYPE_PUBACK);
36 | msgId = publish.getMessageId();
37 | }
38 |
39 | protected byte[] getVariableHeader() throws MqttException {
40 | return encodeMessageId();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 |
22 | /**
23 | * An on-the-wire representation of an MQTT PUBREC message.
24 | */
25 | public class MqttPubRec extends MqttAck {
26 | public MqttPubRec(byte info, byte[] data) throws IOException {
27 | super(MqttWireMessage.MESSAGE_TYPE_PUBREC);
28 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
29 | DataInputStream dis = new DataInputStream(bais);
30 | msgId = dis.readLong();
31 | dis.close();
32 | }
33 |
34 | public MqttPubRec(MqttPublish publish) {
35 | super(MqttWireMessage.MESSAGE_TYPE_PUBREC);
36 | msgId = publish.getMessageId();
37 | }
38 |
39 | protected byte[] getVariableHeader() throws MqttException {
40 | return encodeMessageId();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/IMqttActionListener.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.paho.client.mqttv3;
2 |
3 | /**
4 | * Implementors of this interface will be notified when an asynchronous action completes.
5 | *
6 | *
A listener is registered on an MqttToken and a token is associated 7 | * with an action like connect or publish. When used with tokens on the MqttAsyncClient 8 | * the listener will be called back on the MQTT clients thread. The listener will be informed 9 | * if the action succeeds or fails. It is important that the listener returns control quickly 10 | * otherwise the operation of the MQTT client will be stalled. 11 | *
12 | */ 13 | public interface IMqttActionListener { 14 | /** 15 | * This method is invoked when an action has completed successfully. 16 | * @param asyncActionToken associated with the action that has completed 17 | */ 18 | public void onSuccess(IMqttToken asyncActionToken ); 19 | /** 20 | * This method is invoked when an action fails. 21 | * If a client is disconnected while an action is in progress 22 | * onFailure will be called. For connections 23 | * that use clean session set to false, any QOS 1 and 2 messages that 24 | * are in the process of being delivered will be delivered to the requested 25 | * quality of service next time the client connects. 26 | * @param asyncActionToken associated with the action that has failed 27 | */ 28 | public void onFailure(IMqttToken asyncActionToken, Throwable exception); 29 | } 30 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/nls/messages_fr.properties: -------------------------------------------------------------------------------- 1 | #/* 2 | # * Copyright (c) 2009, 2012 IBM Corp. 3 | # * 4 | # * All rights reserved. This program and the accompanying materials 5 | # * are made available under the terms of the Eclipse Public License v1.0 6 | # * which accompanies this distribution, and is available at 7 | # * http://www.eclipse.org/legal/epl-v10.html 8 | # * 9 | # * Contributors: 10 | # * Dave Locke - initial API and implementation and/or initial documentation 11 | # */ 12 | # NLS_MESSAGEFORMAT_VAR 13 | # NLS_ENCODING=UNICODE 14 | 1=Version de protocole incorrecte 15 | 2=ID client incorrect 16 | 3=Courtier indisponible 17 | 4=Nom d'utilisateur ou mot de passe incorrect 18 | 5=L'utilisateur n'est pas autoris\u00e9 \u00e0 se connecter 19 | 6=Erreur inattendue. 20 | 32000=Expiration du d\u00e9lai d'attente d'une r\u00e9ponse du serveur 21 | 32100=Client connect\u00e9 22 | 32101=Client d\u00e9connect\u00e9 23 | 32102=Client en cours de d\u00e9connexion 24 | 32103=Impossible de se connecter au serveur 25 | 32104=Client non connect\u00e9 26 | 32105=Le type SocketFactory sp\u00e9cifi\u00e9 ne correspond pas \u00e0 l'URI de courtier 27 | 32106=Erreur de configuration SSL 28 | 32107=D\u00e9connexion non autoris\u00e9e pour une m\u00e9thode de rappel 29 | 32108=Paquet non reconnu 30 | 32109=Connexion perdue 31 | 32110=Connexion d\u00e9j\u00e0 en cours 32 | 32111=Client ferm\u00e9 33 | 32200=La persistance est d\u00e9j\u00e0 en cours d'utilisation 34 | 32201=Jeton d\u00e9j\u00e0 en cours d'utilisation 35 | 32202=Trop de publications en cours 36 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubComp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal.wire; 13 | 14 | import java.io.ByteArrayInputStream; 15 | import java.io.DataInputStream; 16 | import java.io.IOException; 17 | 18 | import org.eclipse.paho.client.mqttv3.MqttException; 19 | 20 | 21 | 22 | /** 23 | * An on-the-wire representation of an MQTT PUBCOMP message. 24 | */ 25 | public class MqttPubComp extends MqttAck { 26 | public MqttPubComp(byte info, byte[] data) throws IOException { 27 | super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP); 28 | ByteArrayInputStream bais = new ByteArrayInputStream(data); 29 | DataInputStream dis = new DataInputStream(bais); 30 | msgId = dis.readLong(); 31 | dis.close(); 32 | } 33 | 34 | public MqttPubComp(MqttPublish publish) { 35 | super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP); 36 | this.msgId = publish.getMessageId(); 37 | } 38 | 39 | public MqttPubComp(long msgId) { 40 | super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP); 41 | this.msgId = msgId; 42 | } 43 | 44 | protected byte[] getVariableHeader() throws MqttException { 45 | return encodeMessageId(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/nls/messages_de.properties: -------------------------------------------------------------------------------- 1 | #/* 2 | # * Copyright (c) 2009, 2012 IBM Corp. 3 | # * 4 | # * All rights reserved. This program and the accompanying materials 5 | # * are made available under the terms of the Eclipse Public License v1.0 6 | # * which accompanies this distribution, and is available at 7 | # * http://www.eclipse.org/legal/epl-v10.html 8 | # * 9 | # * Contributors: 10 | # * Dave Locke - initial API and implementation and/or initial documentation 11 | # */ 12 | # NLS_MESSAGEFORMAT_VAR 13 | # NLS_ENCODING=UNICODE 14 | 1=Protokollversion ung\u00fcltig 15 | 2=Client-ID ung\u00fcltig 16 | 3=Broker nicht verf\u00fcgbar 17 | 4=Benutzername oder Kennwort falsch 18 | 5=Keine Berechtigung f\u00fcr Verbindung 19 | 6=Unerwarteter Fehler 20 | 32000=Zeitlimit\u00fcberschreitung beim Warten auf eine Antwort vom Server 21 | 32100=Verbindung zu Client ist hergestellt 22 | 32101=Verbindung zu Client ist getrennt 23 | 32102=Verbindung zu Client wird derzeit getrennt 24 | 32103=Verbindung zu Server kann nicht hergestellt werden 25 | 32104=Keine Verbindung zu Client 26 | 32105=Der angegebene Socket-Factorytyp entspricht nicht der Broker-URI 27 | 32106=SSL-Konfigurationsfehler 28 | 32107=Trennung einer Verbindung \u00fcber eine Callback-Methode ist nicht zul\u00e4ssig 29 | 32108=Paket nicht erkannt 30 | 32109=Verbindung wurde getrennt 31 | 32110=Verbindungsherstellung wird ausgef\u00fchrt 32 | 32111=Client ist geschlossen 33 | 32200=Persistenz wird bereits verwendet 34 | 32201=Token wird bereits verwendet 35 | 32202=Zu viele Ver\u00f6ffentlichungen werden ausgef\u00fchrt 36 | -------------------------------------------------------------------------------- /src/io/yunba/java/util/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package io.yunba.java.util; 2 | 3 | import java.net.InetAddress; 4 | import java.net.UnknownHostException; 5 | import java.util.regex.Pattern; 6 | 7 | public class CommonUtil { 8 | private final static String HEX = "0123456789ABCDEF"; 9 | 10 | /** 11 | * will trim the string 12 | * 13 | * @param s 14 | * @return 15 | */ 16 | public static boolean isEmpty(String s) { 17 | if (null == s) 18 | return true; 19 | if (s.length() == 0) 20 | return true; 21 | if (s.trim().length() == 0) 22 | return true; 23 | return false; 24 | } 25 | 26 | public static String hostToIp(String host) { 27 | InetAddress address; 28 | try { 29 | address = InetAddress.getByName(host); 30 | return address.getHostAddress(); 31 | } catch (UnknownHostException e) { 32 | return null; 33 | } 34 | } 35 | 36 | public static byte DNS_REASON = 0; 37 | 38 | public staticCountingInputStream wrapping the supplied
26 | * input stream.
27 | */
28 | public CountingInputStream(InputStream in) {
29 | this.in = in;
30 | this.counter = 0;
31 | }
32 |
33 | public int read() throws IOException {
34 | try {
35 | int i = in.read();
36 | if (i != -1) {
37 | counter++;
38 | }
39 | return i;
40 | } catch (Exception e) {
41 | throw new IOException();
42 | }
43 |
44 | }
45 |
46 | /**
47 | * Returns the number of bytes read since the last reset.
48 | */
49 | public int getCounter() {
50 | return counter;
51 | }
52 |
53 | /**
54 | * Resets the counter to zero.
55 | */
56 | public void resetCounter() {
57 | counter = 0;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MultiByteArrayInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 |
17 | public class MultiByteArrayInputStream extends InputStream {
18 |
19 | private byte[] bytesA;
20 | private int offsetA;
21 | private int lengthA;
22 | private byte[] bytesB;
23 | private int offsetB;
24 | private int lengthB;
25 |
26 | private int pos = 0;
27 |
28 | public MultiByteArrayInputStream(byte[] bytesA, int offsetA, int lengthA, byte[] bytesB, int offsetB, int lengthB) {
29 | this.bytesA = bytesA;
30 | this.bytesB = bytesB;
31 | this.offsetA = offsetA;
32 | this.offsetB = offsetB;
33 | this.lengthA = lengthA;
34 | this.lengthB = lengthB;
35 | }
36 | public int read() throws IOException {
37 | int result = -1;
38 | if (posUntil the message has been delivered, the message being delivered will
37 | * be returned. Once the message has been delivered
18 | * An action is in progress until either:
19 | * null will be
38 | * returned.
39 | * @return the message associated with this token or null if already delivered.
40 | * @throws MqttException if there was a problem completing retrieving the message
41 | */
42 | public MqttMessage getMessage() throws MqttException {
43 | return internalTok.getMessage();
44 | }
45 |
46 | protected void setMessage(MqttMessage msg) {
47 | internalTok.setMessage(msg);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 | /**
22 | * An on-the-wire representation of an MQTT CONNACK.
23 | */
24 | public class MqttConnack extends MqttAck {
25 | private int returnCode;
26 |
27 | public MqttConnack(byte info, byte[] variableHeader) throws Exception {
28 | super(MqttWireMessage.MESSAGE_TYPE_CONNACK);
29 | ByteArrayInputStream bais = new ByteArrayInputStream(variableHeader);
30 | DataInputStream dis = new DataInputStream(bais);
31 | dis.readByte();
32 | returnCode = dis.readUnsignedByte();
33 | dis.close();
34 | }
35 |
36 | public int getReturnCode() {
37 | return returnCode;
38 | }
39 |
40 | protected byte[] getVariableHeader() throws MqttException {
41 | // Not needed, as the client never encodes a CONNACK
42 | return new byte[0];
43 | }
44 |
45 | /**
46 | * Returns whether or not this message needs to include a message ID.
47 | */
48 | public boolean isMessageIdRequired() {
49 | return false;
50 | }
51 |
52 | public String getKey() {
53 | return new String("Con");
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/MessageCatalog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal;
13 |
14 | /**
15 | * Catalog of human readable error messages.
16 | */
17 | public abstract class MessageCatalog {
18 | private static MessageCatalog INSTANCE = null;
19 |
20 | public static final String getMessage(int id) {
21 | try {
22 | if (INSTANCE == null) {
23 | if (ExceptionHelper.isClassAvailable("java.util.ResourceBundle")) {
24 | try {
25 | // Hide this class reference behind reflection so that the class does not need to
26 | // be present when compiled on midp
27 | INSTANCE = (MessageCatalog)Class.forName("org.eclipse.paho.client.mqttv3.internal.ResourceBundleCatalog").newInstance();
28 | } catch (Exception e) {
29 | return "";
30 | }
31 | } else if (ExceptionHelper.isClassAvailable("org.eclipse.paho.client.mqttv3.internal.MIDPCatalog")){
32 | try {
33 | INSTANCE = (MessageCatalog)Class.forName("org.eclipse.paho.client.mqttv3.internal.MIDPCatalog").newInstance();
34 | } catch (Exception e) {
35 | return "";
36 | }
37 | }
38 | }
39 | return INSTANCE.getLocalizedMessage(id);
40 | } catch(Exception e) {
41 | return "";
42 | }
43 | }
44 |
45 | protected abstract String getLocalizedMessage(int id);
46 | }
47 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_zh_CN.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=\u65e0\u6548\u534f\u8bae\u7248\u672c
15 | 2=\u65e0\u6548\u5ba2\u6237\u673a\u6807\u8bc6
16 | 3=\u4ee3\u7406\u7a0b\u5e8f\u4e0d\u53ef\u7528
17 | 4=\u9519\u8bef\u7684\u7528\u6237\u540d\u6216\u5bc6\u7801
18 | 5=\u65e0\u6743\u8fde\u63a5
19 | 6=\u610f\u5916\u9519\u8bef
20 | 32000=\u7b49\u5f85\u6765\u81ea\u670d\u52a1\u5668\u7684\u54cd\u5e94\u65f6\u8d85\u65f6
21 | 32100=\u5df2\u8fde\u63a5\u5ba2\u6237\u673a
22 | 32101=\u5df2\u65ad\u5f00\u5ba2\u6237\u673a\u8fde\u63a5
23 | 32102=\u5ba2\u6237\u673a\u6b63\u5728\u65ad\u5f00\u8fde\u63a5
24 | 32103=\u65e0\u6cd5\u8fde\u63a5\u81f3\u670d\u52a1\u5668
25 | 32104=\u5ba2\u6237\u673a\u672a\u8fde\u63a5
26 | 32105=\u6307\u5b9a\u7684 SocketFactory \u7c7b\u578b\u4e0e\u4ee3\u7406\u7a0b\u5e8f URI \u4e0d\u5339\u914d
27 | 32106=SSL \u914d\u7f6e\u9519\u8bef
28 | 32107=\u4e0d\u5141\u8bb8\u901a\u8fc7\u56de\u8c03\u65b9\u6cd5\u65ad\u5f00\u8fde\u63a5
29 | 32108=\u4e0d\u53ef\u8bc6\u522b\u7684\u5305
30 | 32109=\u5df2\u65ad\u5f00\u8fde\u63a5
31 | 32110=\u5df2\u5728\u8fdb\u884c\u8fde\u63a5
32 | 32111=\u5ba2\u6237\u673a\u5df2\u5173\u95ed
33 | 32200=\u6301\u4e45\u6027\u5df2\u5728\u4f7f\u7528\u4e2d
34 | 32201=\u4ee4\u724c\u5df2\u5728\u4f7f\u7528\u4e2d
35 | 32202=\u6b63\u5728\u8fdb\u884c\u8fc7\u591a\u7684\u53d1\u5e03
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/MqttSecurityException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3;
13 |
14 | /**
15 | * Thrown when a client is not authorized to perform an operation, or
16 | * if there is a problem with the security configuration.
17 | */
18 | public class MqttSecurityException extends MqttException {
19 | private static final long serialVersionUID = 300L;
20 |
21 | /**
22 | * Constructs a new MqttSecurityException with the specified code
23 | * as the underlying reason.
24 | * @param reasonCode the reason code for the exception.
25 | */
26 | public MqttSecurityException(int reasonCode) {
27 | super(reasonCode);
28 | }
29 |
30 | /**
31 | * Constructs a new MqttSecurityException with the specified
32 | * Throwable as the underlying reason.
33 | * @param cause the underlying cause of the exception.
34 | */
35 | public MqttSecurityException(Throwable cause) {
36 | super(cause);
37 | }
38 | /**
39 | * Constructs a new MqttSecurityException with the specified
40 | * code and Throwable as the underlying reason.
41 | * @param reasonCode the reason code for the exception.
42 | * @param cause the underlying cause of the exception.
43 | */
44 | public MqttSecurityException(int reasonCode, Throwable cause) {
45 | super(reasonCode, cause);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_pl.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=Niepoprawna wersja protoko\u0142u
15 | 2=Niepoprawny identyfikator klienta
16 | 3=Broker niedost\u0119pny
17 | 4=Niepoprawna nazwa u\u017cytkownika lub has\u0142o
18 | 5=Brak autoryzacji do nawi\u0105zania po\u0142\u0105czenia
19 | 6=Nieoczekiwany b\u0142\u0105d
20 | 32000=Przekroczono limit czasu oczekiwania na odpowied\u017a z serwera
21 | 32100=Po\u0142\u0105czenie z klientem zosta\u0142o nawi\u0105zane
22 | 32101=Po\u0142\u0105czenie z klientem zosta\u0142o roz\u0142\u0105czone
23 | 32102=Klient roz\u0142\u0105cza si\u0119
24 | 32103=Nie mo\u017cna nawi\u0105za\u0107 po\u0142\u0105czenia z serwerem
25 | 32104=Po\u0142\u0105czenie z klientem nie jest nawi\u0105zane
26 | 32105=Podany typ fabryki SocketFactory nie jest zgodny z identyfikatorem URI brokera
27 | 32106=B\u0142\u0105d konfiguracji protoko\u0142u SSL
28 | 32107=Roz\u0142\u0105czenie nie jest dozwolone w metodzie procedury zwrotnej
29 | 32108=Nierozpoznany pakiet
30 | 32109=Utracono po\u0142\u0105czenie
31 | 32110=Operacja nawi\u0105zywania po\u0142\u0105czenia jest ju\u017c w toku
32 | 32111=Klient zosta\u0142 zamkni\u0119ty
33 | 32200=Trwa\u0142o\u015b\u0107 jest ju\u017c w u\u017cyciu
34 | 32201=Znacznik jest ju\u017c w u\u017cyciu
35 | 32202=Zbyt wiele operacji publikowania jest w toku
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_zh_TW.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=\u901a\u8a0a\u5354\u5b9a\u7248\u672c\u7121\u6548
15 | 2=\u7528\u6236\u7aef ID \u7121\u6548
16 | 3=\u5206\u914d\u7ba1\u7406\u7cfb\u7d71\u7121\u6cd5\u4f7f\u7528
17 | 4=\u4f7f\u7528\u8005\u540d\u7a31\u6216\u5bc6\u78bc\u4e0d\u7576
18 | 5=\u672a\u7372\u6388\u6b0a\u9023\u63a5
19 | 6=\u975e\u9810\u671f\u7684\u932f\u8aa4
20 | 32000=\u7b49\u5f85\u4f3a\u670d\u5668\u7684\u56de\u61c9\u6642\u903e\u6642
21 | 32100=\u5df2\u9023\u63a5\u7528\u6236\u7aef
22 | 32101=\u5df2\u4e2d\u65b7\u7528\u6236\u7aef\u7684\u9023\u63a5
23 | 32102=\u7528\u6236\u7aef\u76ee\u524d\u6b63\u5728\u4e2d\u65b7\u9023\u7dda
24 | 32103=\u7121\u6cd5\u9023\u63a5\u5230\u4f3a\u670d\u5668
25 | 32104=\u7528\u6236\u7aef\u672a\u9023\u63a5
26 | 32105=\u6307\u5b9a\u7684 SocketFactory \u985e\u578b\u8207\u5206\u914d\u7ba1\u7406\u7cfb\u7d71 URI \u4e0d\u7b26
27 | 32106=SSL \u914d\u7f6e\u932f\u8aa4
28 | 32107=\u4e0d\u5bb9\u8a31\u8207\u56de\u547c\u65b9\u6cd5\u4e2d\u65b7\u9023\u7dda
29 | 32108=\u5c01\u5305\u7121\u6cd5\u8fa8\u8b58
30 | 32109=\u9023\u7dda\u907a\u5931
31 | 32110=\u9023\u63a5\u5df2\u5728\u9032\u884c\u4e2d
32 | 32111=\u5df2\u95dc\u9589\u7528\u6236\u7aef
33 | 32200=\u6301\u7e8c\u6027\u5df2\u5728\u4f7f\u7528\u4e2d
34 | 32201=\u8a18\u865f\u5df2\u5728\u4f7f\u7528\u4e2d
35 | 32202=\u592a\u591a\u767c\u4f48\u9032\u884c\u4e2d
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 | /**
21 | * An on-the-wire representation of an MQTT PUBREL message.
22 | */
23 | public class MqttPubRel extends MqttPersistableWireMessage {
24 |
25 | /**
26 | * Createa a pubrel message based on a pubrec
27 | * @param pubRec
28 | */
29 | public MqttPubRel(MqttPubRec pubRec) {
30 | super(MqttWireMessage.MESSAGE_TYPE_PUBREL);
31 | this.setMessageId(pubRec.getMessageId());
32 | }
33 |
34 | /**
35 | * Creates a pubrel based on a pubrel set of bytes read fro the network
36 | * @param info
37 | * @param data
38 | * @throws IOException
39 | */
40 | public MqttPubRel(byte info, byte[] data) throws IOException {
41 | super(MqttWireMessage.MESSAGE_TYPE_PUBREL);
42 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
43 | DataInputStream dis = new DataInputStream(bais);
44 | msgId = dis.readLong();
45 | dis.close();
46 | }
47 |
48 | protected byte[] getVariableHeader() throws MqttException {
49 | return encodeMessageId();
50 | }
51 |
52 | protected byte getMessageInfo() {
53 | return (byte)( 2 | (this.duplicate?8:0));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_hu.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=\u00c9rv\u00e9nytelen protokoll v\u00e1ltozat
15 | 2=\u00c9rv\u00e9nytelen \u00fcgyf\u00e9lazonos\u00edt\u00f3
16 | 3=K\u00f6zvet\u00edt\u0151 nem el\u00e9rhet\u0151
17 | 4=Rossz felhaszn\u00e1l\u00f3i n\u00e9v vagy jelsz\u00f3
18 | 5=Nem jogosult csatlakozni
19 | 6=V\u00e1ratlan hiba
20 | 32000=T\u00fall\u00e9pte a megengedett id\u0151t a kiszolg\u00e1l\u00f3 v\u00e1lasz\u00e1ra v\u00e1rva
21 | 32100=Az \u00fcgyf\u00e9l csatlakoztatva van
22 | 32101=Az \u00fcgyf\u00e9l sz\u00e9tkapcsolt
23 | 32102=Az \u00fcgyf\u00e9l \u00e9pp megszak\u00edtja a kapcsolatot
24 | 32103=Nem lehet kapcsol\u00f3dni a kiszolg\u00e1l\u00f3hoz
25 | 32104=Az \u00fcgyf\u00e9l nincs csatlakoztatva
26 | 32105=A megadott SocketFactory t\u00edpus nem illeszkedik a k\u00f6zvet\u00edt\u0151 URI azonos\u00edt\u00f3hoz
27 | 32106=SSL konfigur\u00e1ci\u00f3s hiba
28 | 32107=A megszak\u00edt\u00e1s visszah\u00edv\u00e1s met\u00f3dusb\u00f3l nem enged\u00e9lyezett
29 | 32108=Ismeretlen csomag
30 | 32109=Kapcsolat elveszett
31 | 32110=A csatlakoz\u00e1s m\u00e1r folyamatban van
32 | 32111=Az \u00fcgyf\u00e9l bez\u00e1r\u00e1sra ker\u00fclt
33 | 32200=A megmarad\u00f3 \u00e1llapot m\u00e1r haszn\u00e1latban van
34 | 32201=A token m\u00e1r haszn\u00e1latban van.
35 | 32202=T\u00fal sok k\u00f6zz\u00e9t\u00e9tel van folyamatban
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/ExceptionHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttException;
15 | import org.eclipse.paho.client.mqttv3.MqttSecurityException;
16 |
17 | /**
18 | * Utility class to help create exceptions of the correct type.
19 | */
20 | public class ExceptionHelper {
21 | public static MqttException createMqttException(int reasonCode) {
22 | if ((reasonCode == MqttException.REASON_CODE_FAILED_AUTHENTICATION) ||
23 | (reasonCode == MqttException.REASON_CODE_NOT_AUTHORIZED)) {
24 | return new MqttSecurityException(reasonCode);
25 | }
26 |
27 | return new MqttException(reasonCode);
28 | }
29 |
30 | public static MqttException createMqttException(Throwable cause) {
31 | if (cause.getClass().getName().equals("java.security.GeneralSecurityException")) {
32 | return new MqttSecurityException(cause);
33 | }
34 | return new MqttException(cause);
35 | }
36 |
37 | /**
38 | * Returns whether or not the specified class is available to the current
39 | * class loader. This is used to protect the code against using Java SE
40 | * APIs on Java ME.
41 | */
42 | public static boolean isClassAvailable(String className) {
43 | boolean result = false;
44 | try {
45 | Class.forName(className);
46 | result = true;
47 | }
48 | catch (ClassNotFoundException ex) {
49 | }
50 | return result;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.BufferedOutputStream;
15 | import java.io.IOException;
16 | import java.io.OutputStream;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 | /**
22 | * An MqttOutputStream lets applications write instances of
23 | * MqttWireMessage.
24 | */
25 | public class MqttOutputStream extends OutputStream {
26 | private BufferedOutputStream out;
27 |
28 | public MqttOutputStream(OutputStream out) {
29 | this.out = new BufferedOutputStream(out);
30 | }
31 |
32 | public void close() throws IOException {
33 | out.close();
34 | }
35 |
36 | public void flush() throws IOException {
37 | out.flush();
38 | }
39 |
40 | public void write(byte[] b) throws IOException {
41 | out.write(b);
42 | }
43 |
44 | public void write(byte[] b, int off, int len) throws IOException {
45 | out.write(b, off, len);
46 | }
47 |
48 | public void write(int b) throws IOException {
49 | out.write(b);
50 | }
51 |
52 | /**
53 | * Writes an MqttWireMessage to the stream.
54 | */
55 | public void write(MqttWireMessage message) throws IOException, MqttException {
56 | byte[] bytes = message.getHeader();
57 | byte[] pl = message.getPayload();
58 | // out.write(message.getHeader());
59 | // out.write(message.getPayload());
60 | out.write(bytes,0,bytes.length);
61 | out.write(pl,0,pl.length);
62 | }
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPersistableWireMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import org.eclipse.paho.client.mqttv3.MqttException;
15 | import org.eclipse.paho.client.mqttv3.MqttPersistable;
16 | import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
17 |
18 | public abstract class MqttPersistableWireMessage extends MqttWireMessage
19 | implements MqttPersistable {
20 |
21 | public MqttPersistableWireMessage(byte type) {
22 | super(type);
23 | }
24 |
25 | public byte[] getHeaderBytes() throws MqttPersistenceException {
26 | try {
27 | return getHeader();
28 | }
29 | catch (MqttException ex) {
30 | throw new MqttPersistenceException(ex.getCause());
31 | }
32 | }
33 |
34 | public int getHeaderLength() throws MqttPersistenceException {
35 | return getHeaderBytes().length;
36 | }
37 |
38 | public int getHeaderOffset() throws MqttPersistenceException{
39 | return 0;
40 | }
41 |
42 | // public String getKey() throws MqttPersistenceException {
43 | // return new Integer(getMessageId()).toString();
44 | // }
45 |
46 | public byte[] getPayloadBytes() throws MqttPersistenceException {
47 | try {
48 | return getPayload();
49 | }
50 | catch (MqttException ex) {
51 | throw new MqttPersistenceException(ex.getCause());
52 | }
53 | }
54 |
55 | public int getPayloadLength() throws MqttPersistenceException {
56 | return 0;
57 | }
58 |
59 | public int getPayloadOffset() throws MqttPersistenceException {
60 | return 0;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttUnsubscribe.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayOutputStream;
15 | import java.io.DataOutputStream;
16 | import java.io.IOException;
17 |
18 | import org.eclipse.paho.client.mqttv3.MqttException;
19 |
20 |
21 | /**
22 | * An on-the-wire representation of an MQTT UNSUBSCRIBE message.
23 | */
24 | public class MqttUnsubscribe extends MqttWireMessage {
25 |
26 | private String[] names;
27 |
28 | /**
29 | * Constructs an MqttUnsubscribe
30 | */
31 | public MqttUnsubscribe(String[] names) {
32 | super(MqttWireMessage.MESSAGE_TYPE_UNSUBSCRIBE);
33 | this.names = names;
34 | }
35 |
36 | protected byte getMessageInfo() {
37 | return (byte)( 2 | (this.duplicate?8:0));
38 | }
39 |
40 | protected byte[] getVariableHeader() throws MqttException {
41 | try {
42 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
43 | DataOutputStream dos = new DataOutputStream(baos);
44 | dos.writeLong(msgId);
45 | dos.flush();
46 | return baos.toByteArray();
47 | }
48 | catch (IOException ex) {
49 | throw new MqttException(ex);
50 | }
51 | }
52 |
53 | public byte[] getPayload() throws MqttException {
54 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
55 | DataOutputStream dos = new DataOutputStream(baos);
56 | for (int i=0; i
10 | *
17 | *
20 | *
27 | *
Until the message has been delivered, the message being delivered will
35 | * be returned. Once the message has been delivered null will be
36 | * returned.
37 | * @return the message associated with this token or null if already delivered.
38 | * @throws MqttException if there was a problem completing retrieving the message
39 | */
40 | public MqttMessage getMessage() throws MqttException;
41 | }
42 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/MqttPersistenceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3;
13 |
14 | /**
15 | * This exception is thrown by the implementor of the persistence
16 | * interface if there is a problem reading or writing persistent data.
17 | */
18 | public class MqttPersistenceException extends MqttException {
19 | private static final long serialVersionUID = 300L;
20 |
21 | /** Persistence is already being used by another client. */
22 | public static final short REASON_CODE_PERSISTENCE_IN_USE = 32200;
23 |
24 | /**
25 | * Constructs a new MqttPersistenceException
26 | */
27 | public MqttPersistenceException() {
28 | super(REASON_CODE_CLIENT_EXCEPTION);
29 | }
30 |
31 | /**
32 | * Constructs a new MqttPersistenceException with the specified code
33 | * as the underlying reason.
34 | * @param reasonCode the reason code for the exception.
35 | */
36 | public MqttPersistenceException(int reasonCode) {
37 | super(reasonCode);
38 | }
39 | /**
40 | * Constructs a new MqttPersistenceException with the specified
41 | * Throwable as the underlying reason.
42 | * @param cause the underlying cause of the exception.
43 | */
44 | public MqttPersistenceException(Throwable cause) {
45 | super(cause);
46 | }
47 | /**
48 | * Constructs a new MqttPersistenceException with the specified
49 | * Throwable as the underlying reason.
50 | * @param reason the reason code for the exception.
51 | * @param cause the underlying cause of the exception.
52 | */
53 | public MqttPersistenceException(int reason, Throwable cause) {
54 | super(reason, cause);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/nls/messages_ko.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Copyright (c) 2009, 2012 IBM Corp.
3 | # *
4 | # * All rights reserved. This program and the accompanying materials
5 | # * are made available under the terms of the Eclipse Public License v1.0
6 | # * which accompanies this distribution, and is available at
7 | # * http://www.eclipse.org/legal/epl-v10.html
8 | # *
9 | # * Contributors:
10 | # * Dave Locke - initial API and implementation and/or initial documentation
11 | # */
12 | # NLS_MESSAGEFORMAT_VAR
13 | # NLS_ENCODING=UNICODE
14 | 1=\uc62c\ubc14\ub974\uc9c0 \uc54a\uc740 \ud504\ub85c\ud1a0\ucf5c \ubc84\uc804
15 | 2=\uc62c\ubc14\ub974\uc9c0 \uc54a\uc740 \ud074\ub77c\uc774\uc5b8\ud2b8 ID
16 | 3=\ube0c\ub85c\ucee4 \uc0ac\uc6a9 \ubd88\uac00\ub2a5
17 | 4=\uc798\ubabb\ub41c \uc0ac\uc6a9\uc790 \uc774\ub984 \ub610\ub294 \ube44\ubc00\ubc88\ud638
18 | 5=\uc5f0\uacb0\ud560 \uc218 \uc788\ub294 \uad8c\ud55c\uc774 \ubd80\uc5ec\ub418\uc9c0 \uc54a\uc74c
19 | 6=\uc608\uc0c1\uce58 \ubabb\ud55c \uc624\ub958
20 | 32000=\uc11c\ubc84\uc5d0\uc11c \uc751\ub2f5\uc744 \uae30\ub2e4\ub9ac\ub294 \uc911 \uc81c\ud55c\uc2dc\uac04 \ucd08\uacfc
21 | 32100=\ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5f0\uacb0\ub428
22 | 32101=\ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5f0\uacb0\uc774 \ub04a\uae40
23 | 32102=\ud604\uc7ac \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5f0\uacb0\uc744 \ub04a\ub294 \uc911
24 | 32103=\uc11c\ubc84\uc5d0 \uc5f0\uacb0\ud560 \uc218 \uc5c6\uc74c
25 | 32104=\ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc5f0\uacb0\ub418\uc9c0 \uc54a\uc74c
26 | 32105=\uc9c0\uc815\ub41c SocketFactory \uc720\ud615\uc774 \ube0c\ub85c\ucee4 URI\uc640 \uc77c\uce58\ud558\uc9c0 \uc54a\uc74c
27 | 32106=SSL \uad6c\uc131 \uc624\ub958
28 | 32107=\ucf5c\ubc31 \uba54\uc18c\ub4dc\ub85c\ubd80\ud130 \uc5f0\uacb0\uc744 \ub04a\ub294 \uac83\uc774 \ud5c8\uc6a9\ub418\uc9c0 \uc54a\uc74c
29 | 32108=\uc778\uc2dd\ub418\uc9c0 \uc54a\uc740 \ud328\ud0b7
30 | 32109=\uc5f0\uacb0 \uc720\uc2e4
31 | 32110=\uc5f0\uacb0\uc774 \uc774\ubbf8 \uc9c4\ud589 \uc911\uc784
32 | 32111=\ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \ub2eb\ud798
33 | 32200=\uc9c0\uc18d \ud30c\uc77c\uc744 \uc774\ubbf8 \uc0ac\uc6a9 \uc911
34 | 32201=\ud1a0\ud070\uc774 \uc774\ubbf8 \uc0ac\uc6a9 \uc911\uc784
35 | 32202=\ub108\ubb34 \ub9ce\uc740 \ubc1c\ud589\uc774 \uc9c4\ud589 \uc911\uc784
36 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal.wire;
13 |
14 | import java.io.ByteArrayOutputStream;
15 | import java.io.DataInputStream;
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 |
19 | import org.eclipse.paho.client.mqttv3.MqttException;
20 | import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper;
21 |
22 |
23 | /**
24 | * An MqttInputStream lets applications read instances of
25 | * MqttWireMessage.
26 | */
27 | public class MqttInputStream extends InputStream {
28 | private DataInputStream in;
29 |
30 | public MqttInputStream(InputStream in) {
31 | this.in = new DataInputStream(in);
32 | }
33 |
34 | public int read() throws IOException {
35 | return in.read();
36 | }
37 |
38 | public int available() throws IOException {
39 | return in.available();
40 | }
41 |
42 | public void close() throws IOException {
43 | in.close();
44 | }
45 |
46 | /**
47 | * Reads an MqttWireMessage from the stream.
48 | */
49 | public MqttWireMessage readMqttWireMessage() throws Exception, MqttException {
50 | ByteArrayOutputStream bais = new ByteArrayOutputStream();
51 | byte first = in.readByte();
52 | byte type = (byte) ((first >>> 4) & 0x0F);
53 | if ((type < MqttWireMessage.MESSAGE_TYPE_CONNECT) ||
54 | (type > MqttWireMessage.MESSAGE_TYPE_EXPAND)) {
55 | // Invalid MQTT message type...
56 | throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_INVALID_MESSAGE);
57 | }
58 | long remLen = MqttWireMessage.readMBI(in).getValue();
59 | bais.write(first);
60 | // bit silly, we decode it then encode it
61 | bais.write(MqttWireMessage.encodeMBI(remLen));
62 | byte[] packet = new byte[(int)(bais.size()+remLen)];
63 | in.readFully(packet,bais.size(),packet.length - bais.size());
64 | byte[] header = bais.toByteArray();
65 | System.arraycopy(header,0,packet,0, header.length);
66 | MqttWireMessage message = MqttWireMessage.createWireMessage(packet);
67 | return message;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttExpandAck.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.paho.client.mqttv3.internal.wire;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.DataInputStream;
5 | import java.io.IOException;
6 |
7 | import org.codehaus.jettison.json.JSONObject;
8 | import org.eclipse.paho.client.mqttv3.MqttException;
9 |
10 | public class MqttExpandAck extends MqttAck {
11 | public byte command;
12 | public byte status;
13 | public String result;
14 |
15 | public MqttExpandAck(byte info, byte[] data) {
16 | super(MESSAGE_TYPE_EXPAND);
17 | DataInputStream dis = null;
18 | try {
19 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
20 | CountingInputStream counter = new CountingInputStream(bais);
21 | dis = new DataInputStream(counter);
22 | msgId = dis.readLong();
23 | byte[] payload = new byte[data.length - counter.getCounter()];
24 | dis.readFully(payload);
25 | command = payload[0];
26 | status = payload[1];
27 | if (payload.length > 2) {
28 | int lenth = getLenth(payload[2], payload[3]);
29 | byte[] msg = new byte[lenth];
30 |
31 | System.arraycopy(payload, 4, msg, 0, msg.length);
32 | result = new String(msg, "UTF-8");
33 | if (command == MqttExpand.CMD_GET_STATUS_ACK) {
34 | try {
35 | JSONObject js = new JSONObject();
36 | js.put("status", result);
37 | result = js.toString();
38 | } catch (Exception e) {
39 | // YLogger.e("JSONObject", "", e);
40 | }
41 | } else if(command == MqttExpand.CMD_GET_ALIAS_ACK) {
42 | // System.err.println("MqttExpand.CMD_GET_ALIAS_ACK = " + result);
43 | JSONObject js = new JSONObject();
44 | js.put("alias", result);
45 | result = js.toString();
46 |
47 | }
48 | // YLogger.d("MqttExpandAck", "result = " + result);
49 | } else {
50 | // YLogger.d("MqttExpandAck", "no data in payload");
51 | }
52 |
53 | } catch (Exception e) {
54 | // YLogger.e("MqttExpandAck", "", e);
55 | } finally {
56 | if (dis != null) {
57 | try {
58 | dis.close();
59 | } catch (Exception e) {
60 |
61 | }
62 | }
63 | }
64 |
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "command " + command + " status " + status + " msg = " + result;
70 | }
71 |
72 | @Override
73 | protected byte[] getVariableHeader() throws MqttException {
74 | // TODO Auto-generated method stub
75 | return null;
76 | }
77 |
78 | public static int getLenth(byte b1, byte b2) throws IOException {
79 |
80 | return ((b1 << 8) & 0xFF00) | b2 & 0xFF;
81 |
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/MqttToken.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.paho.client.mqttv3;
2 |
3 | import org.codehaus.jettison.json.JSONObject;
4 | import org.eclipse.paho.client.mqttv3.internal.Token;
5 |
6 | /**
7 | * Provides a mechanism for tracking the completion of an asynchronous action.
8 | *
9 | * A token that implements the ImqttToken interface is returned from all non-blocking 10 | * method with the exception of publish. 11 | *
12 | * 13 | * @see IMqttToken 14 | */ 15 | 16 | public class MqttToken implements IMqttToken { 17 | /** 18 | * A reference to the the class that provides most of the implementation of the 19 | * MqttToken. MQTT application programs must not use the internal class. 20 | */ 21 | public Token internalTok = null; 22 | 23 | public MqttToken() { 24 | } 25 | 26 | public MqttToken(String logContext) { 27 | internalTok = new Token(logContext); 28 | } 29 | 30 | public MqttException getException() { 31 | return internalTok.getException(); 32 | } 33 | 34 | public boolean isComplete() { 35 | return internalTok.isComplete(); 36 | } 37 | 38 | public void setActionCallback(IMqttActionListener listener) { 39 | internalTok.setActionCallback(listener); 40 | 41 | } 42 | public IMqttActionListener getActionCallback() { 43 | return internalTok.getActionCallback(); 44 | } 45 | 46 | public void waitForCompletion() throws MqttException { 47 | internalTok.waitForCompletion(-1); 48 | } 49 | 50 | public void waitForCompletion(long timeout) throws MqttException { 51 | internalTok.waitForCompletion(timeout); 52 | } 53 | 54 | public IMqttAsyncClient getClient() { 55 | return internalTok.getClient(); 56 | } 57 | 58 | public String[] getTopics() { 59 | return internalTok.getTopics(); 60 | } 61 | 62 | public Object getUserContext() { 63 | return internalTok.getUserContext(); 64 | } 65 | 66 | public void setUserContext(Object userContext) { 67 | internalTok.setUserContext(userContext); } 68 | 69 | public long getMessageId() { 70 | return internalTok.getMessageID(); 71 | } 72 | 73 | private String alias; 74 | 75 | @Override 76 | public String getAlias() { 77 | return alias; 78 | } 79 | 80 | @Override 81 | public void setAlias(String alias) { 82 | this.alias = alias; 83 | } 84 | 85 | private JSONObject result; 86 | 87 | @Override 88 | public JSONObject getResult() { 89 | return result; 90 | } 91 | 92 | @Override 93 | public void setResult(JSONObject result) { 94 | this.result = result; 95 | } 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/nls/messages_ja.properties: -------------------------------------------------------------------------------- 1 | #/* 2 | # * Copyright (c) 2009, 2012 IBM Corp. 3 | # * 4 | # * All rights reserved. This program and the accompanying materials 5 | # * are made available under the terms of the Eclipse Public License v1.0 6 | # * which accompanies this distribution, and is available at 7 | # * http://www.eclipse.org/legal/epl-v10.html 8 | # * 9 | # * Contributors: 10 | # * Dave Locke - initial API and implementation and/or initial documentation 11 | # */ 12 | # NLS_MESSAGEFORMAT_VAR 13 | # NLS_ENCODING=UNICODE 14 | 1=\u7121\u52b9\u306a\u30d7\u30ed\u30c8\u30b3\u30eb\u30fb\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3059 15 | 2=\u7121\u52b9\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID \u3067\u3059 16 | 3=\u30d6\u30ed\u30fc\u30ab\u30fc\u304c\u4f7f\u7528\u4e0d\u53ef\u3067\u3059 17 | 4=\u9593\u9055\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u540d\u307e\u305f\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u3067\u3059 18 | 5=\u63a5\u7d9a\u3059\u308b\u6a29\u9650\u304c\u3042\u308a\u307e\u305b\u3093 19 | 6=\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc 20 | 32000=\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u306e\u5fdc\u7b54\u5f85\u6a5f\u304c\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306b\u306a\u308a\u307e\u3057\u305f 21 | 32100=\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u63a5\u7d9a\u3057\u307e\u3057\u305f 22 | 32101=\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u5207\u65ad\u3057\u307e\u3057\u305f 23 | 32102=\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306f\u73fe\u5728\u5207\u65ad\u4e2d\u3067\u3059 24 | 32103=\u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3067\u304d\u307e\u305b\u3093 25 | 32104=\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306f\u63a5\u7d9a\u3055\u308c\u3066\u3044\u307e\u305b\u3093 26 | 32105=\u6307\u5b9a\u3055\u308c\u305f SocketFactory \u30bf\u30a4\u30d7\u306f\u30d6\u30ed\u30fc\u30ab\u30fc URI \u3068\u4e00\u81f4\u3057\u307e\u305b\u3093 27 | 32106=SSL \u69cb\u6210\u30a8\u30e9\u30fc\u3067\u3059 28 | 32107=\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u30fb\u30e1\u30bd\u30c3\u30c9\u304b\u3089\u306e\u5207\u65ad\u306f\u8a31\u53ef\u3055\u308c\u307e\u305b\u3093 29 | 32108=\u8b58\u5225\u3055\u308c\u3066\u3044\u306a\u3044\u30d1\u30b1\u30c3\u30c8\u3067\u3059 30 | 32109=\u63a5\u7d9a\u55aa\u5931 31 | 32110=\u63a5\u7d9a\u51e6\u7406\u306f\u65e2\u306b\u9032\u884c\u4e2d\u3067\u3059 32 | 32111=\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u30af\u30ed\u30fc\u30ba\u3055\u308c\u307e\u3057\u305f 33 | 32200=\u30d1\u30fc\u30b7\u30b9\u30bf\u30f3\u30b9\u306f\u3059\u3067\u306b\u4f7f\u7528\u4e2d\u3067\u3059\u3002 34 | 32201=\u30c8\u30fc\u30af\u30f3\u306f\u65e2\u306b\u4f7f\u7528\u4e2d\u3067\u3059 35 | 32202=\u51e6\u7406\u4e2d\u306e\u30d1\u30d6\u30ea\u30c3\u30b7\u30e5\u304c\u591a\u3059\u304e\u307e\u3059 36 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSubscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal.wire; 13 | 14 | 15 | import java.io.ByteArrayOutputStream; 16 | import java.io.DataOutputStream; 17 | import java.io.IOException; 18 | 19 | import org.eclipse.paho.client.mqttv3.MqttException; 20 | import org.eclipse.paho.client.mqttv3.MqttMessage; 21 | 22 | 23 | /** 24 | * An on-the-wire representation of an MQTT SUBSCRIBE message. 25 | */ 26 | public class MqttSubscribe extends MqttWireMessage { 27 | private String[] names; 28 | private int[] qos; 29 | 30 | /** 31 | * Constructor for on an on hte wire MQTT subscribe message 32 | * @param names - one or more topics to subscribe to 33 | * @param qos - the max QOS that each each topic will be subscribed at 34 | */ 35 | public MqttSubscribe(String[] names, int[] qos) { 36 | super(MqttWireMessage.MESSAGE_TYPE_SUBSCRIBE); 37 | this.names = names; 38 | this.qos = qos; 39 | 40 | if (names.length != qos.length) { 41 | throw new IllegalArgumentException(); 42 | } 43 | 44 | for (int i=0;iSimpleFormatter object.
19 | */
20 | public SimpleLogFormatter() {
21 | super();
22 | }
23 |
24 | /**
25 | * Format the logrecord as a single line with well defined columns.
26 | */
27 | public String format(LogRecord r) {
28 | StringBuffer sb = new StringBuffer();
29 | sb.append(r.getLevel().getName()+"\t");
30 | sb.append(MessageFormat.format("{0, date, yy-MM-dd} {0, time, kk:mm:ss.SSSS} ",
31 | new Object[] { new Date(r.getMillis()) })+"\t");
32 | String cnm = r.getSourceClassName();
33 | String cn="";
34 | if (cnm != null) {
35 | int cnl = cnm.length();
36 | if (cnl>20) {
37 | cn = r.getSourceClassName().substring(cnl-19);
38 | } else {
39 | char sp[] = {' '};
40 | StringBuffer sb1= new StringBuffer().append(cnm);
41 | cn = sb1.append(sp,0, 1).toString();
42 | }
43 | }
44 | sb.append(cn+"\t").append(" ");
45 | sb.append(left(r.getSourceMethodName(),23,' ')+"\t");
46 | sb.append(r.getThreadID()+"\t");
47 | sb.append(formatMessage(r)).append(ls);
48 | if (null != r.getThrown()) {
49 | sb.append("Throwable occurred: ");
50 | Throwable t = r.getThrown();
51 | PrintWriter pw = null;
52 | try {
53 | StringWriter sw = new StringWriter();
54 | pw = new PrintWriter(sw);
55 | t.printStackTrace(pw);
56 | sb.append(sw.toString());
57 | } finally {
58 | if (pw != null) {
59 | try {
60 | pw.close();
61 | } catch (Exception e) {
62 | // ignore
63 | }
64 | }
65 | }
66 | }
67 | return sb.toString();
68 | }
69 |
70 | /**
71 | * Left justify a string.
72 | *
73 | * @param s the string to justify
74 | * @param width the field width to justify within
75 | * @param fillChar the character to fill with
76 | *
77 | * @return the justified string.
78 | */
79 | public static String left(String s, int width, char fillChar) {
80 | if (s.length() >= width) {
81 | return s;
82 | }
83 | StringBuffer sb = new StringBuffer(width);
84 | sb.append(s);
85 | for (int i = width - s.length(); --i >= 0;) {
86 | sb.append(fillChar);
87 | }
88 | return sb.toString();
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/persist/MemoryPersistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.persist;
13 |
14 | import java.util.Enumeration;
15 | import java.util.Hashtable;
16 |
17 | import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
18 | import org.eclipse.paho.client.mqttv3.MqttPersistable;
19 | import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
20 |
21 | /**
22 | * Persistence that uses memory
23 | *
24 | * In cases where reliability is not required across client or device
25 | * restarts memory this memory peristence can be used. In cases where
26 | * reliability is required like when clean session is set to false
27 | * then a non-volatile form of persistence should be used.
28 | *
29 | */
30 | public class MemoryPersistence implements MqttClientPersistence {
31 |
32 | private Hashtable data;
33 |
34 | /* (non-Javadoc)
35 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#close()
36 | */
37 | public void close() throws MqttPersistenceException {
38 | data.clear();
39 | }
40 |
41 | /* (non-Javadoc)
42 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#keys()
43 | */
44 | public Enumeration keys() throws MqttPersistenceException {
45 | return data.keys();
46 | }
47 |
48 | /* (non-Javadoc)
49 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#get(java.lang.String)
50 | */
51 | public MqttPersistable get(String key) throws MqttPersistenceException {
52 | return (MqttPersistable)data.get(key);
53 | }
54 |
55 | /* (non-Javadoc)
56 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#open(java.lang.String, java.lang.String)
57 | */
58 | public void open(String clientId, String serverURI) throws MqttPersistenceException {
59 | this.data = new Hashtable();
60 | }
61 |
62 | /* (non-Javadoc)
63 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#put(java.lang.String, org.eclipse.paho.client.mqttv3.MqttPersistable)
64 | */
65 | public void put(String key, MqttPersistable persistable) throws MqttPersistenceException {
66 | data.put(key, persistable);
67 | }
68 |
69 | /* (non-Javadoc)
70 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#remove(java.lang.String)
71 | */
72 | public void remove(String key) throws MqttPersistenceException {
73 | data.remove(key);
74 | }
75 |
76 | /* (non-Javadoc)
77 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#clear()
78 | */
79 | public void clear() throws MqttPersistenceException {
80 | data.clear();
81 | }
82 |
83 | /* (non-Javadoc)
84 | * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#containsKey(java.lang.String)
85 | */
86 | public boolean containsKey(String key) throws MqttPersistenceException {
87 | return data.containsKey(key);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/FileLock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal;
13 | /**
14 | * FileLock - used to obtain a lock that can be used to prevent other MQTT clients
15 | * using the same persistent store. If the lock is already held then an exception
16 | * is thrown.
17 | *
18 | * Some Java runtimes such as JME MIDP do not support file locking or even
19 | * the Java classes that support locking. The class is coded to both compile
20 | * and work on all Java runtimes. In Java runtimes that do not support
21 | * locking it will look as though a lock has been obtained but in reality
22 | * no lock has been obtained.
23 | */
24 | import java.io.File;
25 | import java.io.IOException;
26 | import java.io.RandomAccessFile;
27 | import java.lang.reflect.Method;
28 |
29 | public class FileLock {
30 | private File lockFile;
31 | private RandomAccessFile file;
32 | private Object fileLock;
33 |
34 | /**
35 | * Creates an NIO FileLock on the specified file if on a suitable Java runtime.
36 | * @param clientDir the a File of the directory to contain the lock file.
37 | * @param lockFilename name of the the file to lock
38 | * @throws Exception if the lock could not be obtained for any reason
39 | */
40 | public FileLock(File clientDir, String lockFilename) throws Exception {
41 | // Create a file to obtain a lock on.
42 | lockFile = new File(clientDir,lockFilename);
43 | if (ExceptionHelper.isClassAvailable("java.nio.channels.FileLock")) {
44 | try {
45 | this.file = new RandomAccessFile(lockFile,"rw");
46 | Method m = file.getClass().getMethod("getChannel",new Class[]{});
47 | Object channel = m.invoke(file,new Object[]{});
48 | m = channel.getClass().getMethod("tryLock",new Class[]{});
49 | this.fileLock = m.invoke(channel, new Object[]{});
50 | } catch(NoSuchMethodException nsme) {
51 | this.fileLock = null;
52 | } catch(IllegalArgumentException iae) {
53 | this.fileLock = null;
54 | } catch(IllegalAccessException iae) {
55 | this.fileLock = null;
56 | }
57 | if (fileLock == null) {
58 | // Lock not obtained
59 | release();
60 | throw new Exception("Problem obtaining file lock");
61 | }
62 | }
63 | }
64 |
65 | /**
66 | * Releases the lock.
67 | */
68 | public void release() {
69 | try {
70 | if (fileLock != null) {
71 | Method m = fileLock.getClass().getMethod("release",new Class[]{});
72 | m.invoke(fileLock, new Object[]{});
73 | fileLock = null;
74 | }
75 | } catch (Exception e) {
76 | // Ignore exceptions
77 | }
78 | if (file != null) {
79 | try {
80 | file.close();
81 | } catch (IOException e) {
82 | }
83 | file = null;
84 | }
85 |
86 | if (lockFile != null && lockFile.exists()) {
87 | lockFile.delete();
88 | }
89 | lockFile = null;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/LocalNetworkModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3.internal;
13 |
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 | import java.io.OutputStream;
17 | import java.lang.reflect.Method;
18 |
19 | import org.eclipse.paho.client.mqttv3.MqttException;
20 |
21 |
22 | /**
23 | * Special comms class that allows an MQTT client to use a non TCP / optimised
24 | * mechanism to talk to an MQTT server when running in the same JRE instance as the
25 | * MQTT server.
26 | *
27 | * This class checks for the existence of the optimised comms adatper class i.e. the one
28 | * that provides the optimised communication mechanism. If not available the request
29 | * to connect using the optimised mechanism is rejected.
30 | *
31 | * The only known server that implements this is the microbroker:- an MQTT server that
32 | * ships with a number of IBM products.
33 | */
34 | public class LocalNetworkModule implements NetworkModule {
35 | private Class LocalListener;
36 | private String brokerName;
37 | private Object localAdapter;
38 |
39 | public LocalNetworkModule(String brokerName) {
40 | this.brokerName = brokerName;
41 | }
42 |
43 | public void start() throws IOException, MqttException{
44 | if (!ExceptionHelper.isClassAvailable("com.ibm.mqttdirect.modules.local.bindings.LocalListener")) {
45 | throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_SERVER_CONNECT_ERROR);
46 | }
47 | try {
48 | LocalListener = Class.forName("com.ibm.mqttdirect.modules.local.bindings.LocalListener");
49 | Method connect_m = LocalListener.getMethod("connect", new Class[]{ java.lang.String.class });
50 | localAdapter = connect_m.invoke(null,new Object[]{ brokerName });
51 | } catch(Exception e) {
52 | }
53 | if(localAdapter == null) {
54 | throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_SERVER_CONNECT_ERROR);
55 | }
56 | }
57 |
58 | public InputStream getInputStream() throws IOException {
59 | InputStream stream = null;
60 | try {
61 | Method m = LocalListener.getMethod("getClientInputStream",new Class[]{});
62 | stream = (InputStream)m.invoke(this.localAdapter,new Object[]{});
63 | } catch(Exception e) {
64 | }
65 | return stream;
66 | }
67 |
68 | public OutputStream getOutputStream() throws IOException {
69 | OutputStream stream = null;
70 | try {
71 | Method m = LocalListener.getMethod("getClientOutputStream",new Class[]{});
72 | stream = (OutputStream)m.invoke(this.localAdapter,new Object[]{});
73 | } catch(Exception e) {
74 | }
75 | return stream;
76 | }
77 |
78 | public void stop() throws IOException {
79 | if (localAdapter != null) {
80 | try {
81 | Method m = LocalListener.getMethod("close",new Class[]{});
82 | m.invoke(this.localAdapter,new Object[]{});
83 | } catch(Exception e) {
84 | }
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttExpand.java:
--------------------------------------------------------------------------------
1 | package org.eclipse.paho.client.mqttv3.internal.wire;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 |
7 | import org.eclipse.paho.client.mqttv3.MqttException;
8 |
9 | public class MqttExpand extends MqttWireMessage{
10 | public static final byte CMD_GET_ALIAS = 1;
11 | public static final byte CMD_GET_ALIAS_ACK = 2;
12 | public static final byte CMD_GET_TOPIC = 3;
13 | public static final byte CMD_GET_TOPIC_ACK = 4;
14 | public static final byte CMD_GET_ALIASLIST = 5;
15 | public static final byte CMD_GET_ALIASLIST_ACK = 6;
16 | public static final byte CMD_PUBLISH = 7;
17 | public static final byte CMD_PUBLISH_ACK = 8;
18 | public static final byte CMD_GET_STATUS = 9;
19 | public static final byte CMD_GET_STATUS_ACK = 10;
20 | public static final byte CMD_GET_STATUS_V2 = 19;
21 | public static final byte CMD_GET_STATUS_ACK_V2 = 20;
22 | public static final byte CMD_GET_TOPIC_V2 = 13;
23 | public static final byte CMD_GET_TOPIC_ACK_V2 = 14;
24 | public static final byte CMD_GET_ALIASLIST_V2 = 15;
25 | public static final byte CMD_GET_ALIASLIST_ACK_V2 = 16;
26 |
27 | public MqttExpand () {
28 | super(MqttWireMessage.MESSAGE_TYPE_EXPAND);
29 | }
30 |
31 | public MqttExpand (String topics, byte command) throws MqttException {
32 | super(MqttWireMessage.MESSAGE_TYPE_EXPAND);
33 | this.command = command;
34 | topic = topics;
35 | setPayload();
36 | }
37 | protected byte[] encodedPayload = null;
38 | protected String topic = null;
39 | protected byte command ;
40 |
41 | @Override
42 | protected byte[] getVariableHeader() throws MqttException {
43 | try {
44 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
45 | DataOutputStream dos = new DataOutputStream(baos);
46 |
47 | //****change the version code . write by Quentin***//
48 | //********************for massage id refactor******//
49 | //dos.writeShort(msgId);
50 | dos.writeLong(msgId);
51 | //*************************************************//
52 |
53 | dos.flush();
54 | return baos.toByteArray();
55 | }
56 | catch (IOException ex) {
57 | throw new MqttException(ex);
58 | }
59 | }
60 |
61 | public boolean isMessageIdRequired() {
62 | // all publishes require a message ID as it's used as the key to the token store
63 | return true;
64 | }
65 |
66 |
67 |
68 | @Override
69 | public byte[] getPayload() throws MqttException {
70 | return encodedPayload;
71 | }
72 |
73 |
74 |
75 | public void setPayload() throws MqttException {
76 | try {
77 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
78 | DataOutputStream dos = new DataOutputStream(baos);
79 | dos.writeByte(command);
80 | if(null != topic) {
81 | byte[] encodedString = topic.getBytes("UTF-8");
82 | dos.writeChar(topic.length());
83 | dos.write(encodedString);
84 | } else {
85 | dos.writeChar(0);
86 | }
87 |
88 | //*************************************************//
89 |
90 | dos.flush();
91 | encodedPayload = baos.toByteArray();
92 | }
93 | catch (IOException ex) {
94 | throw new MqttException(ex);
95 | }
96 | }
97 |
98 | @Override
99 | protected byte getMessageInfo() {
100 | return (byte) 0;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/org/eclipse/paho/client/mqttv3/MqttCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009, 2012 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | *
9 | * Contributors:
10 | * Dave Locke - initial API and implementation and/or initial documentation
11 | */
12 | package org.eclipse.paho.client.mqttv3;
13 |
14 |
15 | /**
16 | * Enables an application to be notified when asynchronous
17 | * events related to the client occur.
18 | * Classes implementing this interface
19 | * can be registered on both types of client: {@link IMqttClient#setCallback(MqttCallback)}
20 | * and {@link IMqttAsyncClient#setCallback(MqttCallback)}
21 | */
22 | public interface MqttCallback {
23 | /**
24 | * This method is called when the connection to the server is lost.
25 | *
26 | * @param cause the reason behind the loss of connection.
27 | */
28 | public void connectionLost(Throwable cause);
29 |
30 | /**
31 | * This method is called when a message arrives from the server.
32 | *
33 | * 34 | * This method is invoked synchronously by the MQTT client. An 35 | * acknowledgement is not sent back to the server until this 36 | * method returns cleanly.
37 | *
38 | * If an implementation of this method throws an Exception, then the
39 | * client will be shut down. When the client is next re-connected, any QoS
40 | * 1 or 2 messages will be redelivered by the server.
42 | * Any additional messages which arrive while an 43 | * implementation of this method is running, will build up in memory, and 44 | * will then back up on the network.
45 | *46 | * If an application needs to persist data, then it 47 | * should ensure the data is persisted prior to returning from this method, as 48 | * after returning from this method, the message is considered to have been 49 | * delivered, and will not be reproducable.
50 | *51 | * It is possible to send a new message within an implementation of this callback 52 | * (for example, a response to this message), but the implementation must not 53 | * disconnect the client, as it will be impossible to send an acknowledgement for 54 | * the message being processed, and a deadlock will occur.
55 | * 56 | * @param topic name of the topic on the message was published to 57 | * @param message the actual message. 58 | * @throws Exception if a terminal error has occurred, and the client should be 59 | * shut down. 60 | */ 61 | public void messageArrived(String topic, MqttMessage message) throws Exception; 62 | 63 | 64 | 65 | public void presenceMessageArrived(String topic, MqttMessage message) throws Exception; 66 | 67 | /** 68 | * Called when delivery for a message has been completed, and all 69 | * acknowledgements have been received. For QOS 0 messages it is 70 | * called once the message has been handed to the network for 71 | * delivery. For QOS 1 it is called when PUBACK is received and 72 | * for QOS 2 when PUBCOMP is received. The token will be the same 73 | * token as that returned when the message was published. 74 | * 75 | * @param token the delivery token associated with the message. 76 | */ 77 | public void deliveryComplete(IMqttDeliveryToken token); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/MqttTopic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3; 13 | 14 | import org.eclipse.paho.client.mqttv3.internal.ClientComms; 15 | import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish; 16 | 17 | /** 18 | * Represents a topic destination, used for publish/subscribe messaging. 19 | */ 20 | public class MqttTopic { 21 | 22 | private ClientComms comms; 23 | private String name; 24 | 25 | public MqttTopic(String name, ClientComms comms) { 26 | this.comms = comms; 27 | this.name = name; 28 | } 29 | 30 | /** 31 | * Publishes a message on the topic. This is a convenience method, which will 32 | * create a new {@link MqttMessage} object with a byte array payload and the 33 | * specified QoS, and then publish it. All other values in the 34 | * message will be set to the defaults. 35 | 36 | * @param payload the byte array to use as the payload 37 | * @param qos the Quality of Service. Valid values are 0, 1 or 2. 38 | * @param retained whether or not this message should be retained by the server. 39 | * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. 40 | * @see #publish(MqttMessage) 41 | * @see MqttMessage#setQos(int) 42 | * @see MqttMessage#setRetained(boolean) 43 | */ 44 | public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { 45 | MqttMessage message = new MqttMessage(payload); 46 | message.setQos(qos); 47 | message.setRetained(retained); 48 | return this.publish(message); 49 | } 50 | 51 | /** 52 | * Publishes the specified message to this topic, but does not wait for delivery 53 | * of the message to complete. The returned {@link MqttDeliveryToken token} can be used 54 | * to track the delivery status of the message. Once this method has 55 | * returned cleanly, the message has been accepted for publication by the 56 | * client. Message delivery will be completed in the background when a connection 57 | * is available. 58 | * 59 | * @param message the message to publish 60 | * @return an MqttDeliveryToken for tracking the delivery of the message 61 | */ 62 | public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException { 63 | MqttDeliveryToken token = new MqttDeliveryToken(comms.getClient().getClientId()); 64 | token.setMessage(message); 65 | comms.sendNoWait(createPublish(message), token); 66 | token.internalTok.waitUntilSent(); 67 | return token; 68 | } 69 | 70 | /** 71 | * Returns the name of the queue or topic. 72 | * 73 | * @return the name of this destination. 74 | */ 75 | public String getName() { 76 | return name; 77 | } 78 | 79 | /** 80 | * Create a PUBLISH packet from the specified message. 81 | */ 82 | private MqttPublish createPublish(MqttMessage message) { 83 | return new MqttPublish(this.getName(), message); 84 | } 85 | 86 | /** 87 | * Returns a string representation of this topic. 88 | * @return a string representation of this topic. 89 | */ 90 | public String toString() { 91 | return getName(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/nls/messages_ru.properties: -------------------------------------------------------------------------------- 1 | #/* 2 | # * Copyright (c) 2009, 2012 IBM Corp. 3 | # * 4 | # * All rights reserved. This program and the accompanying materials 5 | # * are made available under the terms of the Eclipse Public License v1.0 6 | # * which accompanies this distribution, and is available at 7 | # * http://www.eclipse.org/legal/epl-v10.html 8 | # * 9 | # * Contributors: 10 | # * Dave Locke - initial API and implementation and/or initial documentation 11 | # */ 12 | # NLS_MESSAGEFORMAT_VAR 13 | # NLS_ENCODING=UNICODE 14 | 1=\u041d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 15 | 2=\u041d\u0435\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0439 \u0418\u0414 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 16 | 3=\u041f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d 17 | 4=\u041e\u0448\u0438\u0431\u043e\u0447\u043d\u043e\u0435 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c 18 | 5=\u041d\u0435\u0442 \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 19 | 6=\u041d\u0435\u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 20 | 32000=\u0422\u0430\u043c-\u0430\u0443\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 21 | 32100=\u041a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d 22 | 32101=\u041a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d 23 | 32102=\u041a\u043b\u0438\u0435\u043d\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f 24 | 32103=\u041d\u0435 \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 25 | 32104=\u041a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d 26 | 32105=\u0422\u0438\u043f SocketFactory \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 URI \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u0430 27 | 32106=\u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 SSL 28 | 32107=\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 29 | 32108=\u041d\u0435\u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 30 | 32109=\u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043d\u043e 31 | 32110=\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 32 | 32111=\u041a\u043b\u0438\u0435\u043d\u0442 \u0437\u0430\u043a\u0440\u044b\u0442 33 | 32200=\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f 34 | 32201=\u041c\u0430\u0440\u043a\u0435\u0440 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f 35 | 32202=\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 36 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/security/SimpleBase64Encoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal.security; 13 | 14 | public class SimpleBase64Encoder { 15 | 16 | // if this string is changed, then the decode method must also be adapted. 17 | private final static String PWDCHARS_STRING = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 18 | private final static char[] PWDCHARS_ARRAY = PWDCHARS_STRING.toCharArray(); 19 | 20 | /** 21 | * Encodes an array of byte into a string of printable ASCII characters 22 | * using a base-64 encoding. 23 | * @param bytes The array of bytes to e encoded 24 | * @return The encoded array. 25 | */ 26 | public static String encode(byte[] bytes) { 27 | // Allocate a string buffer. 28 | int len = bytes.length; 29 | final StringBuffer encoded = new StringBuffer((len+2)/3*4); 30 | int i=0; 31 | int j=len; 32 | while(j>=3){ 33 | encoded.append(to64((((bytes[i] & 0xff) << 16) 34 | | (int) ((bytes[i+1] & 0xff) << 8) | (int) (bytes[i+2] & 0xff)),4)); 35 | i+=3; 36 | j-=3; 37 | } 38 | // j==2 | j==1 | j==0 39 | if(j==2) { 40 | // there is a rest of 2 bytes. This encodes into 3 chars. 41 | encoded.append(to64(((bytes[i] &0xff)<<8) | ((bytes[i+1] & 0xff)),3)); 42 | } 43 | if(j==1) { 44 | // there is a rest of 1 byte. This encodes into 1 char. 45 | encoded.append(to64(((bytes[i] & 0xff)),2)); 46 | } 47 | return encoded.toString(); 48 | } 49 | 50 | public static byte[] decode(String string) { 51 | byte[] encoded=string.getBytes(); 52 | int len=encoded.length; 53 | byte[] decoded=new byte[len*3/4]; 54 | int i=0; 55 | int j=len; 56 | int k=0; 57 | while(j>=4) { 58 | long d=from64(encoded, i, 4); 59 | j-=4; 60 | i+=4; 61 | for(int l=2;l>=0;l--) { 62 | decoded[k+l]=(byte) (d & 0xff); 63 | d=d >>8; 64 | } 65 | k+=3; 66 | } 67 | // j==3 | j==2 68 | if(j==3) { 69 | long d=from64(encoded, i, 3); 70 | for(int l=1;l>=0;l--) { 71 | decoded[k+l]=(byte) (d & 0xff); 72 | d=d >>8; 73 | } 74 | } 75 | if(j==2) { 76 | long d=from64(encoded, i, 2); 77 | decoded[k]=(byte) (d & 0xff); 78 | } 79 | return decoded; 80 | } 81 | 82 | /* the core conding routine. Translates an input integer into 83 | * a string of the given length.*/ 84 | private final static String to64(long input, int size) { 85 | final StringBuffer result = new StringBuffer(size); 86 | while (size > 0) { 87 | size--; 88 | result.append(PWDCHARS_ARRAY[((int) (input & 0x3f))]); 89 | input = input >> 6; 90 | } 91 | return result.toString(); 92 | } 93 | 94 | /* 95 | * The reverse operation of to64 96 | */ 97 | private final static long from64(byte[] encoded, int idx, int size) { 98 | long res=0; 99 | int f=0; 100 | while(size>0) { 101 | size--; 102 | long r=0; 103 | // convert encoded[idx] back into a 6-bit value. 104 | byte d=encoded[idx++]; 105 | if(d=='/') { 106 | r=1; 107 | } 108 | if(d>='0' && d<='9') { 109 | r=2+d-'0'; 110 | } 111 | if(d>='A' && d<='Z') { 112 | r=12+d-'A'; 113 | } 114 | if(d>='a' && d<='z') { 115 | r=38+d-'a'; 116 | } 117 | res=res+((long)r << f); 118 | f+=6; 119 | } 120 | return res; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/TCPNetworkModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.internal; 13 | 14 | 15 | import java.io.IOException; 16 | import java.io.InputStream; 17 | import java.io.OutputStream; 18 | import java.net.ConnectException; 19 | import java.net.InetSocketAddress; 20 | import java.net.Socket; 21 | import java.net.SocketAddress; 22 | 23 | import javax.net.SocketFactory; 24 | 25 | import org.eclipse.paho.client.mqttv3.MqttException; 26 | import org.eclipse.paho.client.mqttv3.logging.Logger; 27 | import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; 28 | 29 | /** 30 | * A network module for connecting over TCP. 31 | */ 32 | public class TCPNetworkModule implements NetworkModule { 33 | protected Socket socket; 34 | private SocketFactory factory; 35 | private String host; 36 | private int port; 37 | private int conTimeout; 38 | 39 | final static String className = TCPNetworkModule.class.getName(); 40 | Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT,className); 41 | 42 | /** 43 | * Constructs a new TCPNetworkModule using the specified host and 44 | * port. The supplied SocketFactory is used to supply the network 45 | * socket. 46 | */ 47 | public TCPNetworkModule(SocketFactory factory, String host, int port, String resourceContext) { 48 | log.setResourceName(resourceContext); 49 | this.factory = factory; 50 | this.host = host; 51 | this.port = port; 52 | 53 | } 54 | 55 | /** 56 | * Starts the module, by creating a TCP socket to the server. 57 | */ 58 | public void start() throws IOException, MqttException { 59 | final String methodName = "start"; 60 | try { 61 | // InetAddress localAddr = InetAddress.getLocalHost(); 62 | // socket = factory.createSocket(host, port, localAddr, 0); 63 | // @TRACE 252=connect to host {0} port {1} timeout {2} 64 | log.fine(className,methodName, "252", new Object[] {host, new Integer(port), new Long(conTimeout*1000)}); 65 | SocketAddress sockaddr = new InetSocketAddress(host, port); 66 | socket = factory.createSocket(); 67 | socket.connect(sockaddr, conTimeout*1000); 68 | 69 | // SetTcpNoDelay was originally set ot true disabling Nagle's algorithm. 70 | // This should not be required. 71 | // socket.setTcpNoDelay(true); // TCP_NODELAY on, which means we do not use Nagle's algorithm 72 | } 73 | catch (ConnectException ex) { 74 | //@TRACE 250=Failed to create TCP socket 75 | log.fine(className,methodName,"250",null,ex); 76 | throw new MqttException(MqttException.REASON_CODE_SERVER_CONNECT_ERROR, ex); 77 | } 78 | } 79 | 80 | public InputStream getInputStream() throws IOException { 81 | return socket.getInputStream(); 82 | } 83 | 84 | public OutputStream getOutputStream() throws IOException { 85 | return socket.getOutputStream(); 86 | } 87 | 88 | /** 89 | * Stops the module, by closing the TCP socket. 90 | */ 91 | public void stop() throws IOException { 92 | if (socket != null) { 93 | try { 94 | socket.close(); 95 | } catch(AssertionError e){ 96 | } 97 | } 98 | 99 | } 100 | 101 | /** 102 | * Set the maximum time to wait for a socket to be established 103 | * @param timeout 104 | */ 105 | public void setConnectTimeout(int timeout) { 106 | this.conTimeout = timeout; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/MqttPersistable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3; 13 | 14 | /** 15 | * Represents an object used to pass data to be persisted across the 16 | * {@link org.eclipse.paho.client.mqttv3.MqttClientPersistence MqttClientPersistence} 17 | * interface. 18 | *19 | * When data is passed across the interface the header and payload are 20 | * separated, so that unnecessary message copies may be avoided. 21 | * For example, if a 10 MB payload was published it would be inefficient 22 | * to create a byte array a few bytes larger than 10 MB and copy the 23 | * MQTT message header and payload into a contiguous byte array.
24 | *25 | * When the request to persist data is made a separate byte array and offset 26 | * is passed for the header and payload. Only the data between 27 | * offset and length need be persisted. 28 | * So for example, a message to be persisted consists of a header byte 29 | * array starting at offset 1 and length 4, plus a payload byte array 30 | * starting at offset 30 and length 40000. There are three ways in which 31 | * the persistence implementation may return data to the client on 32 | * recovery: 33 | *
22 | * If the methods defined throw the MqttPersistenceException then the state of the data persisted 23 | * should remain as prior to the method being called. For example, if {@link #put(String, MqttPersistable)} 24 | * throws an exception at any point then the data will be assumed to not be in the persistent store. 25 | * Similarly if {@link #remove(String)} throws an exception then the data will be 26 | * assumed to still be held in the persistent store.
27 | *28 | * It is up to the persistence interface to log any exceptions or error information 29 | * which may be required when diagnosing a persistence failure.
30 | */ 31 | public interface MqttClientPersistence { 32 | /** 33 | * Initialise the persistent store. 34 | * If a persistent store exists for this client ID then open it, otherwise 35 | * create a new one. If the persistent store is already open then just return. 36 | * An application may use the same client ID to connect to many different 37 | * servers, so the client ID in conjunction with the 38 | * connection will uniquely identify the persistence store required. 39 | * 40 | * @param clientId The client for which the persistent store should be opened. 41 | * @param serverURI The connection string as specified when the MQTT client instance was created. 42 | * @throws MqttPersistenceException if there was a problem opening the persistent store. 43 | */ 44 | public void open(String clientId, String serverURI) throws MqttPersistenceException; 45 | 46 | /** 47 | * Close the persistent store that was previously opened. 48 | * This will be called when a client application disconnects from the broker. 49 | * @throws MqttPersistenceException 50 | */ 51 | public void close() throws MqttPersistenceException; 52 | 53 | /** 54 | * Puts the specified data into the persistent store. 55 | * @param key the key for the data, which will be used later to retrieve it. 56 | * @param persistable the data to persist 57 | * @throws MqttPersistenceException if there was a problem putting the data 58 | * into the persistent store. 59 | */ 60 | public void put(String key, MqttPersistable persistable) throws MqttPersistenceException; 61 | 62 | /** 63 | * Gets the specified data out of the persistent store. 64 | * @param key the key for the data, which was used when originally saving it. 65 | * @return the un-persisted data 66 | * @throws MqttPersistenceException if there was a problem getting the data 67 | * from the persistent store. 68 | */ 69 | public MqttPersistable get(String key) throws MqttPersistenceException; 70 | 71 | /** 72 | * Remove the data for the specified key. 73 | */ 74 | public void remove(String key) throws MqttPersistenceException; 75 | 76 | /** 77 | * Returns an Enumeration over the keys in this persistent data store. 78 | * @return an enumeration of {@link String} objects. 79 | */ 80 | public Enumeration keys() throws MqttPersistenceException; 81 | 82 | /** 83 | * Clears persistence, so that it no longer contains any persisted data. 84 | */ 85 | public void clear() throws MqttPersistenceException; 86 | 87 | /** 88 | * Returns whether or not data is persisted using the specified key. 89 | * @param key the key for data, which was used when originally saving it. 90 | */ 91 | public boolean containsKey(String key) throws MqttPersistenceException; 92 | } 93 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/wire/MqttExpandPublish.java: -------------------------------------------------------------------------------- 1 | package org.eclipse.paho.client.mqttv3.internal.wire; 2 | 3 | 4 | 5 | import io.yunba.java.util.MqttUtil; 6 | 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.DataOutputStream; 9 | import java.io.IOException; 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.Iterator; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | import org.codehaus.jettison.json.JSONObject; 17 | import org.eclipse.paho.client.mqttv3.MqttException; 18 | ; 19 | 20 | public class MqttExpandPublish extends MqttExpand { 21 | public MqttExpandPublish () { 22 | super(); 23 | } 24 | 25 | public String msg ; 26 | public JSONObject opts; 27 | public MqttExpandPublish (String topics, String msg, byte command, JSONObject opts) throws MqttException { 28 | super(); 29 | this.command = command; 30 | this.opts = opts; 31 | this.msg = msg; 32 | topic = topics; 33 | setPayload(); 34 | } 35 | 36 | 37 | public void setPayload() throws MqttException { 38 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 39 | DataOutputStream dos = new DataOutputStream(baos); 40 | try { 41 | dos.writeByte(command); 42 | byte[] tlv = getTLVBytes(opts, topic, msg); 43 | if (null != tlv) { 44 | dos.writeChar(tlv.length); 45 | dos.write(tlv); 46 | } else { 47 | dos.writeChar(0); 48 | } 49 | 50 | // *************************************************// 51 | 52 | dos.flush(); 53 | encodedPayload = baos.toByteArray(); 54 | } catch (Exception ex) { 55 | throw new MqttException(-105,ex); 56 | } finally { 57 | try { 58 | dos.close(); 59 | baos.close(); 60 | } catch (Exception e) { 61 | 62 | } 63 | } 64 | } 65 | 66 | 67 | public byte[] getTLVBytes(JSONObject opts, String topic, String msg) { 68 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 69 | DataOutputStream dos = new DataOutputStream(baos); 70 | try { 71 | if (!MqttUtil.isEmpty(topic)) { 72 | dos.writeByte(0); 73 | dos.writeChar(topic.getBytes().length); 74 | dos.write(topic.getBytes("UTF-8")); 75 | } 76 | 77 | if (!MqttUtil.isEmpty(msg)) { 78 | dos.writeByte(1); 79 | dos.writeChar(msg.getBytes().length); 80 | dos.write(msg.getBytes("UTF-8")); 81 | } 82 | if (null != opts && opts.length() > 0) { 83 | Iterator> keys = opts.keys(); 84 | 85 | while (keys.hasNext()) { 86 | String key = (String) keys.next(); 87 | String value = opts.getString(key); 88 | int keyToInt = getKey(key); 89 | if (keyToInt != -1) { 90 | dos.writeByte(keyToInt); 91 | dos.writeChar(value.getBytes().length); 92 | dos.write(value.getBytes("UTF-8")); 93 | } 94 | } 95 | } 96 | dos.flush(); 97 | 98 | return baos.toByteArray(); 99 | } catch (Exception ex) { 100 | //YLogger.e("MqttExpandPublish", "", ex); 101 | System.err.println(ex.getMessage()); 102 | return null; 103 | } finally { 104 | try { 105 | dos.close(); 106 | baos.close(); 107 | } catch (Exception e) { 108 | 109 | } 110 | } 111 | } 112 | 113 | 114 | // 0: "topics", 115 | // 1: "payload", 116 | // 2: "platform", 117 | // 3: "time_to_live", 118 | // 4: "time_delay", 119 | // 5: "location", 120 | // 6: "qos", 121 | // 7: "apn_json", 122 | private static MapWhen using the asynchronous/non-blocking MQTT programming interface all 23 | * methods /operations that take any time and in particular those that involve 24 | * any network operation return control to the caller immediately. The operation 25 | * then proceeds to run in the background so as not to block the invoking thread. 26 | * An IMqttToken is used to track the state of the operation. An application can use the 27 | * token to wait for an operation to complete. A token is passed to callbacks 28 | * once the operation completes and provides context linking it to the original 29 | * request. A token is associated with a single operation.
30 | *
31 | * An action is in progress until either: 32 | *
The timeout specifies the maximum time it will block for. If the action 54 | * completes before the timeout then control returns immediately, if not 55 | * it will block until the timeout expires.
56 | *If the action being tracked fails or the timeout expires an exception will 57 | * be thrown. In the event of a timeout the action may complete after timeout. 58 | *
59 | * 60 | * @param timeout the maximum amount of time to wait for, in milliseconds. 61 | * @throws MqttException if there was a problem with the action associated with the token. 62 | */ 63 | public void waitForCompletion(long timeout) throws MqttException; 64 | 65 | /** 66 | * Returns whether or not the action has finished. 67 | *True will be returned both in the case where the action finished successfully 68 | * and in the case where it failed. If the action failed {@link #getException()} will 69 | * be non null. 70 | *
71 | */ 72 | public boolean isComplete(); 73 | 74 | /** 75 | * Returns an exception providing more detail if an operation failed 76 | *While an action in in progress and when an action completes successfully 77 | * null will be returned. Certain errors like timeout or shutting down will not 78 | * set the exception as the action has not failed or completed at that time 79 | *
80 | * @return exception may return an exception if the operation failed. Null will be 81 | * returned while action is in progress and if action completes successfully. 82 | */ 83 | public MqttException getException(); 84 | 85 | /** 86 | * Register a listener to be notified when an action completes. 87 | *Once a listener is registered it will be invoked when the action the token 88 | * is associated with either succeeds or fails. 89 | *
90 | * @param listener to be invoked once the action completes 91 | */ 92 | public void setActionCallback(IMqttActionListener listener); 93 | 94 | /** 95 | * Return the async listener for this token. 96 | * @return listener that is set on the token or null if a listener is not registered. 97 | */ 98 | public IMqttActionListener getActionCallback(); 99 | 100 | /** 101 | * Returns the MQTT client that is responsible for processing the asynchronous 102 | * action 103 | */ 104 | public IMqttAsyncClient getClient(); 105 | 106 | /** 107 | * Returns the topic string(s) for the action being tracked by this 108 | * token. If the action has not been initiated or the action has not 109 | * topic associated with it such as connect then null will be returned. 110 | * 111 | * @return the topic string(s) for the subscribe being tracked by this token or null 112 | */ 113 | public String[] getTopics(); 114 | 115 | /** 116 | * Store some context associated with an action. 117 | *Allows the caller of an action to store some context that can be 118 | * accessed from within the ActionListener associated with the action. This 119 | * can be useful when the same ActionListener is associated with multiple 120 | * actions
121 | * @param userContext to associate with an action 122 | */ 123 | public void setUserContext(Object userContext); 124 | 125 | /** 126 | * Retrieve the context associated with an action. 127 | *Allows the ActionListener associated with an action to retrieve any context 128 | * that was associated with the action when the action was invoked. If not 129 | * context was provided null is returned.
130 | 131 | * @return Object context associated with an action or null if there is none. 132 | */ 133 | public Object getUserContext(); 134 | 135 | /** 136 | * Returns the message ID of the message that is associated with the token. 137 | * A message id of zero will be returned for tokens associated with 138 | * connect, disconnect and ping operations as there can only ever 139 | * be one of these outstanding at a time. For other operations 140 | * the MQTT message id flowed over the network. 141 | */ 142 | public long getMessageId(); 143 | 144 | public String getAlias(); 145 | 146 | public void setAlias(String alias); 147 | 148 | public JSONObject getResult(); 149 | 150 | public void setResult(JSONObject result); 151 | 152 | } 153 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/logging/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2012 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | * 9 | * Contributors: 10 | * Dave Locke - initial API and implementation and/or initial documentation 11 | */ 12 | package org.eclipse.paho.client.mqttv3.logging; 13 | 14 | 15 | import java.lang.reflect.Method; 16 | 17 | /** 18 | * LoggerFactory will create a logger instance ready for use by the caller. 19 | * 20 | * The default is to create a logger that utilises the Java's built in 21 | * logging facility java.util.logging (JSR47). It is possible to override 22 | * this for systems where JSR47 is not available or an alternative logging 23 | * facility is needed by using setLogger and passing the the class name of 24 | * a logger that implements {@link Logger} 25 | */ 26 | import java.util.MissingResourceException; 27 | import java.util.ResourceBundle; 28 | /** 29 | * A factory that returns a logger for use by the MQTT client. 30 | * 31 | * The default log and trace facility uses Java's build in log facility:- 32 | * java.util.logging. For systems where this is not available or where 33 | * an alternative logging framework is required the logging facility can be 34 | * replaced using {@link org.eclipse.paho.client.mqttv3.logging.LoggerFactory#setLogger(String)} 35 | * which takes an implementation of the {@link org.eclipse.paho.client.mqttv3.logging.Logger} 36 | * interface. 37 | */ 38 | public class LoggerFactory { 39 | /** 40 | * Default message catalog. 41 | */ 42 | public final static String MQTT_CLIENT_MSG_CAT = "org.eclipse.paho.client.mqttv3.internal.nls.logcat"; 43 | private final static String className = LoggerFactory.class.getName(); 44 | 45 | private static String overrideloggerClassName = null; 46 | private static boolean logFlog = false; 47 | /** 48 | * Default logger that uses java.util.logging. 49 | */ 50 | private static String jsr47LoggerClassName = "org.eclipse.paho.client.mqttv3.logging.JSR47Logger"; 51 | 52 | /** 53 | * Find or create a logger for a named package/class. 54 | * If a logger has already been created with the given name 55 | * it is returned. Otherwise a new logger is created. By default a logger 56 | * that uses java.util.logging will be returned. 57 | * 58 | * @param messageCatalogName the resource bundle containing the logging messages. 59 | * @param loggerID unique name to identify this logger. 60 | * @return a suitable Logger. 61 | * @throws Exception 62 | */ 63 | public static Logger getLogger(String messageCatalogName, String loggerID) { 64 | if(!logFlog) return new MLogger(); 65 | String loggerClassName = overrideloggerClassName; 66 | Logger logger = null; 67 | 68 | if (loggerClassName == null) { 69 | loggerClassName = jsr47LoggerClassName; 70 | } 71 | // logger = getJSR47Logger(ResourceBundle.getBundle(messageCatalogName), loggerID, null) ; 72 | logger = getLogger(loggerClassName, ResourceBundle.getBundle(messageCatalogName), loggerID, null) ; 73 | // } 74 | 75 | if (null == logger) { 76 | throw new MissingResourceException("Error locating the logging class", className, loggerID); 77 | } 78 | 79 | return logger; 80 | } 81 | 82 | 83 | /** 84 | * Return an instance of a logger 85 | * 86 | * @param the class name of the load to load 87 | * @param messageCatalog the resource bundle containing messages 88 | * @param loggerID an identifier for the logger 89 | * @param resourceName a name or context to associate with this logger instance. 90 | * @return a ready for use logger 91 | */ 92 | private static Logger getLogger(String loggerClassName, ResourceBundle messageCatalog, String loggerID, String resourceName) { //, FFDC ffdc) { 93 | if(!logFlog) return new MLogger(); 94 | 95 | Logger logger = null; 96 | Class logClass = null; 97 | 98 | try { 99 | logClass = Class.forName(loggerClassName); 100 | } catch (NoClassDefFoundError ncdfe) { 101 | return null; 102 | } catch (ClassNotFoundException cnfe) { 103 | return null; 104 | } 105 | if (null != logClass) { 106 | // Now instantiate the log 107 | try { 108 | logger = (Logger)logClass.newInstance(); 109 | } catch (IllegalAccessException e) { 110 | return null; 111 | } catch (InstantiationException e) { 112 | return null; 113 | } catch (ExceptionInInitializerError e) { 114 | return null; 115 | } catch (SecurityException e) { 116 | return null; 117 | } 118 | logger.initialise(messageCatalog, loggerID, resourceName); 119 | } 120 | 121 | return logger; 122 | } 123 | 124 | /** 125 | * When run in JSR47, this allows access to the properties in the logging.properties 126 | * file. 127 | * If not run in JSR47, or the property isn't set, returns null. 128 | * @param name the property to return 129 | * @return the property value, or null if it isn't set or JSR47 isn't being used 130 | */ 131 | public static String getLoggingProperty(String name) { 132 | String result = null; 133 | try { 134 | // Hide behind reflection as java.util.logging is guaranteed to be 135 | // available. 136 | Class logManagerClass = Class.forName("java.util.logging.LogManager"); 137 | Method m1 = logManagerClass.getMethod("getLogManager", new Class[]{}); 138 | Object logManagerInstance = m1.invoke(null, null); 139 | Method m2 = logManagerClass.getMethod("getProperty", new Class[]{String.class}); 140 | result = (String)m2.invoke(logManagerInstance,new Object[]{name}); 141 | } catch(Exception e) { 142 | // Any error, assume JSR47 isn't available and return null 143 | result = null; 144 | } 145 | return result; 146 | } 147 | 148 | /** 149 | * Set the class name of the logger that the LoggerFactory will load 150 | * If not set getLogger will attempt to create a logger 151 | * appropriate for the platform. 152 | * @param loggerClassName - Logger implementation class name to use. 153 | */ 154 | public static void setLogger(String loggerClassName) { 155 | LoggerFactory.overrideloggerClassName = loggerClassName; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/org/eclipse/paho/client/mqttv3/internal/nls/logcat_pt_BR.properties: -------------------------------------------------------------------------------- 1 | # @start_prolog@ 2 | # ============================================================================ 3 | #