Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/schemas for xml api files #20

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 18 additions & 8 deletions src/main/java/pl/psnc/dl/ege/webapp/servlet/ConversionServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
version = "1.0",
description = "EGE Webservice API to convert and validate TEI related data.",
license = @License(name = " GPL-3.0 license", url = "https://www.gnu.org/licenses/gpl-3.0.en.html"),
contact = @Contact(url = "https://teigarage.tei-c.de/", name = "Anne Ferger", email = "anne.ferger@upb.de")
contact = @Contact(url = "https://github.com/TEIC/TEIGarage", name = "Anne Ferger", email = "anne.ferger@upb.de")
), tags = {
@Tag(name = "ege-webservice", description = "Conversion, Validation and Customization")
},
Expand Down Expand Up @@ -151,7 +151,7 @@ public ConversionServlet() {
@ApiResponse(
description = "List of possible conversions is returned",
responseCode = "200",
content = @Content(mediaType = "text/xml", schema = @Schema(implementation = XML.class))),
content = @Content(mediaType = "text/xml", schema = @Schema(implementation=ConversionsPath.class))),
@ApiResponse(
description = "Wrong method error message if the method is called wrong",
responseCode = "405")
Expand Down Expand Up @@ -207,8 +207,13 @@ protected void printConversionsPaths(HttpServletResponse response,
StringBuffer resp = new StringBuffer();
StringBuffer sbpath = new StringBuffer();
StringBuffer pathopt = new StringBuffer();
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ":" + rr.getRequest().getServerPort() +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
resp.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
resp.append("<conversions-paths xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
resp.append("<conversions-paths xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" +
baseprefix + "schemas/conversions-paths.xsd\">");
int counter = 0;
String reqTransf;
for (ConversionsPath cp : paths) {
Expand Down Expand Up @@ -282,11 +287,16 @@ protected void printConversionPossibilities(HttpServletResponse response,
PrintWriter out = response.getWriter();
try {
response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<input-data-types xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ":" + rr.getRequest().getServerPort() +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
String prefix = rr.getRequest().getRequestURL().toString()
+ (rr.getRequest().getRequestURL().toString().endsWith(SLASH) ? ""
: "/");
+ (rr.getRequest().getRequestURL().toString().endsWith(SLASH) ? ""
: "/");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<input-data-types xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" +
baseprefix + "schemas/input-data-types.xsd\">");
for (DataType dt : inputDataTypes) {
out.println("<input-data-type id=\"" + dt.toString()
+ "\" xlink:href=\"" + prefix + rr.encodeDataType(dt)
Expand Down Expand Up @@ -417,7 +427,7 @@ protected void performConversion(HttpServletResponse response,
ValidationResult vRes = ege.performValidation(ins, cpath.getInputDataType());
if (vRes.getStatus().equals(ValidationResult.Status.FATAL)) {
ValidationServlet valServ = new ValidationServlet();
valServ.printValidationResult(response, vRes);
valServ.printValidationResult(response, vRes, rr);
try {
ins.close();
} finally {
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/pl/psnc/dl/ege/webapp/servlet/ValidationServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ValidationServlet()
@ApiResponse(
description = "List of possible validations is returned",
responseCode = "200",
content = @Content(mediaType = "text/xml", schema = @Schema(implementation = XML.class))),
content = @Content(mediaType = "text/xml", schema = @Schema(implementation = DataType.class))),
@ApiResponse(
description = "Wrong method error message if the method is called wrong",
responseCode = "405")
Expand Down Expand Up @@ -120,13 +120,17 @@ private void printAvailableValidations(HttpServletResponse response,
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
return;
}
response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out
.println("<validations xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
String prefix = rr.getRequest().getRequestURL().toString()
+ (rr.getRequest().getRequestURL().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
RequestResolver.SLASH) ? "" : "/");
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ":" + rr.getRequest().getServerPort() +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<validations xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" + baseprefix
+ "schemas/validations.xsd\">");
for (DataType dt : dts) {
out.println("<input-data-type id=\"" + dt.toString()
+ "\" xlink:href=\"" + prefix + rr.encodeDataType(dt)
Expand All @@ -153,13 +157,13 @@ private void printAvailableValidations(HttpServletResponse response,
description = "Input document type",
required = true,
name = "input-document-type",
schema = @Schema(type= "string", format="text/plain"))
schema = @Schema(implementation = DataType.class))
},
responses = {
@ApiResponse(
description = "Validation Result",
responseCode = "200",
content = @Content(mediaType = "text/xml", schema = @Schema(implementation = XML.class))),
content = @Content(mediaType = "text/xml", schema = @Schema(implementation = ValidationResult.class))),
@ApiResponse(
description = "Wrong method error message if the method is called wrong",
responseCode = "405")
Expand Down Expand Up @@ -211,7 +215,7 @@ private void performValidation(DataType dt, RequestResolver rr,
is = item.openStream();
//perform validation and print result to response.
ValidationResult result = ege.performValidation(is, dt);
printValidationResult(response,result);
printValidationResult(response,result, rr);
is.close();
}
}
Expand All @@ -236,11 +240,19 @@ private void performValidation(DataType dt, RequestResolver rr,
}
}

public void printValidationResult(HttpServletResponse response, ValidationResult result) throws IOException{
public void printValidationResult(HttpServletResponse response, ValidationResult result, RequestResolver rr) throws IOException{
PrintWriter out = response.getWriter();
String prefix = rr.getRequest().getRequestURL().toString()
+ (rr.getRequest().getRequestURL().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ":" + rr.getRequest().getServerPort() +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
RequestResolver.SLASH) ? "" : "/");
response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<validation-result>");
out.println("<validation-result xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" + baseprefix
+ "schemas/validation-result.xsd\">");
out.println("<status>" + result.getStatus()
+ "</status>");
out.println("<messages>");
Expand Down
Loading