Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3a69914
refactor: minor
predic8 Dec 4, 2025
80c313d
feat: terminal colors
predic8 Dec 4, 2025
c7fec61
Merge branch 'master' into tutorial-fail-on-error
predic8 Dec 5, 2025
4008f2b
feat: reorganized utility classes into 'text' and 'xml' packages, add…
predic8 Dec 6, 2025
9c69104
refactor: cleanup unused methods, enhance type-checking, and suppress…
predic8 Dec 6, 2025
1b8c173
refactor: adjust default behavior in `TerminalColors` and improve cod…
predic8 Dec 6, 2025
7a6289f
fix: improve OS detection logic and update roadmap for 7.1.0 prep
predic8 Dec 6, 2025
f3981a1
Merge remote-tracking branch 'origin/master' into tutorial-fail-on-error
predic8 Dec 6, 2025
792ca26
refactor: Fixed OSUtil win vs. windows, consolidate `StringUtil` and …
predic8 Dec 6, 2025
1bf6d8d
refactor: simplify imports in `TextUtilTest` and `TerminalColors` by …
predic8 Dec 6, 2025
06d83e6
feat: enhance logging with terminal color support and improve OS util…
predic8 Dec 7, 2025
604425a
refactor: streamline OS utility methods and terminal color logic
predic8 Dec 7, 2025
c51d46b
feat: enhance terminal color support and fix OS detection issues
predic8 Dec 7, 2025
a096c33
feat: improve terminal environment handling and simplify ANSI support…
predic8 Dec 7, 2025
474f79e
refactor: rename terminal color environment variable and property for…
predic8 Dec 7, 2025
dc77934
feat: add support for disabling terminal colors via environment varia…
predic8 Dec 7, 2025
e7de265
refactor: remove `isDumbTerminal` method and inline logic in `Termina…
predic8 Dec 7, 2025
b9aa428
feat: enhance and standardize terminal color support
predic8 Dec 7, 2025
4e404ab
feat: add `membrane.disable.term.colors` system property to batch script
predic8 Dec 7, 2025
f248bcf
feat: extend terminal compatibility detection in shell script
predic8 Dec 7, 2025
103248b
feat: extend terminal compatibility detection in shell script
predic8 Dec 7, 2025
16ef6d2
Merge branch 'master' into tutorial-fail-on-error
predic8 Dec 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
*/
public class JsonSchemaGenerator extends AbstractGrammar {

public static final String MEMBRANE_SCHEMA_JSON_FILENAME = "membrane.schema.json";
Comment thread
predic8 marked this conversation as resolved.

private final Map<String, Boolean> topLevelAdded = new HashMap<>();

public JsonSchemaGenerator(ProcessingEnvironment processingEnv) {
Expand Down Expand Up @@ -166,7 +168,7 @@ private FileObject createFile(MainInfo main) throws IOException {
.createResource(
CLASS_OUTPUT,
main.getAnnotation().outputPackage().replaceAll("\\.spring$", ".json"),
"membrane.schema.json",
MEMBRANE_SCHEMA_JSON_FILENAME,
sources.toArray(new Element[0])
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void activationRun() {
uidsToRemove.add(bd.getUid());
} catch (Exception e) {
log.error("Could not handle {} {}/{}", bd.getAction(), bd.getNamespace(), bd.getName(), e);
throw new RuntimeException(e);
}
}
for (String uid : uidsToRemove)
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/com/predic8/membrane/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public class Constants {

public static final String MEMBRANE_HOME = "MEMBRANE_HOME";

public static final String CRLF = "" + ((char) 13) + ((char) 10);
// Java System Properties

/**
* System property set by start script based on MEMBRANE_DISABLE_TERM_COLORS detection.
* Users should use the environment variable instead.
*/
public static final String MEMBRANE_DISABLE_TERM_COLORS_PROPERTY = "membrane.disable.term.colors";

public static final String CRLF = "" + ((char) 13) + ((char) 10);

public static final byte[] CRLF_BYTES = { 13, 10 };

Expand All @@ -42,7 +50,7 @@ public class Constants {
Properties p = new Properties(); // Development
p.load(new FileInputStream("target/maven-archiver/pom.properties"));
version = p.getProperty("version") + " - DEVELOPMENT";
} catch (Exception e2) {
} catch (Exception ignored) {
}
}
VERSION = version;
Expand Down
31 changes: 11 additions & 20 deletions core/src/main/java/com/predic8/membrane/core/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.predic8.membrane.core.util.DNSCache;
import com.predic8.membrane.core.util.TimerManager;
import com.predic8.membrane.core.util.URIFactory;
import com.predic8.membrane.core.util.text.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
Expand All @@ -67,10 +68,11 @@
import java.util.*;
import java.util.concurrent.ExecutorService;

import static com.predic8.membrane.core.Constants.PRODUCT_NAME;
import static com.predic8.membrane.core.Constants.VERSION;
import static com.predic8.membrane.core.Constants.*;
import static com.predic8.membrane.core.jmx.JmxExporter.JMX_EXPORTER_NAME;
import static com.predic8.membrane.core.util.DLPUtil.displayTraceWarning;
import static com.predic8.membrane.core.util.text.TerminalColors.BRIGHT_CYAN;
import static com.predic8.membrane.core.util.text.TerminalColors.RESET;
import static java.util.concurrent.Executors.newSingleThreadExecutor;

/**
Expand Down Expand Up @@ -355,7 +357,11 @@ public void start() {

ApiInfo.logInfosAboutStartedProxies(ruleManager);
if (!asynchronousInitialization)
log.info("{} {} up and running!", PRODUCT_NAME, VERSION);
logStartupMessage();
}

private static void logStartupMessage() {
log.info("{}{} {} up and running!{}", BRIGHT_CYAN(), PRODUCT_NAME, VERSION, RESET());
}

private void startJmx() {
Expand Down Expand Up @@ -662,40 +668,25 @@ public GlobalInterceptor getGlobalInterceptor() {
return globalInterceptor;
}

public synchronized boolean isAsynchronousInitialization() {
return asynchronousInitialization;
}

public synchronized void setAsynchronousInitialization(boolean asynchronousInitialization) {
this.asynchronousInitialization = asynchronousInitialization;
notifyAll();
}

public synchronized void waitForAsynchronousInitialization() {
while (asynchronousInitialization) {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

public void handleAsynchronousInitializationResult(boolean success) {
if (!success && !retryInit)
System.exit(1);
ApiInfo.logInfosAboutStartedProxies(ruleManager);
log.info("{} {} up and running!", PRODUCT_NAME, VERSION);
logStartupMessage();
setAsynchronousInitialization(false);
}

@Override
public void handleBeanEvent(BeanDefinition bd, Object bean, Object oldBean) throws IOException {
if (!(bean instanceof Proxy)) {
if (!(bean instanceof Proxy newProxy)) {
throw new IllegalArgumentException("Bean must be a Proxy instance, but got: " + bean.getClass().getName());
}

Proxy newProxy = (Proxy) bean;
if (newProxy.getName() == null)
newProxy.setName(bd.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.*;
import java.util.concurrent.atomic.*;

import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.xml.XMLTextUtil.*;
import static java.nio.charset.StandardCharsets.*;
import static java.util.Calendar.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.predic8.membrane.core.http.*;
import com.predic8.membrane.core.interceptor.*;
import com.predic8.membrane.core.util.*;
import com.predic8.membrane.core.util.text.*;
import org.slf4j.*;

import java.security.*;
Expand All @@ -29,6 +30,7 @@
import static com.predic8.membrane.core.http.Request.METHOD_GET;
import static com.predic8.membrane.core.http.Request.METHOD_POST;
import static com.predic8.membrane.core.interceptor.Outcome.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;

/**
* @description Check GraphQL-over-HTTP requests, enforcing several limits and/or restrictions. This effectively helps to reduce
Expand Down Expand Up @@ -187,7 +189,7 @@ public String getLongDescription() {
"graphql-over-http/blob/a1e6d8ca248c9a19eb59a2eedd988c204909ee3f/spec/GraphQLOverHTTP.md\">" +
"GraphQL-over-HTTP</a> specs).<br/>" +
"GraphQL extensions: " + (allowExtensions ? "Allowed." : "Forbidden.") + "<br/>" +
"Allowed HTTP verbs: " + TextUtil.toEnglishList("and", allowedMethods.toArray(new String[0])) + ".<br/>" +
"Allowed HTTP verbs: " + toEnglishList("and", allowedMethods.toArray(new String[0])) + ".<br/>" +
"Maximum allowed nested query levels: " + maxDepth + "<br/>" +
"Maximum allowed recursion levels (nested repetitions of the same word): " + maxRecursion + ".</div>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static com.predic8.membrane.core.http.Header.*;
import static com.predic8.membrane.core.util.ContentTypeDetector.EffectiveContentType.*;
import static com.predic8.membrane.core.util.ContentTypeDetector.*;
import static com.predic8.membrane.core.util.TextUtil.getCharset;
import static com.predic8.membrane.core.util.text.TextUtil.getCharset;

/**
* A HTTP message (request or response).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.predic8.membrane.core.Router;
import com.predic8.membrane.core.config.AbstractXmlElement;
import com.predic8.membrane.core.config.GenericComplexElement;
import com.predic8.membrane.core.util.TextUtil;
import com.predic8.membrane.core.util.text.TextUtil;

public class Resource extends AbstractXmlElement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.predic8.membrane.core.interceptor.acl.TypeMatcher;

import static com.predic8.membrane.core.util.TextUtil.globToRegExp;
import static com.predic8.membrane.core.util.text.TextUtil.globToRegExp;
import static java.util.regex.Pattern.compile;

public class GlobMatcher implements TypeMatcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.predic8.membrane.core.proxies.*;
import com.predic8.membrane.core.proxies.Proxy;
import com.predic8.membrane.core.transport.http.*;
import com.predic8.membrane.core.util.*;
import org.apache.commons.text.*;

import java.io.*;
Expand All @@ -36,6 +35,7 @@
import static com.predic8.membrane.core.interceptor.balancer.BalancerUtil.*;
import static com.predic8.membrane.core.interceptor.balancer.Node.Status.*;
import static com.predic8.membrane.core.util.URLParamUtil.*;
import static com.predic8.membrane.core.util.xml.XMLTextUtil.isValidXMLSnippet;
import static java.nio.charset.StandardCharsets.*;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang3.time.DurationFormatUtils.*;
Expand Down Expand Up @@ -618,12 +618,12 @@ private void createInterceptorVisualization(Interceptor i, int columnSpan, Strin
String longDescription = i.getLongDescription();
boolean same = longDescription.equals(shortDescription);

if (!TextUtil.isValidXMLSnippet(shortDescription)) {
if (!isValidXMLSnippet(shortDescription)) {
shortDescription = StringEscapeUtils.escapeHtml4(shortDescription).replace("\n", "<br/>");
if (same)
longDescription = shortDescription;
}
if (!same && !TextUtil.isValidXMLSnippet(longDescription)) {
if (!same && !isValidXMLSnippet(longDescription)) {
longDescription = StringEscapeUtils.escapeHtml4(longDescription).replace("\n", "<br/>");
}

Expand All @@ -636,9 +636,9 @@ private void createInterceptorVisualization(Interceptor i, int columnSpan, Strin

String iid = "i" + id;
div().id("i" + id);
createHelpIcon(i, id);
createHelpIcon(i);
if (!shortDescription.isEmpty() && !longDescription.equals(shortDescription)) {
createExpandIcon(i, id);
createExpandIcon(id);
}
end();
createShowIconsScript(did, iid);
Expand Down Expand Up @@ -700,7 +700,7 @@ private void createInterceptorVisualization(Interceptor i, int columnSpan, Strin
end();
}

private void createExpandIcon(Interceptor i, String id) {
private void createExpandIcon(String id) {
div().style("float:right;");
span().id("e" + id).classAttr("ui-icon ui-icon-triangle-1-w").title("expand").end();
end();
Expand All @@ -709,7 +709,7 @@ private void createExpandIcon(Interceptor i, String id) {
end();
}

private void createHelpIcon(Interceptor i, String id) {
private void createHelpIcon(Interceptor i) {
String helpId = i.getHelpId();
if (helpId != null) {
div().style("float:right;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static com.predic8.membrane.core.http.Response.ok;
import static com.predic8.membrane.core.transport.http2.Http2ServerHandler.*;
import static com.predic8.membrane.core.util.ComparatorFactory.*;
import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.xml.XMLTextUtil.formatXML;
import static java.nio.charset.StandardCharsets.*;

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.*;

import static com.predic8.membrane.core.interceptor.Interceptor.Flow.Set.*;
import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;
import static org.apache.commons.text.StringEscapeUtils.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.predic8.membrane.core.util.*;
import org.slf4j.*;

import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.text.StringEscapeUtils.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.predic8.membrane.core.config.security.Blob;
import com.predic8.membrane.core.interceptor.oauth2.authorizationservice.AuthorizationService;
import com.predic8.membrane.core.resolver.ResolverMap;
import com.predic8.membrane.core.util.TextUtil;
import com.predic8.membrane.core.util.text.TextUtil;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.predic8.membrane.core.interceptor.*;
import com.predic8.membrane.core.interceptor.lang.*;
import com.predic8.membrane.core.lang.*;
import com.predic8.membrane.core.util.text.*;
import org.slf4j.*;

import java.io.*;
Expand All @@ -28,6 +29,7 @@
import static com.predic8.membrane.core.interceptor.Interceptor.Flow.ABORT;
import static com.predic8.membrane.core.interceptor.Outcome.*;
import static com.predic8.membrane.core.interceptor.log.LogInterceptor.Level.*;
import static com.predic8.membrane.core.util.text.TerminalColors.*;
import static org.slf4j.LoggerFactory.*;

/**
Expand All @@ -39,6 +41,8 @@
* <li>Operational visibility in production (metadata-only, masked values, message, body).</li>
* </ul>
* </p>
* When supported, the log uses terminal colors to make the output easier to read and find. To overwrite the detection
* of color support, set the system property <code>MEMBRANE_TERM_COLORS</code> to <code>true</code> or <code>false</code>.
* @topic 4. Monitoring, Logging and Statistics
*/
@MCElement(name = "log")
Expand Down Expand Up @@ -133,13 +137,12 @@ private static String dumpBody(Message msg) {
}

private void writeLog(String msg) {

switch (level) {
case TRACE -> getLogger(category).trace(msg);
case DEBUG -> getLogger(category).debug(msg);
case INFO -> getLogger(category).info(msg);
case WARN -> getLogger(category).warn(msg);
case ERROR, FATAL -> getLogger(category).error(msg);
case INFO -> getLogger(category).info(brightBlue( msg));
case WARN -> getLogger(category).warn(brightMagenta( msg));
case ERROR, FATAL -> getLogger(category).error(brightRed(msg));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.predic8.membrane.core.exchange.*;
import com.predic8.membrane.core.http.*;
import com.predic8.membrane.core.interceptor.log.AccessLogInterceptor;
import com.predic8.membrane.core.interceptor.log.AdditionalVariable;
import com.predic8.membrane.core.lang.spel.*;
import org.slf4j.*;
Expand All @@ -29,7 +28,7 @@
import java.util.stream.*;

import static com.predic8.membrane.core.interceptor.Interceptor.Flow.*;
import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;

public class AccessLogInterceptorService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static com.predic8.membrane.core.interceptor.Interceptor.Flow.Set.*;
import static com.predic8.membrane.core.interceptor.Outcome.*;
import static com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Type.*;
import static com.predic8.membrane.core.util.TextUtil.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;
import static java.util.Locale.US;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static com.predic8.membrane.core.interceptor.Outcome.ABORT;
import static com.predic8.membrane.core.interceptor.Outcome.*;
import static com.predic8.membrane.core.resolver.ResolverMap.*;
import static com.predic8.membrane.core.util.TextUtil.linkURL;
import static com.predic8.membrane.core.util.text.TextUtil.linkURL;

/**
* Basically switches over {@link WSDLValidator}, {@link XMLSchemaValidator},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.predic8.membrane.core.interceptor.*;
import com.predic8.membrane.core.resolver.*;
import com.predic8.membrane.core.util.*;
import com.predic8.membrane.core.util.text.*;
import org.apache.commons.lang3.*;
import org.jetbrains.annotations.*;
import org.slf4j.*;
Expand All @@ -36,6 +37,7 @@
import static com.predic8.membrane.core.interceptor.Outcome.*;
import static com.predic8.membrane.core.resolver.ResolverMap.combine;
import static com.predic8.membrane.core.util.HttpUtil.*;
import static com.predic8.membrane.core.util.text.TextUtil.*;
import static java.lang.System.currentTimeMillis;

/**
Expand Down Expand Up @@ -313,7 +315,7 @@ public void setGenerateIndex(boolean generateIndex) {

@Override
public String getShortDescription() {
return "Serves static files from<br/>" + TextUtil.linkURL(docBase) + " .";
return "Serves static files from<br/>" + linkURL(docBase) + " .";
}

}
Loading
Loading