Skip to content

Commit

Permalink
Migrated to Spring Boot 3.2.4, jakarta servlet, jsp, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Apr 7, 2024
1 parent c9e8d46 commit 878ad43
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 87 deletions.
Expand Up @@ -37,8 +37,7 @@ public void testClientHtml() throws IOException {
() -> Assertions.assertTrue(res.contains("testBiopaxElementIdRule.owl")),
() -> Assertions.assertTrue(res.contains("testSyntaxErrors.owl"))
);
// System.out.println(baos);
}
}

@Test
public void testClientXml() throws IOException, JAXBException {
Expand Down
26 changes: 19 additions & 7 deletions biopax-validator-web/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<version>3.2.4</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -282,14 +282,14 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
Expand Down Expand Up @@ -340,6 +340,18 @@
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Expand Up @@ -2,8 +2,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
Expand All @@ -21,6 +19,10 @@ public static void main(String[] args) {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
}

@Override
Expand All @@ -32,11 +34,4 @@ public void configureViewResolvers(ViewResolverRegistry registry) {
registry.viewResolver(resolver);
}

@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(-1);
return multipartResolver;
}

}
@@ -1,23 +1,23 @@
package org.biopax.validator.web.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.biopax.validator.web.dto.Clue;
import org.biopax.validator.web.service.Suggester;
import org.biopax.validator.web.dto.Xref;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.*;

@RestController
public class SuggesterController {

@Autowired
private Suggester service;

@GetMapping(value = "/xref/{db}/{id}/", produces = APPLICATION_JSON_VALUE)
@GetMapping(value = "/xref/{db}/{id}/", produces = TEXT_PLAIN_VALUE)
public String xrefDbId(@PathVariable String db, @PathVariable String id,
HttpServletResponse response) throws IOException {
String uri = null;
Expand All @@ -26,7 +26,6 @@ public String xrefDbId(@PathVariable String db, @PathVariable String id,
} catch (IllegalArgumentException e) {
response.sendError(400, e.toString());
}

return uri;
}

Expand Down
Expand Up @@ -5,9 +5,8 @@
import java.net.MalformedURLException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.biopax.paxtools.normalizer.Normalizer;
Expand All @@ -27,7 +26,7 @@
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;
import static org.springframework.http.MediaType.*;

@Controller
public class ValidatorController {
Expand All @@ -42,24 +41,24 @@ public ValidatorController(ValidatorAdapter service) {
this.service = service;
}

@RequestMapping(value = {"schema","schema.html"}, method = RequestMethod.GET, produces = APPLICATION_XML_VALUE)
@ResponseBody public String getSchema() {
@GetMapping(value = {"schema","schema.html"}, produces = APPLICATION_XML_VALUE)
@ResponseBody public String getSchema() {
return service.getSchema();
}

//Views (pages)

@RequestMapping({"/", "home", "home.html"})
@GetMapping({"/", "home", "home.html"})
public String home() {
return "home";
}

@RequestMapping({"ws","ws.html"})
@GetMapping({"ws","ws.html"})
public String ws() {
return "ws";
}

@RequestMapping(value={"check","check.html"}, method=RequestMethod.GET)
@GetMapping(value={"check","check.html"})
public void check(Model model) {
model.addAttribute("normalizer", new Normalizer());
//user can edit some of normalizer's options in the 'check' view
Expand Down Expand Up @@ -89,18 +88,18 @@ public void check(Model model) {
* @return results view name (or null if XML or normalized RDF/XML were requested)
* @throws IOException when data cannot be read from the files or URL, etc.
*/
@RequestMapping(value={"check","check.html"}, method=RequestMethod.POST)
@PostMapping(value={"check","check.html"},
produces = {APPLICATION_XML_VALUE, TEXT_HTML_VALUE, "application/vnd.biopax.rdf+xml"})
public String check(HttpServletRequest request, HttpServletResponse response,
Model mvcModel, Writer writer,
@RequestParam(required=false) String url,
@RequestParam(required=false) String retDesired,
@RequestParam(required=false) Boolean autofix,
@RequestParam(required=false) Behavior filter,
@RequestParam(required=false) Integer maxErrors,
@RequestParam(required=false) String profile,
//normalizer!=null when called from the JSP;
//but it's usually null when from the validator-client or a web script
@ModelAttribute("normalizer") Normalizer normalizer) throws IOException
@RequestParam(required=false) String url,
@RequestParam(required=false) String retDesired,
@RequestParam(required=false) Boolean autofix,
@RequestParam(required=false) Behavior filter,
@RequestParam(required=false) Integer maxErrors,
@RequestParam(required=false) String profile,
//normalizer!=null when called from the JSP (browser); null when called from validator-client or script
@ModelAttribute("normalizer") Normalizer normalizer) throws IOException
{
Resource resource; //to validate
final int lim = (maxErrors != null)? maxErrors.intValue() : 0; //0->no error limit
Expand All @@ -110,7 +109,7 @@ public String check(HttpServletRequest request, HttpServletResponse response,
ValidatorResponse validatorResponse = new ValidatorResponse();

if(url != null && url.length()>0) {
log.info("url : " + url);
log.info("validate from url : " + url);

try {
resource = new UrlResource(url);
Expand Down
Expand Up @@ -36,8 +36,9 @@ public Validation validate(Resource data,
Behavior errorLevel, String profile,
Normalizer normalizer) throws IOException
{
String dataDescr = data.getDescription();
Validation validationResult = new Validation(new BiopaxIdentifier(),
data.getDescription(), isFix, errorLevel, errMax, profile);
dataDescr, isFix, errorLevel, errMax, profile);
//run the biopax-validator (this updates the validationResult object)
biopaxValidator.importModel(validationResult, data.getInputStream());
biopaxValidator.validate(validationResult);
Expand Down
15 changes: 11 additions & 4 deletions biopax-validator-web/src/main/resources/application.properties
Expand Up @@ -3,7 +3,8 @@ spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
#spring.mvc.view.view-names:*
server.error.whitelabel.enabled=false
#server.servlet.context-path = /
#server.servlet.context-path = /validate

spring.main.banner-mode=off
application.message: Hello BioPAX users!

Expand All @@ -14,11 +15,17 @@ management.endpoint.health.enabled=true
management.endpoints.web.exposure.include=health
#management.endpoints.web.exposure.exclude=

#due to migration from spring-boot 2.0 to 2.1
#due to migration from spring-boot 2.0 to 2.1, then 3.x
spring.main.allow-bean-definition-overriding=true

#for rest docs
spring.jackson.serialization.indent-output=true

servlet.multipart.enabled: false
servlet.multipart.max-file-size: 100MB
#servlet.multipart.enabled=false
server.tomcat.max-swallow-size=-1
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=10MB

#server.servlet.encoding.charset=UTF-8
#server.servlet.encoding.enabled=false
#server.servlet.encoding.force-response=true
11 changes: 5 additions & 6 deletions biopax-validator-web/src/main/webapp/jsp/ws.jsp
Expand Up @@ -54,15 +54,14 @@ to save locally and view off-line</li>
</div>

<div class="row">
As an example, there is a basic BioPAX validator client module
(it connects to the http://www.biopax.org/validator/check), and the
As an example, there is a BioPAX validator-client library
(it connects to http://www.biopax.org/validator/check); the
<a target="_blank" href="https://github.com/BioPAX/validator/tree/master/biopax-validator-client">
sources are here</a> (see test classes there as well).
source code is here</a> (see test classes there as well).
</div>

<br/>
<div class="row">
<h3>See also</h3>
<a target="_blank" href="swagger-ui.html">BioPAX Validator API</a> documentation with examples (OpenAPI/Swagger).
See also: <a target="_blank" href="swagger-ui.html">OpenAPI/Swagger page</a> (autogenerated, needs work...)
</div>

<jsp:include page="footer.jsp"/>
Expand Down
Expand Up @@ -43,12 +43,12 @@ public void before() {
// valid synonym and valid id
String anXrefId = "6.1.1.5";
given(service.xrefDbIdToUri("ec", anXrefId))
.willReturn("http://identifiers.org/ec-code/" + anXrefId);
.willReturn("http://bioregistry.io/eccode:" + anXrefId);
// test typo (fixable) name
given(service.xrefDbIdToUri("ec_code", anXrefId))
.willReturn("http://identifiers.org/ec-code/" + anXrefId);
.willReturn("http://bioregistry.io/eccode:" + anXrefId);
given(service.xrefDbIdToUri("Enzyme Nomenclature", anXrefId))
.willReturn("http://identifiers.org/ec-code/" + anXrefId);
.willReturn("http://bioregistry.io/eccode:" + anXrefId);
// bad not-fixable name
given(service.xrefDbIdToUri("foo", anXrefId))
.willThrow(new IllegalArgumentException("Datatype not found"));
Expand All @@ -59,15 +59,14 @@ public void before() {

@Test
public void shouldReturnUri() throws Exception {
mvc.perform(get("/xref/ec/6.1.1.5/").accept(MediaType.APPLICATION_JSON))
mvc.perform(get("/xref/ec/6.1.1.5/").accept(MediaType.TEXT_PLAIN))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(content().string(equalTo("http://identifiers.org/ec-code/6.1.1.5")));
.andExpect(content().string(equalTo("http://bioregistry.io/eccode:6.1.1.5")));

mvc.perform(get("/xref/ec_code/6.1.1.5/").accept(MediaType.APPLICATION_JSON))
mvc.perform(get("/xref/ec_code/6.1.1.5/").accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("http://identifiers.org/ec-code/6.1.1.5")));
.andExpect(content().string(equalTo("http://bioregistry.io/eccode:6.1.1.5")));
}

@Test
Expand Down Expand Up @@ -106,14 +105,14 @@ public void shouldReturnCheckedXrefs() throws Exception {
y.setId("foo"); //invalid
Xref xx = new Xref();
xx.setDb("ec"); //ok
xx.setNamespace("ec-code");
xx.setNamespace("eccode");
xx.setDbOk(true);
xx.setId("1.1.1.1"); //ok
xx.setIdOk(true);
Xref yy = new Xref();
yy.setDb("ec"); // ok
yy.setDbOk(true);
yy.setNamespace("ec-code");
yy.setNamespace("eccode");
yy.setId("foo"); //invalid
Clue xyClue = new Clue("some info");
xyClue.addValue(xx);
Expand Down
Expand Up @@ -67,11 +67,10 @@ void initInternalMaps() {
}

private void addDbSynonymsTo(Map<Class<? extends BioPAXElement>,Set<String>> map) {
for (Map.Entry<Class<? extends BioPAXElement>,Set<String>> entry : map.entrySet()) {
Set<String> val = entry.getValue();
for (String db : new HashSet<>(val))
for (String s : helper.getSynonymsForDbName(db))
val.add(s);
for (Set<String> val : map.values()) {
for (String db : new HashSet<>(val)) {
val.addAll(helper.getSynonymsForDbName(db));
}
}
}

Expand Down
20 changes: 1 addition & 19 deletions pom.xml
Expand Up @@ -177,7 +177,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<github.global.server>github</github.global.server>
<spring-framework.version>5.3.31</spring-framework.version>
<spring-framework.version>6.1.5</spring-framework.version>
<slf4j.version>2.0.11</slf4j.version>
<agent>${settings.localRepository}/org/springframework/spring-instrument/${spring-framework.version}/spring-instrument-${spring-framework.version}.jar</agent>
<paxtools.version>6.0.0-SNAPSHOT</paxtools.version>
Expand Down Expand Up @@ -484,24 +484,6 @@
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
Expand Down

0 comments on commit 878ad43

Please sign in to comment.