Skip to content

Commit

Permalink
Improved error logging and shutdown process.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Oct 25, 2021
1 parent 24f076f commit 09f630e
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Proteus Changelog.
## Unreleased
### No issue

**Improve Optional bean parsing.**


[24f076fb72fc3c1](https://github.com/noboomu/proteus/commit/24f076fb72fc3c1) Joshua Bauer *2021-05-11 21:29:17*

**Bump dependency versions. Update favicon.**


Expand Down
35 changes: 35 additions & 0 deletions proteus-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ Proteus Changelog.
## Unreleased
### No issue

**Improve Optional bean parsing.**


[24f076fb72fc3c1](https://github.com/noboomu/proteus/commit/24f076fb72fc3c1) Joshua Bauer *2021-05-11 21:29:17*

**Bump dependency versions. Update favicon.**


[4777bce4c516e99](https://github.com/noboomu/proteus/commit/4777bce4c516e99) Joshua Bauer *2021-04-02 18:19:35*

**Update README.md**


[8915888e8190521](https://github.com/noboomu/proteus/commit/8915888e8190521) JL Bauer *2021-03-20 05:19:59*

**Rollback swagger ui version.**


[81396a503e7b6aa](https://github.com/noboomu/proteus/commit/81396a503e7b6aa) Joshua Bauer *2021-03-11 00:48:39*

**Bump swagger version and hide swagger models.**


[e69020001b4eb66](https://github.com/noboomu/proteus/commit/e69020001b4eb66) Joshua Bauer *2021-03-11 00:11:44*

**Bump version.**


[7574ab99246d6a3](https://github.com/noboomu/proteus/commit/7574ab99246d6a3) Joshua Bauer *2021-03-10 00:35:10*

**Rework form processing.**


[60edfa65d52d089](https://github.com/noboomu/proteus/commit/60edfa65d52d089) Joshua Bauer *2021-03-10 00:28:19*

**Forms**


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void start()
public void stopped()
{
log.info("Services are stopped");
undertow.stop();

}

public void healthy()
Expand All @@ -202,7 +202,6 @@ public void healthy()

printStatus();

running.set(true);
}

public void failure(Service service)
Expand Down Expand Up @@ -253,6 +252,7 @@ public void failure(Service service)

buildServer();


undertow.start();

Duration timeout = config.getDuration("application.services.timeout");
Expand All @@ -268,6 +268,10 @@ public void failure(Service service)
log.error("Failed to start services",e);
}



this.running.set(true);

// serviceManager.startAsync();

}
Expand All @@ -283,6 +287,8 @@ public void shutdown() throws TimeoutException

log.info("Shutting down...");

undertow.stop();

serviceManager.stopAsync().awaitStopped(2, TimeUnit.SECONDS);

this.running.set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void startAsync(final Executor executor, final Runnable runnable)
}

/**
* Abort current request and respond with redirect. Returns empty @ServerResponse for convenience.
* Abort current request and respond with 302 redirect. Returns empty @ServerResponse for convenience.
* @param location
* @param includeParameters
* @return serverResponse
Expand All @@ -191,8 +191,25 @@ public <T> ServerResponse<T> redirect(String location, boolean includeParameters
{

exchange.setRelativePath("/");
exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, location, includeParameters));
exchange.setStatusCode(302);
exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, location, includeParameters));
exchange.endExchange();

return new ServerResponse<>();
}

/**
* Abort current request and respond with 301 redirect. Returns empty @ServerResponse for convenience.
* @param location
* @param includeParameters
* @return serverResponse
*/
public <T> ServerResponse<T> redirectPermanently(String location, boolean includeParameters)
{

exchange.setRelativePath("/");
exchange.setStatusCode(301);
exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, location, includeParameters));
exchange.endExchange();

return new ServerResponse<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,14 @@ public void send(final HttpHandler handler, final HttpServerExchange exchange) t
return;
}

// if(location != null && (status == 301 || status == 302))
// {
// exchange.setRelativePath("/");
// exchange.setStatusCode(status);
// exchange.getResponseHeaders().put(Headers.LOCATION, RedirectBuilder.redirect(exchange, location, true));
// exchange.endExchange();
// }

if (this.location != null) {
exchange.getResponseHeaders().put(Headers.LOCATION, this.location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))
}
}

log.debug("Scanning methods for class " + clazz.getName());
log.debug("Scanning methods for class {}", clazz.getName());

int nameIndex = 1;

Expand All @@ -411,15 +411,15 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))
continue;
}

log.debug("Scanning method " + m.getName() + "\n");
log.debug("\n\nScanning method: {}\n", m.getName());

EndpointInfo endpointInfo = new EndpointInfo();

String producesContentType = "*/*";
String consumesContentType = "*/*";

Boolean isBlocking = false;
Boolean isDebug = false;
boolean isBlocking = false;
boolean isDebug = false;

Optional<Blocking> blockingAnnotation = Optional.ofNullable(m.getAnnotation(Blocking.class));

Expand Down Expand Up @@ -489,7 +489,7 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))
methodPath = Extractors.pathTemplateFromMethod.apply(m).replaceAll("\\/\\/", "\\/");
} catch (Exception e)
{
log.error(e.getMessage() + " for " + m, e);
log.error("Error parsing method path for {}",m.getName(), e);
continue;
}

Expand Down Expand Up @@ -563,7 +563,8 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))

} catch (Exception e)
{
log.error(e.getMessage(), e);
log.error("Error processing path parameter {} for method {}",p.getName(),m.getName(),e);
throw e;
}
}

Expand All @@ -582,15 +583,17 @@ else if (t.equals(HttpServerExchange.class) || t.equals(ServerRequest.class))

}

Arrays.stream(m.getParameters()).forEachOrdered(p ->
List<Parameter> parameters = Arrays.stream(m.getParameters()).collect(Collectors.toList());

for(Parameter p : parameters)
{

Type type = p.getParameterizedType();

try
{

log.debug("Parameter " + p.getName() + " of type " + type);
log.debug("Method {} parameter {} type {}", m.getName(), p.getName() , type);

if (p.getType().equals(ServerRequest.class))
{
Expand Down Expand Up @@ -700,7 +703,7 @@ else if (handler.equals(TypeHandler.FromStringType))
}
}

log.debug("beanParam handler: " + t);
log.debug("beanParam handler: {}",t);

if (t.equals(TypeHandler.OptionalModelType) || t.equals(TypeHandler.ModelType))
{
Expand Down Expand Up @@ -809,7 +812,8 @@ else if (t.equals(TypeHandler.OptionalBeanListFromStringType) || t.equals(TypeHa

} catch (Exception e)
{
log.error("method builder: \nstatement: " + t.statement + "\npType: " + pType + "\np.name(): " + p.getName() + "\nerasedType: " + erasedType);
log.error("error adding statement to method {} for parameter {}:\nstatement: {}\ntype: {} erased type: {}\n",m.getName(), p.getName(), t.statement, pType, erasedType,e);
throw e;
}

}
Expand All @@ -822,10 +826,11 @@ else if (t.equals(TypeHandler.OptionalBeanListFromStringType) || t.equals(TypeHa

} catch (Exception e)
{
log.error(e.getMessage(), e);
log.error("Failed to generate statement for method {}",m.getName(),e);
throw e;
}

});
}

methodBuilder.addCode("$L", "\n");

Expand Down Expand Up @@ -1087,6 +1092,7 @@ else if (isDebug)
} catch (Exception e)
{
log.error("Failed to register endpoint {}", endpointInfo, e);
throw e;
}

}
Expand Down Expand Up @@ -1259,7 +1265,7 @@ protected static String typeReferenceNameForParameterizedType(Type type)

if (typeName.contains("Optional"))
{
log.warn("For an optional named: " + typeName);
log.warn("Type is for an optional named {}", typeName);
}

Matcher matcher = TYPE_NAME_PATTERN.matcher(typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public void exchangePlaintext(HttpServerExchange exchange)
response("Hello, World!").textPlain().send(exchange);

}



@GET
@Path("exchange/plaintext2")
Expand Down Expand Up @@ -291,15 +293,15 @@ public ServerResponse<Set<Long>> genericOptionalSet( ServerRequest request, @Qu
@Produces(MediaType.WILDCARD)
public ServerResponse<Void> testPermanentRedirect()
{
return response().redirectPermanently("https://google.com");
return response().redirectPermanently("v1/response/debug/blocking");
}

@GET
@Path("redirect")
@Produces(MediaType.WILDCARD)
public ServerResponse<Void> testRedirect()
{
return response().redirect("https://google.com");
return response().redirect("v1/response/debug/blocking");
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,21 +418,21 @@ public void responseFutureResponseMap()
public void testRedirect()
{

given().when().get("v1/tests/redirect").then().statusCode(200).and().header("Server", "gws");
given().when().redirects().follow(false).get("v1/tests/redirect").then().statusCode(302).and().header("Server", "proteus").and().header("Location","v1/response/debug/blocking");
}

@Test
public void testRedirectFoundCode()
{

given().when().redirects().follow(false).get("v1/tests/redirect").then().statusCode(302);
given().when().redirects().follow(false).get("v1/tests/redirect").then().statusCode(302).and().header("Location","v1/response/debug/blocking");
}

@Test
public void testRedirectMovedPermanentlyCode()
{

given().when().redirects().follow(false).get("v1/tests/redirect/permanent").then().statusCode(301);
given().when().redirects().follow(false).get("v1/tests/redirect/permanent").then().statusCode(301).and().header("Location","v1/response/debug/blocking");
}

@Test
Expand Down

0 comments on commit 09f630e

Please sign in to comment.