Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ezyhttp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
</parent>

<artifactId>ezyhttp-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
</parent>

<artifactId>ezyhttp-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ResourceDownloadManager
public static final int DEFAULT_BUFFER_SIZE = 1024;
public static final int DEFAULT_TIMEOUT = 15 * 60 * 1000;
public static final int DEFAULT_THREAD_POOL_SIZE =
Runtime.getRuntime().availableProcessors() * 2;
Runtime.getRuntime().availableProcessors();

public ResourceDownloadManager() {
this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ResourceUploadManager
public static final int DEFAULT_TIMEOUT = 15 * 60 * 1000;
public static final long UNLIMITED_UPLOAD_SIZE = -1;
public static final int DEFAULT_THREAD_POOL_SIZE =
Runtime.getRuntime().availableProcessors() * 2;
Runtime.getRuntime().availableProcessors();

public ResourceUploadManager() {
this(
Expand All @@ -45,7 +45,9 @@ public ResourceUploadManager() {

public ResourceUploadManager(
int capacity,
int threadPoolSize, int bufferSize) {
int threadPoolSize,
int bufferSize
) {
this.capacity = capacity;
this.threadPoolSize = threadPoolSize;
this.bufferSize = bufferSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;

public class BytesRangeFileInputStreamTest {
Expand Down Expand Up @@ -323,4 +322,30 @@ public void seekIoErrorTest() {
// then
Asserts.assertEqualsType(e, IOException.class);
}

@Test
public void readTest() throws Exception {
// given
final String pomFilePath = "pom.xml";
final File pomFile = new File(pomFilePath);
final long fileLength = pomFile.length();
final String range = "bytes=0-1";

final BytesRangeFileInputStream sut = new BytesRangeFileInputStream(
pomFilePath,
range
);
FieldUtil.setFieldValue(
sut,
"from",
fileLength
);

// when
Throwable e = Asserts.assertThrows(() -> sut.read());

// then
sut.close();
Asserts.assertEqualsType(e, UnsupportedOperationException.class);
}
}
2 changes: 1 addition & 1 deletion ezyhttp-server-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
</parent>

<artifactId>ezyhttp-server-boot</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ezyhttp-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.tvd12</groupId>
<artifactId>ezyhttp</artifactId>
<version>1.4.6</version>
<version>1.4.7</version>
</parent>

<artifactId>ezyhttp-server-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@
import com.tvd12.ezyhttp.server.core.resources.ResourceResolvers;
import com.tvd12.ezyhttp.server.core.util.InterceptorAnnotations;
import com.tvd12.ezyhttp.server.core.util.ServiceAnnotations;
import com.tvd12.ezyhttp.server.core.view.AbsentMessageResolver;
import com.tvd12.ezyhttp.server.core.view.MessageProvider;
import com.tvd12.ezyhttp.server.core.view.TemplateResolver;
import com.tvd12.ezyhttp.server.core.view.ViewContext;
import com.tvd12.ezyhttp.server.core.view.ViewContextBuilder;
import com.tvd12.ezyhttp.server.core.view.ViewDecorator;
import com.tvd12.ezyhttp.server.core.view.ViewDialect;
import com.tvd12.ezyhttp.server.core.view.*;

@SuppressWarnings({"rawtypes", "unchecked", "MethodCount"})
public class ApplicationContextBuilder implements EzyBuilder<ApplicationContext> {
Expand Down Expand Up @@ -408,6 +402,9 @@ protected ViewContext buildViewContext(EzyBeanContext beanContext) {
.viewDecorators(beanContext.getSingletonsOf(ViewDecorator.class))
.messageProviders(beanContext.getSingletonsOf(MessageProvider.class))
.absentMessageResolver(beanContext.getSingleton(AbsentMessageResolver.class))
.templateInputStreamLoaders(
beanContext.getSingletonsOf(ViewTemplateInputStreamLoader.class)
)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,29 @@ public class ResourceRequestHandler implements RequestHandler {
private final EzyInputStreamLoader inputStreamLoader;
private final ResourceDownloadManager downloadManager;
private final int defaultTimeout;
private final EzyResultCallback<Boolean> callback;
private final ActualContentTypeDetector actualContentTypeDetector =
ActualContentTypeDetector.getInstance();

public ResourceRequestHandler(
String resourcePath,
String resourceURI,
String resourceExtension,
EzyInputStreamLoader inputStreamLoader,
ResourceDownloadManager downloadManager,
int defaultTimeout
) {
this(
resourcePath,
resourceURI,
resourceExtension,
inputStreamLoader,
downloadManager,
defaultTimeout,
null
);
}

public ResourceRequestHandler(
String resourcePath,
String resourceURI,
Expand Down Expand Up @@ -170,13 +190,19 @@ public void onResponse(Boolean response) {
processWithLogException(inputStream::close);
servletResponse.setStatus(statusCodeFinal);
asyncContext.complete();
if (callback != null) {
callback.onResponse(response);
}
}

@Override
public void onException(Exception e) {
processWithLogException(inputStream::close);
servletResponse.setStatus(StatusCodes.INTERNAL_SERVER_ERROR);
asyncContext.complete();
if (callback != null) {
callback.onException(e);
}
}
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.tvd12.ezyhttp.server.core.request;

import java.util.Map;
import com.tvd12.ezyfox.util.EzyReleasable;
import com.tvd12.ezyhttp.core.constant.HttpMethod;
import com.tvd12.ezyhttp.core.data.BodyData;

import javax.servlet.AsyncContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

import com.tvd12.ezyfox.util.EzyReleasable;
import com.tvd12.ezyhttp.core.constant.HttpMethod;
import com.tvd12.ezyhttp.core.data.BodyData;
import static com.tvd12.ezyfox.io.EzyStrings.*;

@SuppressWarnings("MethodCount")
public interface RequestArguments extends BodyData, EzyReleasable {

HttpMethod getMethod();
Expand Down Expand Up @@ -77,6 +79,39 @@ default String getCookieValue(String name, String defaultValue) {
return answer != null ? answer : defaultValue;
}

String getRequestValue(String argumentName);

default String getRequestValueAnyway(
String... argumentNames
) {
String value = null;
for (String argumentName : argumentNames) {
value = getRequestValueAnyway(argumentName);
if (isNotBlank(value)) {
break;
}
}
return value;
}

default String getRequestValueAnyway(
String argumentName
) {
String value = getRequestValue(argumentName);
String argumentNameLowerCase = EMPTY_STRING;
if (isBlank(value)) {
argumentNameLowerCase = argumentName.toLowerCase();
value = getRequestValue(argumentNameLowerCase);
}
if (isBlank(value)) {
String argumentNameFirstUpperCase =
argumentNameLowerCase.substring(0, 1).toUpperCase() +
argumentNameLowerCase.substring(1);
value = getRequestValue(argumentNameFirstUpperCase);
}
return value;
}

Map<String, Object> getRedirectionAttributes();

<T> T getRedirectionAttribute(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;

import static com.tvd12.ezyfox.io.EzyStrings.EMPTY_STRING;
import static com.tvd12.ezyfox.io.EzyStrings.isBlank;

@SuppressWarnings("unchecked")
public class SimpleRequestArguments implements RequestArguments {

Expand Down Expand Up @@ -242,18 +242,49 @@ public Cookie getCookie(String name) {
return cookieMap != null ? cookieMap.get(name) : null;
}

@Override
public String getRequestValue(String argumentName) {
String value = getCookieValue(argumentName);
if (isBlank(value)) {
value = getHeader(argumentName);
}
if (isBlank(value)) {
value = getParameter(argumentName);
}
if (isBlank(value)) {
value = getPathVariable(argumentName);
}
if (isBlank(value)) {
value = Objects.toString(
request.getAttribute(argumentName),
null
);
}
if (isBlank(value)) {
value = getArgument(argumentName);
}
return value;
}

public void setRedirectionAttributesFromCookie() {
Cookie cookie = getCookie(CoreConstants.COOKIE_REDIRECT_ATTRIBUTES_NAME);
Cookie cookie = getCookie(CoreConstants
.COOKIE_REDIRECT_ATTRIBUTES_NAME);
if (cookie == null) {
return;
}
try {
String value = EzyBase64.decodeUtf(cookie.getValue());
this.redirectionAttributes = objectMapper.readValue(value, Map.class);
this.redirectionAttributes = objectMapper.readValue(
value,
Map.class
);
} catch (Exception e) {
// do nothing
}
Cookie newCookie = new Cookie(CoreConstants.COOKIE_REDIRECT_ATTRIBUTES_NAME, "");
Cookie newCookie = new Cookie(
CoreConstants.COOKIE_REDIRECT_ATTRIBUTES_NAME,
EMPTY_STRING
);
newCookie.setMaxAge(0);
response.addCookie(newCookie);
}
Expand All @@ -267,9 +298,14 @@ public <T> T getRedirectionAttribute(String name) {
}

@Override
public <T> T getRedirectionAttribute(String name, Class<T> outType) {
public <T> T getRedirectionAttribute(
String name,
Class<T> outType
) {
Object value = getRedirectionAttribute(name);
return value != null ? objectMapper.convertValue(value, outType) : null;
return value != null
? objectMapper.convertValue(value, outType)
: null;
}

@Override
Expand Down
Loading
Loading