-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a status endpoint to the demo web app; #215
- Loading branch information
Showing
5 changed files
with
135 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...rver-webapp/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.helger.phase4.server.servlet; | ||
|
||
import com.helger.commons.http.EHttpMethod; | ||
import com.helger.xservlet.AbstractXServlet; | ||
|
||
import jakarta.servlet.annotation.WebServlet; | ||
|
||
/** | ||
* The servlet to show the application status. | ||
* | ||
* @author Philip Helger | ||
*/ | ||
@WebServlet (name = "peppol-status", urlPatterns = "/peppol-status") | ||
public class Phase4PeppolStatusServlet extends AbstractXServlet | ||
{ | ||
public static final String SERVLET_DEFAULT_NAME = "peppol-status"; | ||
public static final String SERVLET_DEFAULT_PATH = '/' + SERVLET_DEFAULT_NAME; | ||
|
||
public Phase4PeppolStatusServlet () | ||
{ | ||
handlerRegistry ().registerHandler (EHttpMethod.GET, new Phase4PeppolStatusXServletHandler ()); | ||
handlerRegistry ().unregisterHandler (EHttpMethod.OPTIONS); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...app/src/main/java/com/helger/phase4/server/servlet/Phase4PeppolStatusXServletHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.helger.phase4.server.servlet; | ||
|
||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.KeyStore; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.helger.commons.annotation.ReturnsMutableCopy; | ||
import com.helger.commons.datetime.PDTFactory; | ||
import com.helger.commons.datetime.PDTWebDateHelper; | ||
import com.helger.commons.debug.GlobalDebug; | ||
import com.helger.commons.mime.CMimeType; | ||
import com.helger.commons.mime.MimeType; | ||
import com.helger.commons.system.SystemProperties; | ||
import com.helger.json.IJsonObject; | ||
import com.helger.json.JsonObject; | ||
import com.helger.phase4.CAS4Version; | ||
import com.helger.phase4.crypto.AS4CryptoFactoryProperties; | ||
import com.helger.phase4.crypto.IAS4CryptoFactory; | ||
import com.helger.servlet.response.UnifiedResponse; | ||
import com.helger.web.scope.IRequestWebScopeWithoutResponse; | ||
import com.helger.xservlet.handler.simple.IXServletSimpleHandler; | ||
|
||
/** | ||
* Create the demo application status information | ||
* | ||
* @author Philip Helger | ||
*/ | ||
public class Phase4PeppolStatusXServletHandler implements IXServletSimpleHandler | ||
{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger (Phase4PeppolStatusXServletHandler.class); | ||
private static final Charset CHARSET = StandardCharsets.UTF_8; | ||
|
||
@Nonnull | ||
@ReturnsMutableCopy | ||
public static IJsonObject getDefaultStatusData () | ||
{ | ||
final IJsonObject aStatusData = new JsonObject (); | ||
aStatusData.add ("status.datetime", PDTWebDateHelper.getAsStringXSD (PDTFactory.getCurrentOffsetDateTimeUTC ())); | ||
aStatusData.add ("global.debug", GlobalDebug.isDebugMode ()); | ||
aStatusData.add ("global.production", GlobalDebug.isProductionMode ()); | ||
aStatusData.add ("java.version", SystemProperties.getJavaVersion ()); | ||
aStatusData.add ("phase4.version", CAS4Version.BUILD_VERSION); | ||
aStatusData.add ("phase4.build-timestamp", CAS4Version.BUILD_TIMESTAMP); | ||
|
||
final IAS4CryptoFactory aCF = AS4CryptoFactoryProperties.getDefaultInstance (); | ||
final KeyStore aKS = aCF.getKeyStore (); | ||
aStatusData.add ("phase4.keystore.loaded", aKS != null); | ||
if (aKS != null) | ||
{ | ||
aStatusData.add ("phase4.keystore.key.alias", aCF.getKeyAlias ()); | ||
final KeyStore.PrivateKeyEntry aPKE = aCF.getPrivateKeyEntry (); | ||
aStatusData.add ("phase4.keystore.key.loaded", aPKE != null); | ||
if (aPKE != null) | ||
{ | ||
final X509Certificate aCert = (X509Certificate) aPKE.getCertificate (); | ||
aStatusData.add ("phase4.keystore.key.issuer", aCert.getIssuerX500Principal ().getName ()); | ||
aStatusData.add ("phase4.keystore.key.subject", aCert.getSubjectX500Principal ().getName ()); | ||
} | ||
} | ||
|
||
return aStatusData; | ||
} | ||
|
||
public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, | ||
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception | ||
{ | ||
if (LOGGER.isDebugEnabled ()) | ||
LOGGER.debug ("Status information requested"); | ||
|
||
// Build data to provide | ||
final IJsonObject aStatusData = getDefaultStatusData (); | ||
|
||
// Put JSON on response | ||
aUnifiedResponse.disableCaching (); | ||
aUnifiedResponse.setMimeType (new MimeType (CMimeType.APPLICATION_JSON).addParameter (CMimeType.PARAMETER_NAME_CHARSET, | ||
CHARSET.name ())); | ||
aUnifiedResponse.setContentAndCharset (aStatusData.getAsJsonString (), CHARSET); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters