11/**
22 * STOMP Auth Client - A simple STOMP client for Java with authentication support
33 * Copyright © 2024 by Konrad Guzek <konrad@guzek.uk>
4-
4+ * <p>
55 * This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
77 * the Free Software Foundation, either version 3 of the License, or
88 * (at your option) any later version.
9-
9+ * <p>
1010 * This program is distributed in the hope that it will be useful,
1111 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313 * GNU General Public License for more details.
14-
14+ * <p>
1515 * You should have received a copy of the GNU General Public License
1616 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1717 */
@@ -41,7 +41,7 @@ public abstract class StompClient extends WebSocketClient {
4141
4242 /**
4343 * Initialises the client.
44- *
44+ *
4545 * @param serverUri the uri of the server
4646 * @param host the host to use to send the CONNECT STOMP frame
4747 */
@@ -51,7 +51,7 @@ public StompClient(URI serverUri, String host) {
5151
5252 /**
5353 * Initialises the client.
54- *
54+ *
5555 * @param serverUri the URI of the STOMP server
5656 * @param headers optional key-value header pairs to use during the initial
5757 * HTTP Upgrade request
@@ -63,7 +63,34 @@ public StompClient(URI serverUri, Map<String, String> headers, String host) {
6363
6464 /**
6565 * Initialises the client.
66- *
66+ *
67+ * @param serverUri the URI of the STOMP server
68+ * @param authType optional authentication method from `uk.guzek.sac.auth.*` to use during the initial
69+ * HTTP Upgrade request
70+ * @param host the host to use to send the CONNECT STOMP frame
71+ */
72+ public StompClient (URI serverUri , AuthType authType , String host ) {
73+ this (serverUri , authType , host , 10 );
74+ }
75+
76+ /**
77+ * Initialises the client.
78+ *
79+ * @param serverUri the URI of the STOMP server
80+ * @param authType optional authentication method from `uk.guzek.sac.auth.*` to use during the initial
81+ * HTTP Upgrade request
82+ * @param host the host to use to send the CONNECT STOMP frame
83+ * @param timeout optional length of time to allow for lost messages to be
84+ * sent when the client is closed, in
85+ * seconds; defaults to 10
86+ */
87+ public StompClient (URI serverUri , AuthType authType , String host , int timeout ) {
88+ this (serverUri , authType .getHeaders (), host , timeout );
89+ }
90+
91+ /**
92+ * Initialises the client.
93+ *
6794 * @param serverUri the URI of the STOMP server
6895 * @param headers optional key-value header pairs to use during the initial
6996 * HTTP Upgrade request
@@ -79,8 +106,7 @@ public StompClient(URI serverUri, Map<String, String> headers, String host, int
79106 }
80107
81108 private void executeMessageQueue () {
82- if (!connected )
83- return ;
109+ if (!connected ) return ;
84110 for (Runnable runnable : messageQueue ) {
85111 runnable .run ();
86112 }
@@ -136,7 +162,7 @@ private int sendDisconnectFrame() {
136162
137163 /**
138164 * Send a SEND frame which is not JSON or plaintext.
139- *
165+ *
140166 * @param message the payload to send
141167 * @param destination the path to send the message to
142168 * @param contentType the MIME content type of the payload
@@ -147,7 +173,7 @@ public void sendSendFrame(String message, String destination, String contentType
147173
148174 /**
149175 * Send a plaintext SEND frame.
150- *
176+ *
151177 * @param message the plaintext payload to send
152178 * @param destination the path to send the message to
153179 */
@@ -157,7 +183,7 @@ public void sendText(String message, String destination) {
157183
158184 /**
159185 * Send a JSON SEND frame.
160- *
186+ *
161187 * @param object the object payload to be serialised as JSON and sent
162188 * @param destination the path to send the message to
163189 * @throws JsonProcessingException passed on from Jackson's `writeValueAsString`
@@ -169,7 +195,7 @@ public void sendJson(Object object, String destination) throws JsonProcessingExc
169195
170196 /**
171197 * Calls `handler` whenever the server sends MESSAGE frames to `destination`.
172- *
198+ *
173199 * @param destination the path of the resource to subscribe to
174200 * @param handler a biconsumable which takes a string-string header map and a body string`
175201 * @return the id of the subscription (incremental)
@@ -232,7 +258,7 @@ public void onConnected() {
232258 * Called for each frame received by the client.
233259 * Use this to handle other frames sent by the server which are not MESSAGE
234260 * frames sent to subscriptions.
235- *
261+ *
236262 * @param frame the frame type
237263 * @param headers a key-value pair of frame headers
238264 * @param body the frame body (can be an empty string, not null)
@@ -243,7 +269,7 @@ public void onConnected() {
243269 * Called for each message received by the client. For STOMP messages, use
244270 * {@link #onStompFrame}.
245271 * Do not override this method unless you know what you are doing.
246- *
272+ *
247273 * @param message the raw message sent by the server
248274 */
249275 @ Override
0 commit comments