Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GoogleJavaFormat using google-java-format-1.15.0 #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 95 additions & 99 deletions OCPP-J/src/main/java/eu/chargetime/ocpp/Draft_HttpHealthCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/*
* Based ON https://github.com/TooTallNate/Java-WebSocket/issues/1077
*/
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import org.java_websocket.WebSocketImpl;
import org.java_websocket.drafts.Draft;
import org.java_websocket.enums.CloseHandshakeType;
Expand All @@ -12,105 +15,98 @@
import org.java_websocket.handshake.*;
import org.java_websocket.util.Charsetfunctions;

import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;

class Draft_HttpHealthCheck extends Draft {

static final int HTTP_HEALTH_CHECK_CLOSE_CODE = 10200;

static Boolean isHttp(ClientHandshake handshakedata) {
String upgradeField = handshakedata.getFieldValue("Upgrade");
return upgradeField == null || upgradeField == "";
}

@Override
public List<ByteBuffer> createHandshake(Handshakedata handshakedata, boolean withcontent) {
byte[] content = Charsetfunctions.asciiBytes("<h1>OCPP-J Websocket OK</h1>");
byte[] header = Charsetfunctions.asciiBytes(
"HTTP/1.0 200 OK\r\n" +
"Mime-Version: 1.0\r\n" +
"Content-Type: text/html\r\n" +
"Content-Length: " + content.length + " \r\n" +
"Connection: close\r\n" +
"\r\n"
);

ByteBuffer bytebuffer = ByteBuffer.allocate(content.length + header.length);
bytebuffer.put(header);
bytebuffer.put(content);
bytebuffer.flip();
return Collections.singletonList(bytebuffer);
}

@Override
public HandshakeState acceptHandshakeAsClient(
ClientHandshake request, ServerHandshake response
) throws InvalidHandshakeException {
throw new InvalidHandshakeException("This draft can't be used on a client");
}

@Override
public HandshakeState acceptHandshakeAsServer(
ClientHandshake handshakedata
) throws InvalidHandshakeException {
return (isHttp(handshakedata)) ? HandshakeState.MATCHED : HandshakeState.NOT_MATCHED;
}

@Override
public ByteBuffer createBinaryFrame(Framedata framedata) {
return null;
}

@Override
public List<Framedata> createFrames(ByteBuffer binary, boolean mask) {
return null;
}

@Override
public List<Framedata> createFrames(String text, boolean mask) {
return null;
}

@Override
public void processFrame(
WebSocketImpl webSocketImpl, Framedata frame
) throws InvalidDataException {
throw new InvalidDataException(0, "This draft can't be used on a client");
}

@Override
public void reset() {
// Nothing to Do
}

@Override
public ClientHandshakeBuilder postProcessHandshakeRequestAsClient(
ClientHandshakeBuilder request
) throws InvalidHandshakeException {
throw new InvalidHandshakeException("This draft can't be used on a client");
}

@Override
public HandshakeBuilder postProcessHandshakeResponseAsServer(
ClientHandshake request, ServerHandshakeBuilder response
) throws InvalidHandshakeException {
return response;
}

@Override
public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataException {
throw new InvalidHandshakeException("This draft doesn't work with frames");
}

@Override
public CloseHandshakeType getCloseHandshakeType() {
return CloseHandshakeType.NONE;
}

@Override
public Draft copyInstance() {
return this;
}
static final int HTTP_HEALTH_CHECK_CLOSE_CODE = 10200;

static Boolean isHttp(ClientHandshake handshakedata) {
String upgradeField = handshakedata.getFieldValue("Upgrade");
return upgradeField == null || upgradeField == "";
}

@Override
public List<ByteBuffer> createHandshake(Handshakedata handshakedata, boolean withcontent) {
byte[] content = Charsetfunctions.asciiBytes("<h1>OCPP-J Websocket OK</h1>");
byte[] header =
Charsetfunctions.asciiBytes(
"HTTP/1.0 200 OK\r\n"
+ "Mime-Version: 1.0\r\n"
+ "Content-Type: text/html\r\n"
+ "Content-Length: "
+ content.length
+ " \r\n"
+ "Connection: close\r\n"
+ "\r\n");

ByteBuffer bytebuffer = ByteBuffer.allocate(content.length + header.length);
bytebuffer.put(header);
bytebuffer.put(content);
bytebuffer.flip();
return Collections.singletonList(bytebuffer);
}

@Override
public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHandshake response)
throws InvalidHandshakeException {
throw new InvalidHandshakeException("This draft can't be used on a client");
}

@Override
public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata)
throws InvalidHandshakeException {
return (isHttp(handshakedata)) ? HandshakeState.MATCHED : HandshakeState.NOT_MATCHED;
}

@Override
public ByteBuffer createBinaryFrame(Framedata framedata) {
return null;
}

@Override
public List<Framedata> createFrames(ByteBuffer binary, boolean mask) {
return null;
}

@Override
public List<Framedata> createFrames(String text, boolean mask) {
return null;
}

@Override
public void processFrame(WebSocketImpl webSocketImpl, Framedata frame)
throws InvalidDataException {
throw new InvalidDataException(0, "This draft can't be used on a client");
}

@Override
public void reset() {
// Nothing to Do
}

@Override
public ClientHandshakeBuilder postProcessHandshakeRequestAsClient(ClientHandshakeBuilder request)
throws InvalidHandshakeException {
throw new InvalidHandshakeException("This draft can't be used on a client");
}

@Override
public HandshakeBuilder postProcessHandshakeResponseAsServer(
ClientHandshake request, ServerHandshakeBuilder response) throws InvalidHandshakeException {
return response;
}

@Override
public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataException {
throw new InvalidHandshakeException("This draft doesn't work with frames");
}

@Override
public CloseHandshakeType getCloseHandshakeType() {
return CloseHandshakeType.NONE;
}

@Override
public Draft copyInstance() {
return this;
}
}
26 changes: 13 additions & 13 deletions OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import eu.chargetime.ocpp.model.CallErrorMessage;
import eu.chargetime.ocpp.model.CallMessage;
import eu.chargetime.ocpp.model.CallResultMessage;
import eu.chargetime.ocpp.model.Message;
import eu.chargetime.ocpp.model.Exclude;

import eu.chargetime.ocpp.model.Message;
import java.lang.reflect.Type;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -101,17 +100,18 @@ public ZonedDateTime deserialize(
static {
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer());
builder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}

@Override
public boolean shouldSkipField(FieldAttributes field) {
return field.getAnnotation(Exclude.class) != null;
}
});
builder.addSerializationExclusionStrategy(
new ExclusionStrategy() {
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}

@Override
public boolean shouldSkipField(FieldAttributes field) {
return field.getAnnotation(Exclude.class) != null;
}
});

gson = builder.disableHtmlEscaping().create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void open(String hostname, int port, ListenerEvents handler) {
drafts) {
@Override
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
if(Draft_HttpHealthCheck.isHttp(clientHandshake)){
if (Draft_HttpHealthCheck.isHttp(clientHandshake)) {
logger.debug("On HTTP Request, for heathcheck");
webSocket.close(Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE);
return;
Expand Down Expand Up @@ -190,8 +190,7 @@ public void onClose(WebSocket webSocket, int code, String reason, boolean remote
reason,
remote);

if(code == Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE)
return;
if (code == Draft_HttpHealthCheck.HTTP_HEALTH_CHECK_CLOSE_CODE) return;

WebSocketReceiver receiver = sockets.get(webSocket);
if (receiver != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

/**
* Exception returned to an outgoing request if an error is reported from the other end.
*/
/** Exception returned to an outgoing request if an error is reported from the other end. */
public class CallErrorException extends Exception {

private String errorCode;
Expand All @@ -37,9 +35,9 @@ public class CallErrorException extends Exception {
/**
* Constructor.
*
* @param errorCode send from the other end.
* @param errorCode send from the other end.
* @param errorDescription describing the error.
* @param payload raw payload send from the other end.
* @param payload raw payload send from the other end.
*/
public CallErrorException(String errorCode, String errorDescription, Object payload) {
super(
Expand Down
6 changes: 4 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public Confirmation handleRequest(Request request) throws UnsupportedFeatureExce
}

@Override
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException {
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
throws UnsupportedFeatureException, OccurenceConstraintException {
return session.completePendingPromise(uniqueId, confirmation);
}

Expand Down Expand Up @@ -171,7 +172,8 @@ public UUID getSessionId() {
return this.session.getSessionId();
}

public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException {
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
throws UnsupportedFeatureException, OccurenceConstraintException {
return session.completePendingPromise(uniqueId, confirmation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public void sendCallResult(String uniqueId, String action, Confirmation confirma
try {
completedHandler.onConfirmationCompleted();
} catch (Throwable e) {
events.onError(uniqueId, "ConfirmationCompletedHandlerFailed", "The confirmation completed callback handler failed with exception " + e.toString(), confirmation);
events.onError(
uniqueId,
"ConfirmationCompletedHandlerFailed",
"The confirmation completed callback handler failed with exception " + e.toString(),
confirmation);
}
}
} catch (NotConnectedException ex) {
Expand All @@ -234,7 +238,8 @@ public void sendCallResult(String uniqueId, String action, Confirmation confirma
public void sendCallError(
String uniqueId, String action, String errorCode, String errorDescription) {
logger.error(
"An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}",
"An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {},"
+ " errorDescription: {}",
uniqueId,
action,
errorCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void accept(Confirmation confirmation, Throwable throwable) {
id,
action,
"InternalError",
"An internal error occurred and the receiver was not able to process the requested Action successfully");
"An internal error occurred and the receiver was not able to process the requested Action"
+ " successfully");
} else if (confirmation == null) {
communicator.sendCallError(
id,
Expand Down
3 changes: 2 additions & 1 deletion ocpp-common/src/main/java/eu/chargetime/ocpp/ISession.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface ISession {

void sendRequest(String action, Request payload, String uuid);

boolean completePendingPromise(String id, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException;
boolean completePendingPromise(String id, Confirmation confirmation)
throws UnsupportedFeatureException, OccurenceConstraintException;

void close();
}
13 changes: 8 additions & 5 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ public Confirmation handleRequest(Request request)
.handleRequest(sessionIdOptional.get(), request);
} else {
logger.error(
"Unable to handle request ({}), the active session was not found for {}.",
request, session.getSessionId());
"Unable to handle request ({}), the active session was not found for"
+ " {}.",
Comment on lines +120 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe skip the strick line length here, it doesn't really improve readability.

request,
session.getSessionId());
throw new IllegalStateException("Active session not found");
}
} else {
Expand All @@ -127,7 +129,8 @@ public Confirmation handleRequest(Request request)
}

@Override
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException {
public boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
throws UnsupportedFeatureException, OccurenceConstraintException {
return session.completePendingPromise(uniqueId, confirmation);
}

Expand Down Expand Up @@ -233,7 +236,8 @@ public CompletableFuture<Confirmation> send(UUID sessionIndex, Request request)
* @return a boolean indicating if pending request was found.
* @throws NotConnectedException Thrown if session with passed sessionIndex is not found
*/
public boolean asyncCompleteRequest(UUID sessionIndex, String uniqueId, Confirmation confirmation) throws NotConnectedException, UnsupportedFeatureException, OccurenceConstraintException {
public boolean asyncCompleteRequest(UUID sessionIndex, String uniqueId, Confirmation confirmation)
throws NotConnectedException, UnsupportedFeatureException, OccurenceConstraintException {
ISession session = sessions.get(sessionIndex);

if (session == null) {
Expand All @@ -246,7 +250,6 @@ public boolean asyncCompleteRequest(UUID sessionIndex, String uniqueId, Confirma
return session.completePendingPromise(uniqueId, confirmation);
}


public boolean isSessionOpen(UUID sessionIndex) {
return sessions.containsKey(sessionIndex);
}
Expand Down
Loading