Skip to content

Commit

Permalink
Backward compatibility with Java 6
Browse files Browse the repository at this point in the history
  • Loading branch information
frwiqueueit committed Sep 4, 2018
1 parent d7870ef commit 11f3430
Show file tree
Hide file tree
Showing 22 changed files with 762 additions and 1,180 deletions.
3 changes: 2 additions & 1 deletion SDK/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
Expand Down
Binary file added SDK/libs/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added SDK/libs/javax.servlet-api.jar
Binary file not shown.
Binary file removed SDK/libs/servlet-api.jar
Binary file not shown.
632 changes: 127 additions & 505 deletions SDK/nbproject/build-impl.xml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions SDK/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=4f4bbae4
build.xml.script.CRC32=cd16bf81
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
build.xml.script.CRC32=edafd639
build.xml.stylesheet.CRC32=28e38971@1.44.1.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=4f4bbae4
nbproject/build-impl.xml.script.CRC32=573072ea
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
nbproject/build-impl.xml.script.CRC32=6eb04d1d
nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
22 changes: 10 additions & 12 deletions SDK/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=SDK
application.vendor=queueit
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
Expand All @@ -20,26 +20,24 @@ debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/SDK.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.servlet-api.jar=libs\\servlet-api.jar
file.reference.javax.servlet-api.jar=libs/javax.servlet-api.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.servlet-api.jar}
${file.reference.javax.servlet-api.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.source=1.6
javac.target=1.6
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
Expand All @@ -64,9 +62,9 @@ platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
# Space-separated list of JVM arguments used when running the project
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
Expand Down
43 changes: 24 additions & 19 deletions SDK/src/queueit/knownuserv3/sdk/KnownUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.time.Instant;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -38,7 +41,7 @@ public static RequestValidationResult validateRequestByIntegrationConfig(String
String customerId, HttpServletRequest request,
HttpServletResponse response, String secretKey) throws Exception {

Map<String, String> debugEntries = new HashMap<>();
Map<String, String> debugEntries = new HashMap();

try {
boolean isDebug = getIsDebug(queueitToken, secretKey);
Expand Down Expand Up @@ -92,7 +95,7 @@ public static RequestValidationResult cancelRequestByLocalConfig(
String customerId, HttpServletRequest request,
HttpServletResponse response, String secretKey) throws Exception {

Map<String, String> debugEntries = new HashMap<>();
Map<String, String> debugEntries = new HashMap();

try {
targetUrl = generateTargetUrl(targetUrl, request);
Expand Down Expand Up @@ -148,7 +151,7 @@ public static RequestValidationResult resolveQueueRequestByLocalConfig(
String customerId, HttpServletRequest request,
HttpServletResponse response, String secretKey) throws Exception {

Map<String, String> debugEntries = new HashMap<>();
Map<String, String> debugEntries = new HashMap();

try {
targetUrl = generateTargetUrl(targetUrl, request);
Expand Down Expand Up @@ -240,7 +243,12 @@ private static void setDebugCookie(Map<String, String> debugEntries, HttpServlet
}

private static void logMoreRequestDetails(Map<String, String> debugEntries, HttpServletRequest request) {
debugEntries.put("ServerUtcTime", Instant.now().toString());
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone offset
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());

debugEntries.put("ServerUtcTime", nowAsISO);
debugEntries.put("RequestIP", request.getRemoteAddr());
debugEntries.put("RequestHttpHeader_Via", request.getHeader("via") != null ? request.getHeader("via") : "");
debugEntries.put("RequestHttpHeader_Forwarded", request.getHeader("forwarded") != null ? request.getHeader("forwarded") : "");
Expand All @@ -260,23 +268,20 @@ private static boolean getIsDebug(String queueitToken, String secretKey) throws

private static String getOriginalUrl(HttpServletRequest request) {
return (request.getQueryString() != null)
? String.join("", request.getRequestURL(), "?", request.getQueryString())
? request.getRequestURL().toString() + "?" + request.getQueryString()
: request.getRequestURL().toString();
}

private static RequestValidationResult handleQueueAction(IntegrationConfigModel matchedConfig, String currentUrlWithoutQueueITToken, CustomerIntegration customerIntegrationInfo, String queueitToken, String customerId, HttpServletRequest request, HttpServletResponse response, String secretKey, Map<String, String> debugEntries) throws Exception {
String targetUrl;
switch (matchedConfig.RedirectLogic) {
case "ForecedTargetUrl": // suuport for typo (fall through)
case "ForcedTargetUrl":
targetUrl = matchedConfig.ForcedTargetUrl;
break;
case "EventTargetUrl":
targetUrl = "";
break;
default:
targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request);
break;

if ("ForecedTargetUrl".equals(matchedConfig.RedirectLogic) || // support for typo
"ForcedTargetUrl".equals(matchedConfig.RedirectLogic)) {
targetUrl = matchedConfig.ForcedTargetUrl;
} else if ("EventTargetUrl".equals(matchedConfig.RedirectLogic)) {
targetUrl = "";
} else {
targetUrl = generateTargetUrl(currentUrlWithoutQueueITToken, request);
}

QueueEventConfig queueConfig = new QueueEventConfig();
Expand Down Expand Up @@ -315,8 +320,8 @@ private static String generateTargetUrl(String originalTargetUrl, HttpServletReq
return !isQueueAjaxCall(request)
? originalTargetUrl
: URLDecoder.decode(request.getHeader(QueueITAjaxHeaderKey), "UTF-8");
} catch (UnsupportedEncodingException e) {
}
} catch (UnsupportedEncodingException e) {
}
return "";
}

Expand Down
66 changes: 35 additions & 31 deletions SDK/src/queueit/knownuserv3/sdk/QueueITHelpers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package queueit.knownuserv3.sdk;

import java.util.AbstractCollection;
import java.util.Iterator;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

Expand All @@ -26,6 +28,18 @@ public static boolean isLong(String value) {
return false;
}
}

public static String join(String delimiter, AbstractCollection<String> s) {
if (s == null || s.isEmpty()) {
return "";
}
Iterator<String> iter = s.iterator();
StringBuilder builder = new StringBuilder(iter.next());
while (iter.hasNext()) {
builder.append(delimiter).append(iter.next());
}
return builder.toString();
}
}

class QueueParameterHelper {
Expand Down Expand Up @@ -53,38 +67,28 @@ public static QueueUrlParams extractQueueParams(String queueitToken) {
for (String paramKeyValue : paramList) {
String[] keyValueArr = paramKeyValue.split(KeyValueSeparatorChar);

switch (keyValueArr[0]) {
case TimeStampKey:
if (Utils.isLong(keyValueArr[1])) {
result.setTimeStamp(Long.parseLong(keyValueArr[1]));
} else {
result.setTimeStamp(0);
}
break;
case CookieValidityMinutesKey: {
if (Utils.isInteger(keyValueArr[1])) {
result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1]));
} else {
result.setCookieValidityMinutes(null);
}
break;
if (TimeStampKey.equals(keyValueArr[0])) {
if (Utils.isLong(keyValueArr[1])) {
result.setTimeStamp(Long.parseLong(keyValueArr[1]));
} else {
result.setTimeStamp(0);
}

case EventIdKey:
result.setEventId(keyValueArr[1]);
break;
case QueueIdKey:
result.setQueueId(keyValueArr[1]);
break;
case ExtendableCookieKey:
result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1]));
break;
case HashKey:
result.setHashCode(keyValueArr[1]);
break;
case RedirectTypeKey:
result.setRedirectType(keyValueArr[1]);
break;
} else if (CookieValidityMinutesKey.equals(keyValueArr[0])) {
if (Utils.isInteger(keyValueArr[1])) {
result.setCookieValidityMinutes(Integer.parseInt(keyValueArr[1]));
} else {
result.setCookieValidityMinutes(null);
}
} else if (EventIdKey.equals(keyValueArr[0])) {
result.setEventId(keyValueArr[1]);
} else if (QueueIdKey.equals(keyValueArr[0])) {
result.setQueueId(keyValueArr[1]);
} else if (ExtendableCookieKey.equals(keyValueArr[0])) {
result.setExtendableCookie(Boolean.parseBoolean(keyValueArr[1]));
} else if (HashKey.equals(keyValueArr[0])) {
result.setHashCode(keyValueArr[1]);
} else if (RedirectTypeKey.equals(keyValueArr[0])) {
result.setRedirectType(keyValueArr[1]);
}
}
String queueITTokenWithoutHash = result.getQueueITToken().replace(KeyValueSeparatorGroupChar + HashKey + KeyValueSeparatorChar + result.getHashCode(), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String getAjaxRedirectUrl() {
if (!Utils.isNullOrWhiteSpace(redirectUrl)) {
return URLEncoder.encode(redirectUrl, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) {
}
return "";
}
Expand Down
17 changes: 7 additions & 10 deletions SDK/src/queueit/knownuserv3/sdk/UserInQueueService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Objects;

interface IUserInQueueService {

Expand All @@ -23,15 +22,14 @@ void extendQueueCookie(
String eventId,
int cookieValidityMinutes,
String cookieDomain,
String secretKey
);
String secretKey);

RequestValidationResult getIgnoreActionResult();
}

class UserInQueueService implements IUserInQueueService {

public static final String SDK_VERSION = "3.5.1";
public static final String SDK_VERSION = "3.5.2";
private final IUserInQueueStateRepository _userInQueueStateRepository;

public UserInQueueService(IUserInQueueStateRepository queueStateRepository) {
Expand All @@ -44,8 +42,7 @@ public RequestValidationResult validateQueueRequest(
String queueitToken,
QueueEventConfig config,
String customerId,
String secretKey
) throws Exception {
String secretKey) throws Exception {
StateInfo stateInfo = this._userInQueueStateRepository.getState(config.getEventId(), config.getCookieValidityMinute(), secretKey, true);
if (stateInfo.isValid()) {
if (stateInfo.isStateExtendable() && config.getExtendCookieValidity()) {
Expand Down Expand Up @@ -77,11 +74,11 @@ private RequestValidationResult getQueueITTokenValidationResult(
String customerId,
String secretKey) throws Exception {
String calculatedHash = HashHelper.generateSHA256Hash(secretKey, queueParams.getQueueITTokenWithoutHash());
if (!Objects.equals(calculatedHash.toUpperCase(), queueParams.getHashCode().toUpperCase())) {
if (!calculatedHash.toUpperCase().equals(queueParams.getHashCode().toUpperCase())) {
return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "hash");
}

if (!Objects.equals(queueParams.getEventId().toUpperCase(), eventId.toUpperCase())) {
if (!eventId.toUpperCase().equals(queueParams.getEventId().toUpperCase())) {
return getVaidationErrorResult(customerId, targetUrl, config, queueParams, "eventid");
}

Expand Down Expand Up @@ -141,7 +138,7 @@ private String getQueryString(
int configVersion,
String culture,
String layoutName) throws Exception {
ArrayList<String> queryStringList = new ArrayList<>();
ArrayList<String> queryStringList = new ArrayList();
queryStringList.add("c=" + URLEncoder.encode(customerId, "UTF-8"));
queryStringList.add("e=" + URLEncoder.encode(eventId, "UTF-8"));
queryStringList.add("ver=v3-java-" + URLEncoder.encode(SDK_VERSION, "UTF-8"));
Expand All @@ -155,7 +152,7 @@ private String getQueryString(
queryStringList.add("l=" + URLEncoder.encode(layoutName, "UTF-8"));
}

return String.join("&", queryStringList);
return Utils.join("&", queryStringList);
}

@Override
Expand Down
Loading

0 comments on commit 11f3430

Please sign in to comment.