Skip to content

Commit 4393c66

Browse files
author
Frohwalt Egerer
committed
Partial Idea inspection cleanup
1 parent 639728f commit 4393c66

34 files changed

+108
-100
lines changed

CHANGELOG

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ Version 0.2.4.build-SNAPSHOT - (in progress)
66
Version 0.2.3 - Mar 30, 2013
77
- return back to com.notnoop.apns group id (#91)
88

9-
- Add NOOP delegate adapter and ability to build service with keystore (#93)
9+
- Add no operation delegate adapter and ability to build service with keystore (#93)
1010
- Proxy support for Feedback connection (#92)
1111
- Make APNS class final
1212
- Batch APNS (#14)
1313
- Update dependencies (#85 #84)
1414

1515
Version 0.2.2 - Jan 20, 2013
1616
- ApnsConnection resend unsent notifications after error
17-
- Do not stop QueuedApnsService on unsuccessfull attempt to submit a message
17+
- Do not stop QueuedApnsService on unsuccessful attempt to submit a message
1818
- Continuous integration builds on travis ci
1919
- Support Proxy.Type.HTTP.
2020
- Do not log error messages for retries when sending a message, rather
2121
log one when we can't send a message at all.
2222
- When there is an error (error packet or exception in parsing error packet)
23-
close the socket instead of wating for APNS to close it.
23+
close the socket instead of waiting for APNS to close it.
2424
- java-apns now is an osgi bundle
2525
- Have ApnsService.push return sent messages
2626
- Add changelog

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Features:
3030
* Easy to use, high performance APNS Service API
3131
* Supports Apple Feedback service
3232
* Support Enhanced Apple Push Notification
33-
* Support MDM and Newstand Notifications
33+
* Support MDM and Newsstand Notifications
3434
* Easy to use with Apple certificates
3535
* Easy to extend and reuse
3636
* Easy to integrate with dependency injection frameworks

docs/cachedNotification_queue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ java-apns maintains a per-connection sent queue (cachedNotifications) like descr
44

55
* java-apns queue is bounded (cacheNotification() will poll notifications out of the queue when the queue gets too big.)
66

7-
* It does not regularily check whether sent messages have been sent a few seconds ago to remove them from the sent queue.
7+
* It does not regularly check whether sent messages have been sent a few seconds ago to remove them from the sent queue.
88

99
So if we send a lot of notifications without failure the old notifications will fall off the queue. This is typically ok (since they are "older" and probably have been sent successfully). The queue only serves to cache all the messages sent in between the client sending a bad notification and the APNS server replying.
1010

src/main/java/com/notnoop/apns/ApnsDelegate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public interface ApnsDelegate {
4343
* Called when message was successfully sent to the Apple servers
4444
*
4545
* @param message the notification that was sent
46-
* @param resent whether the notfication was resent after an error
46+
* @param resent whether the notification was resent after an error
4747
*/
4848
public void messageSent(ApnsNotification message, boolean resent);
4949

@@ -86,7 +86,7 @@ public interface ApnsDelegate {
8686
public void notificationsResent(int resendCount);
8787

8888
/**
89-
* A NOOP delegate that does nothing!
89+
* A no operation delegate that does nothing!
9090
*/
9191
public final static ApnsDelegate EMPTY = new ApnsDelegateAdapter();
9292
}

src/main/java/com/notnoop/apns/ApnsDelegateAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.notnoop.apns;
22

33
/**
4-
* A NOOP delegate that does nothing!
4+
* A no operation delegate that does nothing!
55
*/
66
public class ApnsDelegateAdapter implements ApnsDelegate {
77

src/main/java/com/notnoop/apns/ApnsService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public interface ApnsService {
6060
*
6161
* @param deviceToken the destination iPhone device token
6262
* @param payload The payload message
63-
* @throws NetworkIOException if a network error occured while
63+
* @throws NetworkIOException if a network error occurred while
6464
* attempting to send the message
6565
*/
6666
ApnsNotification push(String deviceToken, String payload) throws NetworkIOException;
@@ -119,7 +119,7 @@ public interface ApnsService {
119119
/**
120120
* Sends the provided notification {@code message} to the desired
121121
* destination.
122-
* @throws NetworkIOException if a network error occured while
122+
* @throws NetworkIOException if a network error occurred while
123123
* attempting to send the message
124124
*/
125125
void push(ApnsNotification message) throws NetworkIOException;
@@ -128,7 +128,7 @@ public interface ApnsService {
128128
* Starts the service.
129129
*
130130
* The underlying implementation may prepare its connections or
131-
* datastructures to be able to send the messages.
131+
* data structures to be able to send the messages.
132132
*
133133
* This method is a blocking call, even if the service represents
134134
* a Non-blocking push service. Once the service is returned, it is ready

src/main/java/com/notnoop/apns/ApnsServiceBuilder.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class ApnsServiceBuilder {
7878
private int connectTimeout = 0;
7979

8080
private String gatewayHost;
81-
private int gatewaPort = -1;
81+
private int gatewayPort = -1;
8282

8383
private String feedbackHost;
8484
private int feedbackPort;
@@ -121,7 +121,7 @@ public class ApnsServiceBuilder {
121121
* This library does not support password-less p12 certificates, due to a
122122
* Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637">
123123
* Bug 6415637</a>. There are three workarounds: use a password-protected
124-
* certificate, use a different boot Java SDK implementation, or constract
124+
* certificate, use a different boot Java SDK implementation, or construct
125125
* the `SSLContext` yourself! Needless to say, the password-protected
126126
* certificate is most recommended option.
127127
*
@@ -184,7 +184,7 @@ public ApnsServiceBuilder withCert(InputStream stream, String password)
184184
* This library does not support password-less p12 certificates, due to a
185185
* Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637">
186186
* Bug 6415637</a>. There are three workarounds: use a password-protected
187-
* certificate, use a different boot Java SDK implementation, or constract
187+
* certificate, use a different boot Java SDK implementation, or construct
188188
* the `SSLContext` yourself! Needless to say, the password-protected
189189
* certificate is most recommended option.
190190
*
@@ -227,7 +227,7 @@ public ApnsServiceBuilder withSSLContext(SSLContext sslContext) {
227227

228228
/**
229229
* Specify the timeout value to be set in new setSoTimeout in created
230-
* sockets, for both feedback and push connections, in msecs.
230+
* sockets, for both feedback and push connections, in milliseconds.
231231
* @param readTimeout timeout value to be set in new setSoTimeout
232232
* @return this
233233
*/
@@ -238,7 +238,7 @@ public ApnsServiceBuilder withReadTimeout(int readTimeout) {
238238

239239
/**
240240
* Specify the timeout value to use for connectionTimeout in created
241-
* sockets, for both feedback and push connections, in msecs.
241+
* sockets, for both feedback and push connections, in milliseconds.
242242
* @param connectTimeout timeout value to use for connectionTimeout
243243
* @return this
244244
*/
@@ -261,7 +261,7 @@ public ApnsServiceBuilder withConnectTimeout(int connectTimeout) {
261261
*/
262262
public ApnsServiceBuilder withGatewayDestination(String host, int port) {
263263
this.gatewayHost = host;
264-
this.gatewaPort = port;
264+
this.gatewayPort = port;
265265
return this;
266266
}
267267

@@ -422,7 +422,7 @@ public ApnsServiceBuilder withProxy(Proxy proxy) {
422422
}
423423

424424
/**
425-
* Specity the number of notifications to cache for error purposes.
425+
* Specify the number of notifications to cache for error purposes.
426426
* Default is 100
427427
*
428428
* @param cacheLength Number of notifications to cache for error purposes
@@ -614,8 +614,8 @@ public ApnsService build() {
614614
SSLSocketFactory sslFactory = sslContext.getSocketFactory();
615615
ApnsFeedbackConnection feedback = new ApnsFeedbackConnection(sslFactory, feedbackHost, feedbackPort, proxy, readTimeout, connectTimeout, proxyUsername, proxyPassword);
616616

617-
ApnsConnection conn = new ApnsConnectionImpl(sslFactory, gatewayHost,
618-
gatewaPort, proxy, proxyUsername, proxyPassword, reconnectPolicy,
617+
ApnsConnection conn = new ApnsConnectionImpl(sslFactory, gatewayHost,
618+
gatewayPort, proxy, proxyUsername, proxyPassword, reconnectPolicy,
619619
delegate, errorDetection, errorDetectionThreadFactory, cacheLength,
620620
autoAdjustCacheLength, readTimeout, connectTimeout);
621621
if (pooledMax != 1) {
@@ -642,7 +642,7 @@ private void checkInitialization() {
642642
throw new IllegalStateException(
643643
"SSL Certificates and attribute are not initialized\n"
644644
+ "Use .withCert() methods.");
645-
if (gatewayHost == null || gatewaPort == -1)
645+
if (gatewayHost == null || gatewayPort == -1)
646646
throw new IllegalStateException(
647647
"The Destination APNS server is not stated\n"
648648
+ "Use .withDestination(), withSandboxDestination(), "

src/main/java/com/notnoop/apns/SimpleApnsNotification.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
* and should not be used in new development.
4242
* https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/LegacyFormat.html
4343
*
44-
* This SimpleApnsNotification also only has limited error handly (by the APNS closing the connection
44+
* This SimpleApnsNotification also only has limited error handling (by the APNS closing the connection
4545
* when a bad message was received) This prevents us from location the malformed notification.
4646
*
4747
* As push messages sent after a malformed notification are discarded by APNS messages will get lost
4848
* and not be delivered with the SimpleApnsNotification.
4949
*
5050
* @deprecated use EnhancedApnsNotification instead.
5151
*/
52+
@SuppressWarnings("deprecation")
5253
@Deprecated
5354
public class SimpleApnsNotification implements ApnsNotification {
5455

src/main/java/com/notnoop/apns/internal/AbstractApnsService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public Collection<EnhancedApnsNotification> push(Collection<String> deviceTokens
8282
byte[] messageBytes = Utilities.toUTF8Bytes(payload);
8383
List<EnhancedApnsNotification> notifications = new ArrayList<EnhancedApnsNotification>(deviceTokens.size());
8484
for (String deviceToken : deviceTokens) {
85-
byte[] dtbytes = Utilities.decodeHex(deviceToken);
85+
byte[] dtBytes = Utilities.decodeHex(deviceToken);
8686
EnhancedApnsNotification notification =
87-
new EnhancedApnsNotification(c.incrementAndGet(), EnhancedApnsNotification.MAXIMUM_EXPIRY, dtbytes, messageBytes);
87+
new EnhancedApnsNotification(c.incrementAndGet(), EnhancedApnsNotification.MAXIMUM_EXPIRY, dtBytes, messageBytes);
8888
notifications.add(notification);
8989
push(notification);
9090
}
@@ -95,9 +95,9 @@ public Collection<EnhancedApnsNotification> push(Collection<String> deviceTokens
9595
byte[] messageBytes = Utilities.toUTF8Bytes(payload);
9696
List<EnhancedApnsNotification> notifications = new ArrayList<EnhancedApnsNotification>(deviceTokens.size());
9797
for (String deviceToken : deviceTokens) {
98-
byte[] dtbytes = Utilities.decodeHex(deviceToken);
98+
byte[] dtBytes = Utilities.decodeHex(deviceToken);
9999
EnhancedApnsNotification notification =
100-
new EnhancedApnsNotification(c.incrementAndGet(), (int)(expiry.getTime() / 1000), dtbytes, messageBytes);
100+
new EnhancedApnsNotification(c.incrementAndGet(), (int)(expiry.getTime() / 1000), dtBytes, messageBytes);
101101
notifications.add(notification);
102102
push(notification);
103103
}

src/main/java/com/notnoop/apns/internal/ApnsFeedbackConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Map<String, Date> getInactiveDevices() throws NetworkIOException {
8484
attempts = 0;
8585
return result;
8686
} catch (final Exception e) {
87-
logger.warn("Failed to retreive invalid devices", e);
87+
logger.warn("Failed to retrieve invalid devices", e);
8888
if (attempts >= RETRIES) {
8989
logger.error("Couldn't get feedback connection", e);
9090
Utilities.wrapAndThrowAsRuntimeException(e);

src/main/java/com/notnoop/apns/internal/BatchApnsService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class BatchApnsService extends AbstractApnsService {
4141
private ScheduledExecutorService scheduleService;
4242
private ScheduledFuture<?> taskFuture;
4343

44-
private Runnable batchRunner = new SendMessagessBatch();
44+
private Runnable batchRunner = new SendMessagesBatch();
4545

4646
public BatchApnsService(ApnsConnection prototype, ApnsFeedbackConnection feedback, int batchWaitTimeInSec, int maxBachWaitTimeInSec, ThreadFactory tf) {
4747
super(feedback);
@@ -73,9 +73,9 @@ public void push(ApnsNotification message) throws NetworkIOException {
7373
firstMessageArrivedTime = System.nanoTime();
7474
}
7575

76-
long sincFirstMessageSec = (System.nanoTime() - firstMessageArrivedTime) / 1000 / 1000 / 1000;
76+
long sinceFirstMessageSec = (System.nanoTime() - firstMessageArrivedTime) / 1000 / 1000 / 1000;
7777

78-
if (taskFuture != null && sincFirstMessageSec < maxBatchWaitTimeInSec) {
78+
if (taskFuture != null && sinceFirstMessageSec < maxBatchWaitTimeInSec) {
7979
taskFuture.cancel(false);
8080
}
8181

@@ -86,7 +86,7 @@ public void push(ApnsNotification message) throws NetworkIOException {
8686
}
8787
}
8888

89-
class SendMessagessBatch implements Runnable {
89+
class SendMessagesBatch implements Runnable {
9090
public void run() {
9191
ApnsConnection newConnection = prototype.copy();
9292
try {

src/main/java/com/notnoop/apns/internal/TlsTunnelBuilder.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public Socket build(SSLSocketFactory factory, Proxy proxy, String proxyUsername,
7979
}
8080

8181
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE",
82-
justification = "use <CR><LF> as according to RFC, not platform-linfeed")
82+
justification = "use <CR><LF> as according to RFC, not platform-linefeed")
8383
Socket makeTunnel(String host, int port, String proxyUsername,
8484
String proxyPassword, InetSocketAddress proxyAddress) throws IOException {
8585
if(host == null || port < 0 || host.isEmpty() || proxyAddress == null){
8686
throw new ProtocolException("Incorrect parameters to build tunnel.");
8787
}
8888
logger.debug("Creating socket for Proxy : " + proxyAddress.getAddress() + ":" + proxyAddress.getPort());
89-
Socket socket = null;
89+
Socket socket;
9090
try {
9191
ProxyClient client = new ProxyClient();
9292
client.getParams().setParameter("http.useragent", "java-apns");
@@ -100,7 +100,7 @@ Socket makeTunnel(String host, int port, String proxyUsername,
100100
if (socket == null) {
101101
ConnectMethod method = response.getConnectMethod();
102102
// Read the proxy's HTTP response.
103-
if(method.getStatusLine().toString().matches("HTTP\\/1\\.\\d 407 Proxy Authentication Required")) {
103+
if(method.getStatusLine().toString().matches("HTTP/1\\.\\d 407 Proxy Authentication Required")) {
104104
// Proxy server returned 407. We will now try to connect with auth Header
105105
if(proxyUsername != null && proxyPassword != null) {
106106
socket = AuthenticateProxy(method, client,proxyHost, proxyAddress.getPort(),
@@ -114,7 +114,9 @@ Socket makeTunnel(String host, int port, String proxyUsername,
114114
} catch (Exception e) {
115115
throw new ProtocolException("Error occurred while creating proxy socket : " + e.toString());
116116
}
117-
logger.debug("Socket for proxy created successfully : " + socket.getRemoteSocketAddress().toString());
117+
if (socket != null) {
118+
logger.debug("Socket for proxy created successfully : " + socket.getRemoteSocketAddress().toString());
119+
}
118120
return socket;
119121
}
120122

src/main/java/com/notnoop/apns/internal/Utilities.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public static SSLContext newSSLContext(final KeyStore ks, final String password,
103103
tmf.init((KeyStore)null);
104104

105105
// Get the SSLContext to help create SSLSocketFactory
106-
final SSLContext sslc = SSLContext.getInstance("TLS");
107-
sslc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
108-
return sslc;
106+
final SSLContext sslContext = SSLContext.getInstance("TLS");
107+
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
108+
return sslContext;
109109
} catch (final GeneralSecurityException e) {
110110
throw new InvalidSSLConfig(e);
111111
}
@@ -117,12 +117,12 @@ public static byte[] decodeHex(final String deviceToken) {
117117

118118
final byte[] bts = new byte[hex.length() / 2];
119119
for (int i = 0; i < bts.length; i++) {
120-
bts[i] = (byte) (charval(hex.charAt(2*i)) * 16 + charval(hex.charAt(2*i + 1)));
120+
bts[i] = (byte) (charVal(hex.charAt(2 * i)) * 16 + charVal(hex.charAt(2 * i + 1)));
121121
}
122122
return bts;
123123
}
124124

125-
private static int charval(final char a) {
125+
private static int charVal(final char a) {
126126
if ('0' <= a && a <= '9') {
127127
return (a - '0');
128128
} else if ('a' <= a && a <= 'f') {

src/test/java/com/notnoop/apns/ApnsGatewayServerSocket.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void handleSocket(Socket socket) throws IOException {
6363
} catch (IOException ioe) {
6464
writeResponse(socket, identifier, 8, 1);
6565
break;
66-
} catch (Exception expt) {
66+
} catch (Exception e) {
6767
writeResponse(socket, identifier, 8, 1);
6868
break;
6969
}
@@ -88,7 +88,8 @@ private void writeResponse(Socket socket, int identifier, int command,
8888
private byte[] toArray(InputStream inputStream, int size)
8989
throws IOException {
9090
byte[] bytes = new byte[size];
91-
inputStream.read(bytes);
91+
final DataInputStream dis = new DataInputStream(inputStream);
92+
dis.readFully(bytes);
9293
return bytes;
9394
}
9495
}

src/test/java/com/notnoop/apns/ApnsServerSocketBuilder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public ApnsServerSocketBuilder() {
9191
* Oracle Java library <a
9292
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> Bug
9393
* 6415637</a>. There are three workarounds: use a password-protected
94-
* certificate, use a different boot Java SDK implementation, or constract
94+
* certificate, use a different boot Java SDK implementation, or construct
9595
* the `SSLContext` yourself! Needless to say, the password-protected
9696
* certificate is most recommended option.
9797
*
@@ -130,7 +130,7 @@ public ApnsServerSocketBuilder withCert(String fileName, String password)
130130
* Oracle Java library <a
131131
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> Bug
132132
* 6415637</a>. There are three workarounds: use a password-protected
133-
* certificate, use a different boot Java SDK implementation, or constract
133+
* certificate, use a different boot Java SDK implementation, or construct
134134
* the `SSLContext` yourself! Needless to say, the password-protected
135135
* certificate is most recommended option.
136136
*
@@ -158,7 +158,7 @@ public ApnsServerSocketBuilder withCert(InputStream stream, String password)
158158
* Oracle Java library <a
159159
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> Bug
160160
* 6415637</a>. There are three workarounds: use a password-protected
161-
* certificate, use a different boot Java SDK implementation, or constract
161+
* certificate, use a different boot Java SDK implementation, or construct
162162
* the `SSLContext` yourself! Needless to say, the password-protected
163163
* certificate is most recommended option.
164164
*

src/test/java/com/notnoop/apns/MainClass.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class MainClass {
1111

1212
/**
13-
* @param args
13+
* @param args Program arguments
1414
* @throws FileNotFoundException
1515
* @throws InvalidSSLConfig
1616
*/

src/test/java/com/notnoop/apns/integration/ApnsSimulatorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public void testClientDoesNotResendMessagesWhenServerClosesSocketWithoutErrorPac
8989

9090
@Ignore
9191
@Test
92-
public void Racecondition() {
93-
// TODO implement test & decide if fix is neccessary afterwards.
92+
public void RaceCondition() {
93+
// TODO implement test & decide if fix is necessary afterwards.
9494
Assert.fail("Assumption: monitoring thread crashes in read() when the sender thread closes the connection first.");
9595
// Thus the last feedback message gets lost, thus we lose messages.
9696
}

0 commit comments

Comments
 (0)