Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

/**
* Build a jaxrs servlet
*
* @author unknow
*/
public class JaxRsServletBuilder {
Expand Down Expand Up @@ -149,6 +150,7 @@ public JaxRsServletBuilder(CompilationUnit cu, Map<String, String> existingClass

/**
* convert a path mapping to a java class name
*
* @param path the path
* @return the class name
*/
Expand Down Expand Up @@ -285,6 +287,7 @@ private void buildOptions(String name, Set<String> methods) {

/**
* create all required converter and add them to servlet fields
*
* @param p the param
* @param n converter field name
* @param i parameter index
Expand Down Expand Up @@ -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<JaxrsMapping> list) throws MojoFailureException {

Expand Down Expand Up @@ -387,23 +391,26 @@ private static Map<List<JaxrsMapping>, Collection<String>> 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<JaxrsMapping> mappings) throws MojoFailureException {
Map<String, JaxrsMapping> 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)
throw new MojoFailureException("Duplicate mapping on " + m.m + " and " + other.m);
}
}

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()));
Expand Down Expand Up @@ -435,6 +442,7 @@ private BlockStmt buildProduces(BlockStmt b, Collection<JaxrsMapping> 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
*/
Expand Down Expand Up @@ -466,6 +474,7 @@ private void buildCall(JaxrsMapping mapping, Map<String, NameExpr> services) {

/**
* get the Exception to conver a param to java type
*
* @param p the param
* @return the excpetion to convert the param
*/
Expand All @@ -487,7 +496,7 @@ private interface ServiceBuilder {

/**
* service without pattern
* will implements do<Method>() directly
* will implements do<Method>() directly
*/
private class SimpleService implements ServiceBuilder {

Expand Down
Loading