Search in sources :

Example 1 with NotFoundException

use of core.framework.web.exception.NotFoundException in project core-ng-project by neowu.

the class Scheduler method triggerNow.

public void triggerNow(String name) {
    Trigger trigger = triggers.get(name);
    if (trigger == null)
        throw new NotFoundException("job not found, name=" + name);
    submitJob(trigger, true);
}
Also used : NotFoundException(core.framework.web.exception.NotFoundException)

Example 2 with NotFoundException

use of core.framework.web.exception.NotFoundException in project core-ng-project by neowu.

the class CacheController method get.

public Response get(Request request) {
    ControllerHelper.assertFromLocalNetwork(request.clientIP());
    String name = request.pathParam("name");
    String key = request.pathParam("key");
    CacheImpl<?> cache = cache(name);
    String value = cache.get(key).orElseThrow(() -> new NotFoundException("cache key not found, name=" + name + ", key=" + key));
    return Response.text(value).contentType(ContentType.APPLICATION_JSON);
}
Also used : NotFoundException(core.framework.web.exception.NotFoundException)

Example 3 with NotFoundException

use of core.framework.web.exception.NotFoundException in project core-ng-demo-project by neowu.

the class CustomerService method update.

public CustomerView update(Long id, UpdateCustomerRequest request) {
    Customer customer = customerRepository.get(id).orElseThrow(() -> new NotFoundException("customer not found, id=" + id));
    customer.updatedTime = LocalDateTime.now();
    customer.firstName = request.firstName;
    if (request.lastName != null) {
        customer.lastName = request.lastName;
    }
    customerRepository.update(customer);
    return view(customer);
}
Also used : Customer(app.demo.customer.domain.Customer) NotFoundException(core.framework.web.exception.NotFoundException)

Example 4 with NotFoundException

use of core.framework.web.exception.NotFoundException in project core-ng-project by neowu.

the class HTTPServerErrorHandlerTest method errorResponseWithErrorCodeException.

@Test
void errorResponseWithErrorCodeException() {
    ErrorResponse response = handler.errorResponse(new NotFoundException("test-message", "TEST_ERROR_CODE"), null);
    assertEquals("test-message", response.message);
    assertEquals("TEST_ERROR_CODE", response.errorCode);
    assertEquals("WARN", response.severity);
}
Also used : NotFoundException(core.framework.web.exception.NotFoundException) ErrorResponse(core.framework.impl.web.service.ErrorResponse) Test(org.junit.jupiter.api.Test)

Example 5 with NotFoundException

use of core.framework.web.exception.NotFoundException in project core-ng-project by neowu.

the class StaticDirectoryController method execute.

@Override
public Response execute(Request request) {
    String path = request.pathParam("path");
    Path filePath = contentDirectory.resolve(path);
    logger.debug("requestFile={}", filePath);
    if (!Files.isRegularFile(filePath, LinkOption.NOFOLLOW_LINKS) || !filePath.startsWith(contentDirectory))
        throw new NotFoundException("not found, path=" + request.path());
    Response response = Response.file(filePath);
    ContentType contentType = MimeTypes.get(filePath.getFileName().toString());
    if (contentType != null)
        response.contentType(contentType);
    if (cacheHeader != null)
        response.header(HTTPHeaders.CACHE_CONTROL, cacheHeader);
    return response;
}
Also used : Path(java.nio.file.Path) Response(core.framework.web.Response) ContentType(core.framework.http.ContentType) NotFoundException(core.framework.web.exception.NotFoundException)

Aggregations

NotFoundException (core.framework.web.exception.NotFoundException)5 Customer (app.demo.customer.domain.Customer)1 ContentType (core.framework.http.ContentType)1 ErrorResponse (core.framework.impl.web.service.ErrorResponse)1 Response (core.framework.web.Response)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1