diff --git a/unknow-server-maven/src/main/java/unknow/server/maven/jaxrs/JaxRsServletBuilder.java b/unknow-server-maven/src/main/java/unknow/server/maven/jaxrs/JaxRsServletBuilder.java index 382c249d..d3aa485b 100644 --- a/unknow-server-maven/src/main/java/unknow/server/maven/jaxrs/JaxRsServletBuilder.java +++ b/unknow-server-maven/src/main/java/unknow/server/maven/jaxrs/JaxRsServletBuilder.java @@ -84,6 +84,7 @@ /** * Build a jaxrs servlet + * * @author unknow */ public class JaxRsServletBuilder { @@ -149,6 +150,7 @@ public JaxRsServletBuilder(CompilationUnit cu, Map existingClass /** * convert a path mapping to a java class name + * * @param path the path * @return the class name */ @@ -285,6 +287,7 @@ private void buildOptions(String name, Set methods) { /** * create all required converter and add them to servlet fields + * * @param p the param * @param n converter field name * @param i parameter index @@ -324,9 +327,10 @@ private void processConverter(JaxrsParam p, String n, int i, BlockStmt b) { /** * build the call for one method on one path + * * @param name java method name * @param list list of mapping on this path and method - * @throws MojoFailureException in case of error + * @throws MojoFailureException in case of error */ private void buildMethod(String name, List list) throws MojoFailureException { @@ -387,14 +391,18 @@ private static Map, Collection> buildConsumeMap(List< /** * build the block to route with the accept header to the right service method - * @param b where to add statement + * + * @param b where to add statement * @param mappings the mapping to manage * @return b * @throws MojoFailureException in case of error */ private BlockStmt buildProduces(BlockStmt b, Collection mappings) throws MojoFailureException { Map produce = new HashMap<>(); + String defaultType = null; for (JaxrsMapping m : mappings) { + if (defaultType == null) + defaultType = m.produce[0]; for (String p : m.produce) { JaxrsMapping other = produce.put(p, m); if (other != null) @@ -402,8 +410,7 @@ private BlockStmt buildProduces(BlockStmt b, Collection mappings) } } - MethodCallExpr accept = new MethodCallExpr(new NameExpr("req"), "getAccepted", - CodeGenUtils.list(mt.predicate(types, produce.keySet()), mt.type(types, produce.keySet().iterator().next()))); + MethodCallExpr accept = new MethodCallExpr(new NameExpr("req"), "getAccepted", CodeGenUtils.list(mt.predicate(types, produce.keySet()), mt.type(types, defaultType))); JaxrsMapping def = produce.remove("*/*"); Statement stmt = new ThrowStmt(new ObjectCreationExpr(null, types.getClass(NotAcceptableException.class), CodeGenUtils.list())); @@ -435,6 +442,7 @@ private BlockStmt buildProduces(BlockStmt b, Collection mappings) /** * build the method that will parse service parameter, call the service method and write the response + * * @param mapping the mapping * @param services service class -> Expression */ @@ -466,6 +474,7 @@ private void buildCall(JaxrsMapping mapping, Map services) { /** * get the Exception to conver a param to java type + * * @param p the param * @return the excpetion to convert the param */ @@ -487,7 +496,7 @@ private interface ServiceBuilder { /** * service without pattern - * will implements do() directly + * will implements do() directly */ private class SimpleService implements ServiceBuilder {