Skip to content
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
<dependency>
<groupId>io.github.unknow0.model</groupId>
<artifactId>unknow-model-bom</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,23 @@ public static <T> ParamConverter<T> converter(Class<T> clazz, Type type, Annotat
}

@SuppressWarnings("unchecked")
public static void sendError(JaxrsReq r, Throwable t, HttpServletResponse res) throws IOException {
Class<?> c = t.getClass();
do {
ExceptionMapper<Throwable> m = exceptions.get(c);
if (m != null) {
try (Response response = m.toResponse(t)) {
JaxrsEntityWriter.RESPONSE.write(r, response, res);
public static void sendError(JaxrsReq r, Throwable t, HttpServletResponse res) {
try {
Class<?> c = t.getClass();
do {
ExceptionMapper<Throwable> m = exceptions.get(c);
if (m != null) {
try (Response response = m.toResponse(t)) {
JaxrsEntityWriter.RESPONSE.write(r, response, res);
}
return;
}
return;
}
} while ((c = c.getSuperclass()) != Object.class);
logger.error("No exception mapping found", t);
res.sendError(500);
} while ((c = c.getSuperclass()) != Object.class);
logger.error("No exception mapping found", t);
res.sendError(500);
} catch (IOException | IllegalStateException e) {
logger.warn("Failed to send error", e);
}
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void write(JaxrsReq r, Response e, HttpServletResponse res) throws WebApp
MediaType mediaType = e.getMediaType();
if (mediaType == null)
mediaType = r.getAccept();
if (mediaType == null)
mediaType = MediaType.TEXT_PLAIN_TYPE;
res.setContentType(mediaType.toString());

Class<?> clazz = o.getClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ public MediaType getContentType() {
}

public MediaType getAccepted(MTPredicate allowed, MediaType def) {
accept = def;
String a = r.getHeader("accept");
if (a == null)
return accept;
return accept = def;
int i;
int l = 0;
double lq = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,66 @@
public interface MTPredicate {
MediaType getMatching(MediaType t);

public static MTPredicate ANY = t -> t;
boolean isCompatible(MediaType t);

public static MTPredicate ANY = new MTPredicate() {

@Override
public MediaType getMatching(MediaType t) {
return t;
}

@Override
public boolean isCompatible(MediaType t) {
return true;
}
};
public static MTPredicate NONE = new MTPredicate() {

@Override
public MediaType getMatching(MediaType t) {
return null;
}

@Override
public boolean isCompatible(MediaType t) {
return false;
}
};

public static class Single implements MTPredicate {
private final MediaType mt;

public Single(MediaType mt) {
this.mt = mt;
}

@Override
public MediaType getMatching(MediaType t) {
String charset = t.getParameters().get(MediaType.CHARSET_PARAMETER);
if (t.isWildcardType()) {
if (t.isWildcardSubtype() || t.getSubtype().equals(mt.getSubtype())) {
if (charset == null)
return mt;
return new MediaType(mt.getType(), mt.getSubtype(), charset);
}
} else if (t.getType().equals(mt.getType())) {
if (t.isWildcardSubtype()) {
if (charset == null)
return mt;
return new MediaType(mt.getType(), mt.getSubtype(), charset);
}
if (t.getSubtype().equals(mt.getSubtype()))
return t;
}
return null;
}

@Override
public boolean isCompatible(MediaType t) {
return t != null && t.isCompatible(mt);
}
}

public static class OneOf implements MTPredicate {
private final MediaType[] mts;
Expand Down Expand Up @@ -43,5 +102,16 @@ public MediaType getMatching(MediaType t) {
}
return null;
}

@Override
public boolean isCompatible(MediaType t) {
if (t == null)
return false;
for (int i = 0; i < mts.length; i++) {
if (t.isCompatible(mts[i]))
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void matrix(String expected, String path, String def) {
public static final Stream<Arguments> accept() {
//@formatter:off
return Stream.of(
Arguments.of(MediaType.WILDCARD_TYPE, "*/*", (MTPredicate) m -> null),
Arguments.of(null, "*/*", MTPredicate.NONE),
Arguments.of(MediaType.WILDCARD_TYPE, "*/*", MTPredicate.ANY),
Arguments.of(MediaType.TEXT_XML_TYPE, "text/plain,text/xml", new MTPredicate.OneOf(MediaType.TEXT_XML_TYPE)),
Arguments.of(MediaType.WILDCARD_TYPE, null, new MTPredicate.OneOf(MediaType.TEXT_XML_TYPE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import com.github.javaparser.ast.CompilationUnit;
Expand Down Expand Up @@ -75,9 +74,6 @@ public class JaxbGeneratorMojo extends AbstractGeneratorMojo {
private final Map<XmlType, String> handlers = new HashMap<>();
private final XmlLoader xmlLoader = new XmlLoader();

@Parameter(name = "graalvm", defaultValue = "true")
protected boolean graalvm;

public JaxbGeneratorMojo() {
handlers.put(XmlLoader.BOOLEAN, BooleanHandler.class.getName());
handlers.put(XmlLoader.BYTE, ByteHandler.class.getName());
Expand Down Expand Up @@ -179,7 +175,7 @@ private void writeXmlLoader() throws MojoExecutionException {
}

private void generateGraalVmResources() throws MojoFailureException {
if (!graalvm)
if (!codegen.graalvm)
return;

try {
Expand Down
Loading
Loading