Skip to content

Commit

Permalink
[69] robo4j-socket-http update
Browse files Browse the repository at this point in the history
  • Loading branch information
mirage22 committed Oct 8, 2024
1 parent 7928ac7 commit a603936
Show file tree
Hide file tree
Showing 10 changed files with 524 additions and 515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.robo4j.util.StringConstants;
import com.robo4j.util.Utf8Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

Expand All @@ -28,73 +30,68 @@
* @author Miroslav Wengner (@miragemiko)
*/
public final class RoboHttpUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(RoboHttpUtils.class);

public static final String NEW_LINE_MAC = "\r";
public static final String NEW_LINE_UNIX = "\n";
public static final String NEW_LINE_MAC = "\r";
public static final String NEW_LINE_UNIX = "\n";

public static final int DEFAULT_PORT = 8042;
public static final int DEFAULT_UDP_PORT = 9042;
public static final String HTTP_PROPERTY_PROTOCOL = "protocol";
public static final String PROPERTY_TARGET = "target";
public static final String PROPERTY_HOST = "host";
public static final String PROPERTY_SOCKET_PORT = "port";
public static final String PROPERTY_CODEC_REGISTRY = "codecRegistry";
public static final String PROPERTY_CODEC_PACKAGES = "packages";
public static final String PROPERTY_UNIT_PATHS_CONFIG = "unitPathsConfig";
public static final String PROPERTY_BUFFER_CAPACITY = "bufferCapacity";
public static final String PROPERTY_BYTE_BUFFER = "byteBuffer";
public static final String PROPERTY_TIMEOUT = "timeout";
public static final int DEFAULT_PORT = 8042;
public static final int DEFAULT_UDP_PORT = 9042;
public static final String HTTP_PROPERTY_PROTOCOL = "protocol";
public static final String PROPERTY_TARGET = "target";
public static final String PROPERTY_HOST = "host";
public static final String PROPERTY_SOCKET_PORT = "port";
public static final String PROPERTY_CODEC_REGISTRY = "codecRegistry";
public static final String PROPERTY_CODEC_PACKAGES = "packages";
public static final String PROPERTY_UNIT_PATHS_CONFIG = "unitPathsConfig";
public static final String PROPERTY_BUFFER_CAPACITY = "bufferCapacity";
public static final String PROPERTY_BYTE_BUFFER = "byteBuffer";
public static final String PROPERTY_TIMEOUT = "timeout";

public static void decorateByNewLine(StringBuilder sb) {
sb.append(NEW_LINE_MAC).append(NEW_LINE_UNIX);
}
public static void decorateByNewLine(StringBuilder sb) {
sb.append(NEW_LINE_MAC).append(NEW_LINE_UNIX);
}

public static String correctLine(String line) {
return line == null ? StringConstants.EMPTY : line;
}
public static String correctLine(String line) {
return line == null ? StringConstants.EMPTY : line;
}

/**
* create host header note
*
* @param host
* desired host
* @param port
* default port is 80
* @return host string
*/
public static String createHost(String host, Integer port) {
Objects.requireNonNull(host, "host not available");
Objects.requireNonNull(host, "port not available");
return new StringBuilder(host).append(Utf8Constant.UTF8_COLON).append(port).toString();
}
/**
* create host header note
*
* @param host desired host
* @param port default port is 80
* @return host string
*/
public static String createHost(String host, Integer port) {
Objects.requireNonNull(host, "host not available");
Objects.requireNonNull(host, "port not available");
return host + Utf8Constant.UTF8_COLON + port;
}

/**
* report time in moment M from start time
*
* @param clazz
* desired class
* @param message
* message
* @param start
* start time
*/
public static void printMeasuredTime(Class<?> clazz, String message, long start) {
System.out.println(String.format("%s message: %s duration: %d%n", clazz.getSimpleName(), message,
System.currentTimeMillis() - start));
}
/**
* report time in moment M from start time
*
* @param clazz desired class
* @param message message
* @param start start time
*/
public static void printMeasuredTime(Class<?> clazz, String message, long start) {
LOGGER.info("{} message: {} duration: {}", clazz.getSimpleName(), message, System.currentTimeMillis() - start);
}

// TODO: 1/26/18 (miro
public static boolean validatePackages(String packages) {
if (packages == null) {
return false;
}
for (int i = 0; i < packages.length(); i++) {
char c = packages.charAt(i);
if (Character.isWhitespace(c)) {
return false;
}
}
return true;
}
// TODO: 1/26/18 (miro) review and simplify
public static boolean validatePackages(String packages) {
if (packages == null) {
return false;
}
for (int i = 0; i < packages.length(); i++) {
char c = packages.charAt(i);
if (Character.isWhitespace(c)) {
return false;
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ private static <T> void printDecodedMessage(T decodedMessage) {
LOGGER.debug("decodedMessage:{}", decodedMessage);
}

private static void printJson(String resultJson) {
LOGGER.debug("resultJson:{}", resultJson);
}

private static Map<String, TestPerson> getStringTestPersonMap() {
TestPerson testPerson2 = new TestPerson();
testPerson2.setName("name2");
Expand All @@ -252,4 +248,8 @@ private static Map<String, TestPerson> getStringTestPersonMap() {
return personMap;
}

private static void printJson(String resultJson) {
LOGGER.debug("json:{}", resultJson);
}

}
Loading

0 comments on commit a603936

Please sign in to comment.