Skip to content

Commit 45c9719

Browse files
committed
Implement the validateParams function on the endpoints to alert the user when required parameters are missing
1 parent 2bf2aee commit 45c9719

37 files changed

+540
-159
lines changed

src/main/java/com/pubnub/api/PubNubError.java

Lines changed: 115 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class PubNubError {
4444
* An ULS singature error occurred . Please contact support with error
4545
* details.
4646
*/
47-
static final int PNERR_ULSSIGN_ERROR = 105;
47+
public static final int PNERR_ULSSIGN_ERROR = 105;
4848

4949
/**
5050
* Please verify if network is reachable
@@ -108,12 +108,12 @@ public class PubNubError {
108108
/**
109109
* Unable to open input stream . Please contact support with error details.
110110
*/
111-
static final int PNERR_GETINPUTSTREAM = 118;
111+
public static final int PNERR_GETINPUTSTREAM = 118;
112112

113113
/**
114114
* Malformed URL . Please contact support with error details .
115115
*/
116-
static final int PNERR_MALFORMED_URL = 119;
116+
public static final int PNERR_MALFORMED_URL = 119;
117117

118118
/**
119119
* Error in opening URL . Please contact support with error details.
@@ -124,38 +124,38 @@ public class PubNubError {
124124
* JSON Error while processing API response. Please contact support with
125125
* error details.
126126
*/
127-
static final int PNERR_JSON_ERROR = 121;
127+
public static final int PNERR_JSON_ERROR = 121;
128128

129129
/**
130130
* Protocol Exception . Please contact support with error details.
131131
*/
132-
static final int PNERR_PROTOCOL_EXCEPTION = 122;
132+
public static final int PNERR_PROTOCOL_EXCEPTION = 122;
133133

134134
/**
135135
* Unable to read input stream . Please contact support with error details.
136136
*/
137-
static final int PNERR_READINPUT = 123;
137+
public static final int PNERR_READINPUT = 123;
138138

139139
/**
140140
* Bad gateway . Please contact support with error details.
141141
*/
142-
static final int PNERR_BAD_GATEWAY = 124;
142+
public static final int PNERR_BAD_GATEWAY = 124;
143143

144144
/**
145145
* PubNub server returned HTTP 502 internal server error status code. Please
146146
* contact support with error details.
147147
*/
148-
static final int PNERR_INTERNAL_ERROR = 125;
148+
public static final int PNERR_INTERNAL_ERROR = 125;
149149

150150
/**
151151
* Parsing Error .
152152
*/
153-
static final int PNERR_PARSING_ERROR = 126;
153+
public static final int PNERR_PARSING_ERROR = 126;
154154

155155
/**
156156
* Bad Request . Please contact support with error details.
157157
*/
158-
static final int PNERR_BAD_REQUEST = 127;
158+
public static final int PNERR_BAD_REQUEST = 127;
159159

160160
public static final int PNERR_HTTP_RC_ERROR = 128;
161161
/**
@@ -168,7 +168,7 @@ public class PubNubError {
168168
/**
169169
* Subscribe Timeout .
170170
*/
171-
static final int PNERR_HTTP_SUBSCRIBE_TIMEOUT = 130;
171+
public static final int PNERR_HTTP_SUBSCRIBE_TIMEOUT = 130;
172172

173173
/**
174174
* Invalid arguments provided to API
@@ -197,88 +197,149 @@ public class PubNubError {
197197
* Crypto Error
198198
*/
199199
public static final int PNERR_CRYPTO_ERROR = 135;
200-
// Error Objects
201200

202-
static final PubNubError PNERROBJ_TIMEOUT = new PubNubError(PNERR_TIMEOUT, "Timeout Occurred");
201+
/**
202+
* Group missing
203+
*
204+
*/
205+
public static final int PNERR_GROUP_MISSING = 136;
206+
207+
/**
208+
* Auth Keys missing
209+
*
210+
*/
211+
public static final int PNERR_AUTH_KEYS_MISSING = 137;
212+
213+
/**
214+
* Subscribe Key missing
215+
*
216+
*/
217+
public static final int PNERR_SUBSCRIBE_KEY_MISSING = 138;
218+
219+
/**
220+
* Publish Key missing
221+
*
222+
*/
223+
public static final int PNERR_PUBLISH_KEY_MISSING = 139;
224+
225+
/**
226+
* State missing
227+
*
228+
*/
229+
public static final int PNERR_STATE_MISSING = 140;
230+
231+
/**
232+
* Channel and Group missing
233+
*
234+
*/
235+
public static final int PNERR_CHANNEL_AND_GROUP_MISSING = 141;
203236

204-
static final PubNubError PNERROBJ_INTERNAL_ERROR = new PubNubError(PNERR_INTERNAL_ERROR, "Internal Error");
237+
/**
238+
* Message missing
239+
*
240+
*/
241+
public static final int PNERR_MESSAGE_MISSING = 142;
242+
243+
/**
244+
* Push TYpe missing
245+
*
246+
*/
247+
public static final int PNERR_PUSH_TYPE_MISSING = 143;
248+
249+
/**
250+
* Device ID missing
251+
*
252+
*/
253+
public static final int PNERR_DEVICE_ID_MISSING = 144;
254+
255+
// Error Objects
205256

206-
static final PubNubError PNERROBJ_ENCRYPTION_ERROR = new PubNubError(PNERR_ENCRYPTION_ERROR,
257+
public static final PubNubError PNERROBJ_TIMEOUT = new PubNubError(PNERR_TIMEOUT, "Timeout Occurred");
258+
259+
public static final PubNubError PNERROBJ_INTERNAL_ERROR = new PubNubError(PNERR_INTERNAL_ERROR, "Internal Error");
260+
261+
public static final PubNubError PNERROBJ_ENCRYPTION_ERROR = new PubNubError(PNERR_ENCRYPTION_ERROR,
207262
"Error while encrypting message to be published to PubNub Cloud ."
208263
+ "Please contact support with error details.");
209264

210-
static final PubNubError PNERROBJ_DECRYPTION_ERROR = new PubNubError(PNERR_DECRYPTION_ERROR, "Decryption Error. "
265+
public static final PubNubError PNERROBJ_DECRYPTION_ERROR = new PubNubError(PNERR_DECRYPTION_ERROR, "Decryption Error. "
211266
+ "Please contact support with error details.");
212267

213-
static final PubNubError PNERROBJ_INVALID_JSON = new PubNubError(PNERR_INVALID_JSON, "Invalid Json. "
268+
public static final PubNubError PNERROBJ_INVALID_JSON = new PubNubError(PNERR_INVALID_JSON, "Invalid Json. "
214269
+ "Please contact support with error details.");
215270

216-
static final PubNubError PNERROBJ_JSON_ERROR = new PubNubError(PNERR_JSON_ERROR,
271+
public static final PubNubError PNERROBJ_JSON_ERROR = new PubNubError(PNERR_JSON_ERROR,
217272
"JSON Error while processing API response. " + "Please contact support with error details.");
218273

219-
static final PubNubError PNERROBJ_MALFORMED_URL = new PubNubError(PNERR_MALFORMED_URL, "Malformed URL ."
274+
public static final PubNubError PNERROBJ_MALFORMED_URL = new PubNubError(PNERR_MALFORMED_URL, "Malformed URL ."
220275
+ "Please contact support with error details.");
221276

222-
static final PubNubError PNERROBJ_PUBNUB_ERROR = new PubNubError(PNERR_PUBNUB_ERROR, "PubNub Error");
277+
public static final PubNubError PNERROBJ_PUBNUB_ERROR = new PubNubError(PNERR_PUBNUB_ERROR, "PubNub Error");
223278

224-
static final PubNubError PNERROBJ_URL_OPEN = new PubNubError(PNERR_URL_OPEN, "Error opening url. "
279+
public static final PubNubError PNERROBJ_URL_OPEN = new PubNubError(PNERR_URL_OPEN, "Error opening url. "
225280
+ "Please contact support with error details.");
226281

227-
static final PubNubError PNERROBJ_PROTOCOL_EXCEPTION = new PubNubError(PNERR_PROTOCOL_EXCEPTION,
282+
public static final PubNubError PNERROBJ_PROTOCOL_EXCEPTION = new PubNubError(PNERR_PROTOCOL_EXCEPTION,
228283
"Protocol Exception. " + "Please contact support with error details.");
229284

230-
static final PubNubError PNERROBJ_CONNECT_EXCEPTION = new PubNubError(PNERR_CONNECT_EXCEPTION,
285+
public static final PubNubError PNERROBJ_CONNECT_EXCEPTION = new PubNubError(PNERR_CONNECT_EXCEPTION,
231286
"Connect Exception. " + "Please verify if network is reachable. ");
232287

233-
static final PubNubError PNERROBJ_HTTP_RC_ERROR = new PubNubError(PNERR_HTTP_RC_ERROR,
288+
public static final PubNubError PNERROBJ_HTTP_RC_ERROR = new PubNubError(PNERR_HTTP_RC_ERROR,
234289
"Unable to get PnResponse Code. " + "Please contact support with error details.");
235290

236-
static final PubNubError PNERROBJ_GETINPUTSTREAM = new PubNubError(PNERR_GETINPUTSTREAM,
291+
public static final PubNubError PNERROBJ_GETINPUTSTREAM = new PubNubError(PNERR_GETINPUTSTREAM,
237292
"Unable to get Input Stream. " + "Please contact support with error details.");
238293

239-
static final PubNubError PNERROBJ_READINPUT = new PubNubError(PNERR_READINPUT, "Unable to read Input Stream. "
294+
public static final PubNubError PNERROBJ_READINPUT = new PubNubError(PNERR_READINPUT, "Unable to read Input Stream. "
240295
+ "Please contact support with error details.");
241296

242-
static final PubNubError PNERROBJ_BAD_REQUEST = new PubNubError(PNERR_BAD_REQUEST, "Bad request. "
297+
public static final PubNubError PNERROBJ_BAD_REQUEST = new PubNubError(PNERR_BAD_REQUEST, "Bad request. "
243298
+ "Please contact support with error details.");
244299

245300
public static final PubNubError PNERROBJ_HTTP_ERROR = new PubNubError(PNERR_HTTP_ERROR, "HTTP Error. "
246301
+ "Please check network connectivity. " + "Please contact support with error details if issue persists.");
247302

248-
static final PubNubError PNERROBJ_BAD_GATEWAY = new PubNubError(PNERR_BAD_GATEWAY, "Bad Gateway. "
303+
public static final PubNubError PNERROBJ_BAD_GATEWAY = new PubNubError(PNERR_BAD_GATEWAY, "Bad Gateway. "
249304
+ "Please contact support with error details.");
250305

251-
static final PubNubError PNERROBJ_CLIENT_TIMEOUT = new PubNubError(PNERR_CLIENT_TIMEOUT, "Client Timeout");
306+
public static final PubNubError PNERROBJ_CLIENT_TIMEOUT = new PubNubError(PNERR_CLIENT_TIMEOUT, "Client Timeout");
252307

253-
static final PubNubError PNERROBJ_GATEWAY_TIMEOUT = new PubNubError(PNERR_GATEWAY_TIMEOUT, "Gateway Timeout");
308+
public static final PubNubError PNERROBJ_GATEWAY_TIMEOUT = new PubNubError(PNERR_GATEWAY_TIMEOUT, "Gateway Timeout");
254309

255-
static final PubNubError PNERROBJ_5023_INTERNAL_ERROR = new PubNubError(PNERR_INTERNAL_ERROR,
310+
public static final PubNubError PNERROBJ_5023_INTERNAL_ERROR = new PubNubError(PNERR_INTERNAL_ERROR,
256311
"Internal Server Error. " + "Please contact support with error details.");
257312

258313
public static final PubNubError PNERROBJ_PARSING_ERROR = new PubNubError(PNERR_PARSING_ERROR, "Parsing Error");
259314

260-
static final PubNubError PNERROBJ_PUBNUB_EXCEPTION = new PubNubError(PNERR_PUBNUB_EXCEPTION, "PubNub Exception");
315+
public static final PubNubError PNERROBJ_PUBNUB_EXCEPTION = new PubNubError(PNERR_PUBNUB_EXCEPTION, "PubNub Exception");
261316

262-
static final PubNubError PNERROBJ_DISCONNECT = new PubNubError(PNERR_DISCONNECT, "Disconnect");
317+
public static final PubNubError PNERROBJ_DISCONNECT = new PubNubError(PNERR_DISCONNECT, "Disconnect");
263318

264-
static final PubNubError PNERROBJ_DISCONN_AND_RESUB = new PubNubError(PNERR_DISCONN_AND_RESUB,
319+
public static final PubNubError PNERROBJ_DISCONN_AND_RESUB = new PubNubError(PNERR_DISCONN_AND_RESUB,
265320
"Disconnect and Resubscribe");
266321

267-
static final PubNubError PNERROBJ_FORBIDDEN = new PubNubError(PNERR_FORBIDDEN, "Authentication Failure. "
322+
public static final PubNubError PNERROBJ_FORBIDDEN = new PubNubError(PNERR_FORBIDDEN, "Authentication Failure. "
268323
+ "Incorrect Authentication Key");
269324

270-
static final PubNubError PNERROBJ_UNAUTHORIZED = new PubNubError(PNERR_UNAUTHORIZED, "Authentication Failure. "
325+
public static final PubNubError PNERROBJ_UNAUTHORIZED = new PubNubError(PNERR_UNAUTHORIZED, "Authentication Failure. "
271326
+ "Authentication Key is missing");
272327

273-
static final PubNubError PNERROBJ_SECRET_KEY_MISSING = new PubNubError(PNERR_SECRET_KEY_MISSING,
328+
public static final PubNubError PNERROBJ_SECRET_KEY_MISSING = new PubNubError(PNERR_SECRET_KEY_MISSING,
274329
"ULS configuration failed. Secret Key not configured. ");
275330

276-
static final PubNubError PNERROBJ_ULSSIGN_ERROR = new PubNubError(PNERR_ULSSIGN_ERROR, "Invalid Signature . "
331+
public static final PubNubError PNERROBJ_SUBSCRIBE_KEY_MISSING = new PubNubError(PNERR_SUBSCRIBE_KEY_MISSING,
332+
"ULS configuration failed. Subscribe Key not configured. ");
333+
334+
public static final PubNubError PNERROBJ_PUBLISH_KEY_MISSING = new PubNubError(PNERR_PUBLISH_KEY_MISSING,
335+
"ULS configuration failed. Publish Key not configured. ");
336+
337+
public static final PubNubError PNERROBJ_ULSSIGN_ERROR = new PubNubError(PNERR_ULSSIGN_ERROR, "Invalid Signature . "
277338
+ "Please contact support with error details.");
278339

279-
static final PubNubError PNERROBJ_5075_NETWORK_ERROR = new PubNubError(PNERR_NETWORK_ERROR, "Network Error. "
340+
public static final PubNubError PNERROBJ_5075_NETWORK_ERROR = new PubNubError(PNERR_NETWORK_ERROR, "Network Error. "
280341
+ "Please verify if network is reachable.");
281-
static final PubNubError PNERROBJ_NOT_FOUND_ERROR = new PubNubError(PNERR_NOT_FOUND, "Page Not Found"
342+
public static final PubNubError PNERROBJ_NOT_FOUND_ERROR = new PubNubError(PNERR_NOT_FOUND, "Page Not Found"
282343
+ "Please verify if network is reachable." + "Please contact support with error details.");
283344

284345
public static final PubNubError PNERROBJ_SUBSCRIBE_TIMEOUT = new PubNubError(PNERR_HTTP_SUBSCRIBE_TIMEOUT,
@@ -288,9 +349,23 @@ public class PubNubError {
288349

289350
public static final PubNubError PNERROBJ_CHANNEL_MISSING = new PubNubError(PNERR_CHANNEL_MISSING, "Channel Missing.");
290351

352+
public static final PubNubError PNERROBJ_STATE_MISSING = new PubNubError(PNERR_STATE_MISSING, "State Missing.");
353+
354+
public static final PubNubError PNERROBJ_MESSAGE_MISSING = new PubNubError(PNERR_MESSAGE_MISSING, "Message Missing.");
355+
356+
public static final PubNubError PNERROBJ_PUSH_TYPE_MISSING = new PubNubError(PNERR_PUSH_TYPE_MISSING, "Push Type Missing.");
357+
358+
public static final PubNubError PNERROBJ_DEVICE_ID_MISSING = new PubNubError(PNERR_DEVICE_ID_MISSING, "Device Id Missing.");
359+
291360
public static final PubNubError PNERROBJ_CONNECTION_NOT_SET = new PubNubError(PNERR_CONNECTION_NOT_SET,
292361
"PubNub Connection not set");
293362

363+
public static final PubNubError PNERROBJ_GROUP_MISSING = new PubNubError(PNERR_GROUP_MISSING, "Group Missing.");
364+
365+
public static final PubNubError PNERROBJ_CHANNEL_AND_GROUP_MISSING = new PubNubError(PNERR_CHANNEL_AND_GROUP_MISSING, "Channel and Group Missing.");
366+
367+
public static final PubNubError PNERROBJ_AUTH_KEYS_MISSING = new PubNubError(PNERR_AUTH_KEYS_MISSING, "Auth Keys Missing.");
368+
294369
public static final PubNubError PNERROBJ_CHANNEL_GROUP_PARSING_ERROR = new PubNubError(PNERR_CHANNEL_GROUP_PARSING_ERROR,
295370
"Channel group name is invalid");
296371

src/main/java/com/pubnub/api/endpoints/Endpoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public final Output sync() throws PubNubException {
7474
}
7575

7676
public final Call<Input> async(final PNCallback<Output> callback) {
77-
this.validateParams();
7877

7978
Call<Input> call = null;
8079
try {
@@ -235,7 +234,7 @@ protected final Map<String, String> createBaseParams() {
235234
return params;
236235
}
237236

238-
protected abstract boolean validateParams();
237+
protected abstract void validateParams() throws PubNubException;
239238

240239
protected abstract Call<Input> doWork(Map<String, String> baseParams) throws PubNubException;
241240
protected abstract Output createResponse(Response<Input> input) throws PubNubException;

src/main/java/com/pubnub/api/endpoints/History.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import retrofit2.http.GET;
1818
import retrofit2.http.Path;
1919
import retrofit2.http.QueryMap;
20+
import sun.invoke.empty.Empty;
2021

2122
import java.io.IOException;
2223
import java.util.ArrayList;
@@ -45,8 +46,11 @@ Call<JsonNode> fetchHistory(@Path("subKey") String subKey,
4546
}
4647

4748
@Override
48-
protected boolean validateParams() {
49-
return true;
49+
protected void validateParams() throws PubNubException {
50+
if (channel==null || channel.isEmpty())
51+
{
52+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_CHANNEL_MISSING).build();
53+
}
5054
}
5155

5256
@Override

src/main/java/com/pubnub/api/endpoints/Time.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ private interface TimeService {
2525
}
2626

2727
@Override
28-
protected final boolean validateParams() {
29-
return true;
28+
protected final void validateParams() throws PubNubException {
29+
3030
}
3131

3232
@Override

src/main/java/com/pubnub/api/endpoints/access/Audit.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import retrofit2.Call;
1515
import retrofit2.Response;
1616

17+
import java.util.ArrayList;
1718
import java.util.List;
1819
import java.util.Map;
1920

@@ -24,17 +25,27 @@ public class Audit extends Endpoint<Envelope<AccessManagerAuditPayload>, PNAcces
2425
@Setter private String channel;
2526
@Setter private String channelGroup;
2627

27-
public Audit(PubNub pubnub) {
28+
public Audit(PubNub pubnub)
29+
{
2830
super(pubnub);
31+
authKeys = new ArrayList<>();
2932
}
3033

3134
@Override
32-
protected boolean validateParams() {
33-
if (pubnub.getConfiguration().getSecretKey() != null && pubnub.getConfiguration().getSecretKey().length() == 0) {
34-
return false;
35+
protected void validateParams() throws PubNubException {
36+
if (authKeys.size() == 0)
37+
{
38+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_AUTH_KEYS_MISSING).build();
39+
}
40+
if (pubnub.getConfiguration().getSecretKey()==null || pubnub.getConfiguration().getSecretKey().isEmpty()) {
41+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_SECRET_KEY_MISSING).build();
42+
}
43+
if (pubnub.getConfiguration().getSubscribeKey()==null || pubnub.getConfiguration().getSubscribeKey().isEmpty()) {
44+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_SUBSCRIBE_KEY_MISSING).build();
45+
}
46+
if (pubnub.getConfiguration().getPublishKey()==null || pubnub.getConfiguration().getPublishKey().isEmpty()) {
47+
throw PubNubException.builder().pubnubError(PubNubError.PNERROBJ_PUBLISH_KEY_MISSING).build();
3548
}
36-
37-
return true;
3849
}
3950

4051
@Override

0 commit comments

Comments
 (0)