Skip to content

Commit 59fb6bd

Browse files
committed
Implements more REST interfaces in spring boot, error handling, GAM, execute command line, execute reorgs, model property to select Framework
Now JDK 17 is needed to build standar classes Issue: 103655
1 parent a858215 commit 59fb6bd

File tree

8 files changed

+193
-3
lines changed

8 files changed

+193
-3
lines changed

.github/workflows/Build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup Java JDK
3939
uses: actions/setup-java@v1.4.3
4040
with:
41-
java-version: 1.9
41+
java-version: 17
4242
gpg-private-key: ${{ secrets.MAVEN_GPG_BUILDER_PRIVATE_KEY }}
4343
gpg-passphrase: MAVEN_GPG_PASSPHRASE
4444

common/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
<artifactId>xercesImpl</artifactId>
2020
<version>2.12.2</version>
2121
</dependency>
22+
<dependency>
23+
<groupId>org.springframework</groupId>
24+
<artifactId>spring-core</artifactId>
25+
<version>6.0.11</version>
26+
<scope>provided</scope>
27+
</dependency>
2228
<dependency>
2329
<groupId>commons-codec</groupId>
2430
<artifactId>commons-codec</artifactId>

common/src/main/java/com/genexus/ApplicationContext.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class ApplicationContext
1414
private boolean isGXUtility = false;
1515
private boolean isMsgsToUI = true ;
1616
private boolean isServletEngine = false;
17-
private boolean isEJBEngine = false;
17+
private boolean isSpringBootApp = false;
18+
private boolean isEJBEngine = false;
1819
private boolean isDeveloperMenu = false;
1920
private static Object syncObject = new Object();
2021

@@ -112,6 +113,16 @@ public boolean isServletEngine()
112113
return isServletEngine;
113114
}
114115

116+
public void setSpringBootApp(boolean isSpringBootApp)
117+
{
118+
this.isSpringBootApp = isSpringBootApp;
119+
}
120+
121+
public boolean isSpringBootApp()
122+
{
123+
return isSpringBootApp;
124+
}
125+
115126
public void setEJBEngine(boolean isEJBEngine)
116127
{
117128
this.isEJBEngine = isEJBEngine;

common/src/main/java/com/genexus/xml/XMLReader.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.*;
66
import java.util.*;
77

8+
import com.genexus.ApplicationContext;
89
import org.apache.xerces.xni.QName;
910
import org.apache.xerces.xni.XMLAttributes;
1011
import org.apache.xerces.xni.XMLDocumentHandler;
@@ -30,6 +31,7 @@
3031
import com.genexus.ResourceReader;
3132
import com.genexus.internet.IHttpRequest;
3233
import com.genexus.CommonUtil;
34+
import org.springframework.core.io.ClassPathResource;
3335

3436
public class XMLReader implements XMLDocumentHandler, XMLErrorHandler, XMLDTDHandler
3537
{
@@ -770,7 +772,23 @@ public void open(String url)
770772
reset();
771773
try
772774
{
773-
inputSource = new XMLInputSource(null, url, null, new FileInputStream(new File(url)), null);
775+
File xmlFile = new File(url);
776+
if (ApplicationContext.getInstance().isSpringBootApp())
777+
{
778+
ClassPathResource resource = new ClassPathResource(url);
779+
if (resource.exists())
780+
xmlFile = resource.getFile();
781+
else
782+
{
783+
if (url.startsWith(ApplicationContext.getInstance().getServletEngineDefaultPath()))
784+
{
785+
resource = new ClassPathResource(url.replace(ApplicationContext.getInstance().getServletEngineDefaultPath(), ""));
786+
if (resource.exists())
787+
xmlFile = resource.getFile();
788+
}
789+
}
790+
}
791+
inputSource = new XMLInputSource(null, url, null, new FileInputStream(xmlFile), null);
774792
if (documentEncoding.length() > 0)
775793
inputSource.setEncoding(CommonUtil.normalizeEncodingName(documentEncoding));
776794
parserConfiguration.setInputSource(inputSource);

gxspringboot/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.genexus</groupId>
9+
<artifactId>parent</artifactId>
10+
<version>${revision}${changelist}</version>
11+
</parent>
12+
13+
<artifactId>gxspringboot</artifactId>
14+
<name>GeneXus Spring Boot</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>${project.groupId}</groupId>
19+
<artifactId>gxclassR</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>jakarta.servlet</groupId>
24+
<artifactId>jakarta.servlet-api</artifactId>
25+
<version>5.0.0</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
<version>3.1.2</version>
32+
<scope>provided</scope>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<finalName>gxspringboot</finalName>
38+
</build>
39+
</project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.genexus.springboot;
2+
import java.lang.reflect.Constructor;
3+
import jakarta.servlet.Servlet;
4+
import org.springframework.boot.web.servlet.ServletRegistrationBean;
5+
import org.springframework.context.annotation.Bean;
6+
7+
public class GAMServletsDefinition {
8+
@Bean
9+
public ServletRegistrationBean gXOAuthAccessToken() {
10+
return registerServletBean("com.genexus.webpanels.GXOAuthAccessToken", "/oauth/access_token");
11+
}
12+
13+
@Bean
14+
public ServletRegistrationBean gXOAuthLogout() {
15+
return registerServletBean("com.genexus.webpanels.GXOAuthLogout", "/oauth/logout");
16+
}
17+
18+
@Bean
19+
public ServletRegistrationBean gXOAuthUserInfo() {
20+
return registerServletBean("com.genexus.webpanels.GXOAuthUserInfo", "/oauth/userinfo");
21+
}
22+
23+
@Bean
24+
public ServletRegistrationBean gamOAuthSignIn() {
25+
return registerServletBean("genexus.security.api.agamextauthinput", "/oauth/gam/signin");
26+
}
27+
28+
@Bean
29+
public ServletRegistrationBean gamOAuthCallback() {
30+
return registerServletBean("genexus.security.api.agamextauthinput", "/oauth/gam/callback");
31+
}
32+
33+
@Bean
34+
public ServletRegistrationBean gamOAuthAccessToken() {
35+
return registerServletBean("genexus.security.api.agamoauth20getaccesstoken", "/oauth/gam/access_token");
36+
}
37+
38+
@Bean
39+
public ServletRegistrationBean gamAccessTokenV2() {
40+
return registerServletBean("genexus.security.api.agamoauth20getaccesstoken_v20", "/oauth/gam/v2.0/access_token");
41+
}
42+
43+
@Bean
44+
public ServletRegistrationBean gamOAuthUserInfo() {
45+
return registerServletBean("genexus.security.api.agamoauth20getuserinfo", "/oauth/gam/userinfo");
46+
}
47+
48+
@Bean
49+
public ServletRegistrationBean oAuthUserInfoV2() {
50+
return registerServletBean("genexus.security.api.agamoauth20getuserinfo_v20", "/oauth/gam/v2.0/userinfo");
51+
}
52+
53+
@Bean
54+
public ServletRegistrationBean oAuthSSORestV2() {
55+
return registerServletBean("genexus.security.api.agamssorestrequesttokenanduserinfo_v20", "/oauth/gam/v2.0/requesttokenanduserinfo");
56+
}
57+
58+
@Bean
59+
public ServletRegistrationBean gamOAuthSignOut() {
60+
return registerServletBean("genexus.security.api.agamextauthinput", "/oauth/gam/signout");
61+
}
62+
63+
@Bean
64+
public ServletRegistrationBean gamOAuthRequestTokenService() {
65+
return registerServletBean("genexus.security.api.agamstsauthappgetaccesstoken", "/oauth/RequestTokenService");
66+
}
67+
68+
@Bean
69+
public ServletRegistrationBean gamOAuthQueryAccessToken() {
70+
return registerServletBean("genexus.security.api.agamstsauthappvalidaccesstoken", "/oauth/QueryAccessToken");
71+
}
72+
73+
/*@Bean
74+
public ServletRegistrationBean gamSaml20SignOut() {
75+
return registerServletBean("artech.security.saml.servlet.LOGOUT", "/saml/gam/signout");
76+
}
77+
78+
@Bean
79+
public ServletRegistrationBean gamSaml20SignIn() {
80+
return registerServletBean("artech.security.saml.servlet.SSO", "/saml/gam/signin");
81+
}*/
82+
83+
private ServletRegistrationBean registerServletBean(String className, String path) {
84+
try {
85+
Constructor<?> constructor = Class.forName(className).getConstructor();
86+
ServletRegistrationBean bean = new ServletRegistrationBean((Servlet) constructor.newInstance(), path);
87+
return bean;
88+
}
89+
catch(Exception e) {
90+
return null;
91+
}
92+
}
93+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.genexus.springboot;
2+
3+
import com.genexus.GxRestService;
4+
import com.genexus.WrapperUtils;
5+
import org.apache.logging.log4j.Logger;
6+
import org.springframework.http.*;
7+
import org.springframework.web.bind.annotation.*;
8+
import org.springframework.http.converter.HttpMessageNotReadableException;
9+
10+
abstract public class GxSpringBootRestService extends GxRestService {
11+
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(GxSpringBootRestService.class);
12+
13+
@ExceptionHandler(HttpMessageNotReadableException.class)
14+
protected ResponseEntity<Object> handleException(HttpMessageNotReadableException ex) {
15+
log.error("Error executing REST service", ex);
16+
17+
SetError("400", "Bad Request");
18+
ResponseEntity.BodyBuilder builder = ResponseEntity.status(HttpStatus.BAD_REQUEST);
19+
builder.contentType(MediaType.APPLICATION_JSON);
20+
return builder.body(errorJson.toString()) ;
21+
}
22+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<modules>
8383
<module>common</module>
8484
<module>gxweb</module>
85+
<module>gxspringboot</module>
8586
<module>wrapperjavax</module>
8687
<module>wrapperjakarta</module>
8788
<module>wrappercommon</module>

0 commit comments

Comments
 (0)