diff --git a/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeader.java b/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeader.java new file mode 100644 index 000000000..d9115036c --- /dev/null +++ b/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeader.java @@ -0,0 +1,23 @@ +package org.codehaus.enunciate.jaxrs; + +/** + * Documents an expected response header for a resource or resource method. + * + * @author Ryan Heaton + */ +public @interface ResponseHeader { + + /** + * The name of the response header. + * + * @return The name of the response header. + */ + String name(); + + /** + * The description of the response header. + * + * @return The description of the response header. + */ + String description(); +} diff --git a/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeaders.java b/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeaders.java new file mode 100644 index 000000000..9a87ed2aa --- /dev/null +++ b/core-annotations/src/main/java/org/codehaus/enunciate/jaxrs/ResponseHeaders.java @@ -0,0 +1,19 @@ +package org.codehaus.enunciate.jaxrs; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Documents expected response headers for a resource or resource method. + * + * @author Ryan Heaton + */ +@Retention ( RetentionPolicy.RUNTIME ) +@Target ({ ElementType.TYPE, ElementType.METHOD }) +public @interface ResponseHeaders { + + ResponseHeader[] value(); + +} diff --git a/core/src/main/java/org/codehaus/enunciate/contract/jaxrs/ResourceMethod.java b/core/src/main/java/org/codehaus/enunciate/contract/jaxrs/ResourceMethod.java index c3554f1aa..552234186 100644 --- a/core/src/main/java/org/codehaus/enunciate/contract/jaxrs/ResourceMethod.java +++ b/core/src/main/java/org/codehaus/enunciate/contract/jaxrs/ResourceMethod.java @@ -25,9 +25,7 @@ import net.sf.jelly.apt.decorations.type.DecoratedClassType; import net.sf.jelly.apt.decorations.type.DecoratedTypeMirror; import org.codehaus.enunciate.contract.validation.ValidationException; -import org.codehaus.enunciate.jaxrs.StatusCodes; -import org.codehaus.enunciate.jaxrs.TypeHint; -import org.codehaus.enunciate.jaxrs.Warnings; +import org.codehaus.enunciate.jaxrs.*; import org.codehaus.enunciate.rest.MimeType; import javax.ws.rs.*; @@ -56,6 +54,7 @@ public class ResourceMethod extends DecoratedMethodDeclaration { private final Map metaData = new HashMap(); private final List statusCodes; private final List warnings; + private final Map responseHeaders = new HashMap(); private final ResourceRepresentationMetadata representationMetadata; public ResourceMethod(MethodDeclaration delegate, Resource parent) { @@ -224,6 +223,20 @@ else if (parameterDeclaration.getAnnotation(Context.class) == null) { } } + ResponseHeaders responseHeaders = parent.getAnnotation(ResponseHeaders.class); + if (responseHeaders != null) { + for (ResponseHeader header : responseHeaders.value()) { + this.responseHeaders.put(header.name(), header.description()); + } + } + + responseHeaders = getAnnotation(ResponseHeaders.class); + if (responseHeaders != null) { + for (ResponseHeader header : responseHeaders.value()) { + this.responseHeaders.put(header.name(), header.description()); + } + } + this.entityParameter = entityParameter; this.resourceParameters = resourceParameters; this.subpath = subpath; @@ -582,4 +595,12 @@ public void putMetaData(String name, Object data) { this.metaData.put(name, data); } + /** + * The response headers that are expected on this resource method. + * + * @return The response headers that are expected on this resource method. + */ + public Map getResponseHeaders() { + return responseHeaders; + } } diff --git a/core/src/main/java/org/codehaus/enunciate/main/Enunciate.java b/core/src/main/java/org/codehaus/enunciate/main/Enunciate.java index 3e178a5f8..0eaef0488 100644 --- a/core/src/main/java/org/codehaus/enunciate/main/Enunciate.java +++ b/core/src/main/java/org/codehaus/enunciate/main/Enunciate.java @@ -97,6 +97,7 @@ public enum Target { private final Set additionalSourceRoots = new TreeSet(); private final Set webAppFragments = new TreeSet(new WebAppFragmentComparator()); private final List classpathHandlers = new ArrayList(); + private final List configuredJavacArguments = new ArrayList(); public static void main(String[] args) throws Exception { Main.main(args); @@ -857,6 +858,7 @@ public void invokeJavac(String classpath, String version, File compileDir, List< args.add("-d"); args.add(compileDir.getAbsolutePath()); args.addAll(additionalArgs); + args.addAll(this.configuredJavacArguments); args.addAll(Arrays.asList(sourceFiles)); if (isDebug()) { @@ -1644,6 +1646,15 @@ public boolean isModuleEnabled(String moduleName) { return false; } + /** + * Configured arguments to pass to the Enunciate java compiler. + * + * @return Configured arguments to pass to the Enunciate java compiler. + */ + public List getConfiguredJavacArguments() { + return configuredJavacArguments; + } + /** * Set the configuration for the mechanism. * diff --git a/core/src/main/java/org/codehaus/enunciate/main/EnunciateTask.java b/core/src/main/java/org/codehaus/enunciate/main/EnunciateTask.java index 725f7bee6..d6dad545a 100644 --- a/core/src/main/java/org/codehaus/enunciate/main/EnunciateTask.java +++ b/core/src/main/java/org/codehaus/enunciate/main/EnunciateTask.java @@ -59,6 +59,7 @@ public class EnunciateTask extends MatchingTask { private File flexHome; private Enunciate.Target target; private final ArrayList exports = new ArrayList(); + private final ArrayList javacArguments = new ArrayList(); /** * Executes the enunciate task. @@ -355,6 +356,17 @@ public Export createExport() { return export; } + /** + * Creates a nested javac argument. + * + * @return the nested javac argument. + */ + public JavacArgument createJavacArgument() { + JavacArgument export = new JavacArgument(); + this.javacArguments.add(export); + return export; + } + /** * A nested export task. */ @@ -400,6 +412,32 @@ public void setDestination(File destination) { } } + /** + * A nested javac argument task. + */ + public static class JavacArgument { + + private String argument; + + /** + * The argument. + * + * @return The argument + */ + public String getArgument() { + return argument; + } + + /** + * The argument. + * + * @param argument The javac argument. + */ + public void setArgument(String argument) { + this.argument = argument; + } + } + /** * An Enunciate mechanism that leverages Ant's logging capabilities, too. */ @@ -411,12 +449,16 @@ public AntLoggingEnunciate(String[] sourceFiles) { @Override public void debug(String message, Object... formatArgs) { - getProject().log(String.format(message, formatArgs), Project.MSG_VERBOSE); + if (debug) { + getProject().log(String.format(message, formatArgs), Project.MSG_VERBOSE); + } } @Override public void info(String message, Object... formatArgs) { - getProject().log(String.format(message, formatArgs), Project.MSG_INFO); + if (verbose) { + getProject().log(String.format(message, formatArgs), Project.MSG_INFO); + } } @Override diff --git a/core/src/main/java/org/codehaus/enunciate/main/Main.java b/core/src/main/java/org/codehaus/enunciate/main/Main.java index c4069364f..0b243e95e 100644 --- a/core/src/main/java/org/codehaus/enunciate/main/Main.java +++ b/core/src/main/java/org/codehaus/enunciate/main/Main.java @@ -100,6 +100,7 @@ public enum Option { debug("vv", "Print debug-level output to the console."), disableDebugInfo("xg", "Disable compilation with debug info."), javacCheck("Xc", "Do a javac check before invoking Enunciate."), + javacArguments("Xa", "argument", "Extra arguments to pass to javac. May be repeated."), configFile("f", "file", "The enunciate xml config file."), generateDir("g", "dir", "The output directory for the \"generate\" step."), compileDir("c", "dir", "The output directory for the \"compile\" step."), @@ -295,6 +296,10 @@ public boolean handle(String option, String value, Enunciate enunciate) { enunciate.addExport(option.substring(1), new File(value)); return true; + case javacArguments: + enunciate.getConfiguredJavacArguments().add(value); + return true; + default: return false; } diff --git a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.fmt b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.fmt index 8d25a1960..95b06a565 100644 --- a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.fmt +++ b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.fmt @@ -775,7 +775,7 @@ [/#list] [#list operation.warning as warning] [#if warning_index = 0] -

Possible Warnings

+

Warnings

@@ -790,6 +790,23 @@
code
[/#if] [/#list] + [#list operation.responseHeader as responseHeader] + [#if responseHeader_index = 0] +

Response Headers

+ + + + + + [/#if] + + + + + [#if !responseHeader_has_next] +
namedescription
${responseHeader.name}${responseHeader.documentation}
+ [/#if] + [/#list] [/#list] [/#macro] [#macro processEndpointInterface endpointInterface] diff --git a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xml.fmt b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xml.fmt index bfe68b4bd..f731feb7e 100644 --- a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xml.fmt +++ b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xml.fmt @@ -385,6 +385,12 @@ [/#list] + [#list resource.responseHeaders?keys as responseHeader] + + ${responseHeader} + + + [/#list] [#--[/#if]--] [/#if] diff --git a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xsd b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xsd index cdb06ac40..df04f2c14 100644 --- a/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xsd +++ b/docs/src/main/resources/org/codehaus/enunciate/modules/docs/docs.xsd @@ -635,6 +635,7 @@ + @@ -643,6 +644,13 @@ + + + + + + + diff --git a/documentation/executables.html b/documentation/executables.html index 95176131b..4e31f1a46 100644 --- a/documentation/executables.html +++ b/documentation/executables.html @@ -259,6 +259,11 @@

Configuration

boolean Whether to compile with debug information. + + javacArguments + array + List of additional arguments passed to Enunciate's Java compiler when compiling client-side code. +

Example

@@ -418,11 +423,13 @@

Enunciate Task Attributes

Nested Elements

In addition to the nested elements of a MatchingTask - that are used to select the source files on which to invoke Enunciate, the EnunciateTask supports two additional nested elements.

+ that are used to select the source files on which to invoke Enunciate, the EnunciateTask supports additional nested elements.

  • The classpath element is a path-like structure used to specify the Enunciate classpath for execution.
  • +
  • The javacArgument element is used to configure extra argument(s) to apply when Enunciate compiles client-side artifacts. It supports an "argument" + attribute to pass in the value of the argument.
  • The export element is used to specify an export. Here are its attributes:
@@ -470,6 +477,7 @@

Example

<include name="**/*.java"/> <classpath refid="enunciate.classpath"/> <export artifactId="war.file" destination="${tomcat.home}/webapps/myapp.war"/> + <javacArgument argument="-g"/> </enunciate> ... diff --git a/gwt/src/main/resources/org/codehaus/enunciate/modules/gwt/gwt-type-mapper.fmt b/gwt/src/main/resources/org/codehaus/enunciate/modules/gwt/gwt-type-mapper.fmt index a83ff922e..5accba5b9 100644 --- a/gwt/src/main/resources/org/codehaus/enunciate/modules/gwt/gwt-type-mapper.fmt +++ b/gwt/src/main/resources/org/codehaus/enunciate/modules/gwt/gwt-type-mapper.fmt @@ -18,7 +18,7 @@ import org.codehaus.enunciate.modules.gwt.*; * @author Ryan Heaton */ @java.lang.SuppressWarnings( {"all"} ) -public [#if type.abstract]abstract [/#if][#if type.final]final [/#if]class ${type.simpleName}GWTMapper [#if baseobject]extends BaseGWTMapper [#else]extends ${type.superclass.declaration.package.qualifiedName + ".gwt." + type.superclass.declaration.simpleName}GWTMapper [/#if]implements GWTMapper { +public [#if type.abstract]abstract [/#if][#if type.final]final [/#if]class ${type.simpleName}GWTMapper [#if baseobject]extends BaseGWTMapper [#else]extends ${type.superclass.declaration.package.qualifiedName + ".gwt." + type.superclass.declaration.simpleName}GWTMapper [/#if] { public ${type.simpleName}GWTMapper() { super(${type.qualifiedName}.class, ${classname}.class[#list type.attributes as attribute], "${attribute.simpleName}"[/#list][#if type.value?exists], "${type.value.simpleName}"[#else][#list type.elements as element], "${element.simpleName}"[/#list][/#if]); diff --git a/integration-tests/jaxws-ri-rest/src/main/samples/full/org/codehaus/enunciate/samples/genealogy/services/PersonService.java b/integration-tests/jaxws-ri-rest/src/main/samples/full/org/codehaus/enunciate/samples/genealogy/services/PersonService.java index cb9aeb5df..c187de4f8 100644 --- a/integration-tests/jaxws-ri-rest/src/main/samples/full/org/codehaus/enunciate/samples/genealogy/services/PersonService.java +++ b/integration-tests/jaxws-ri-rest/src/main/samples/full/org/codehaus/enunciate/samples/genealogy/services/PersonService.java @@ -18,9 +18,7 @@ import com.sun.jersey.multipart.FormDataParam; import org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature; -import org.codehaus.enunciate.jaxrs.ResponseCode; -import org.codehaus.enunciate.jaxrs.StatusCodes; -import org.codehaus.enunciate.jaxrs.Warnings; +import org.codehaus.enunciate.jaxrs.*; import org.codehaus.enunciate.samples.genealogy.data.Person; import org.codehaus.enunciate.samples.genealogy.data.PersonExt; import org.codehaus.enunciate.samples.genealogy.data.RootElementMapWrapper; @@ -57,6 +55,9 @@ public interface PersonService { ) @PUT @Path ("/pedigree/person") + @ResponseHeaders ( + @ResponseHeader( name = "Location", description = "The location of the person stored.") + ) Person storePerson(Person person); @GET diff --git a/jersey/src/main/java/org/codehaus/enunciate/modules/jersey/JerseyDeploymentModule.java b/jersey/src/main/java/org/codehaus/enunciate/modules/jersey/JerseyDeploymentModule.java index 1921e3057..2157106f4 100644 --- a/jersey/src/main/java/org/codehaus/enunciate/modules/jersey/JerseyDeploymentModule.java +++ b/jersey/src/main/java/org/codehaus/enunciate/modules/jersey/JerseyDeploymentModule.java @@ -74,10 +74,10 @@ * *

Content Negotiation

* - *

Enuncite provides content type negotiation (conneg) to Jersey that conforms to the content type negotiation of - * the Enunciate REST module. This means that each resource is mounted from the REST subcontext (see above) but ALSO from a subcontext that conforms to the - * id of each content type that the resource supports. So, if the content type id of the "application/xml" content type is "xml" then the resource at path - * "mypath" will be mounted at both "/rest/mypath" and "/xml/mypath".

+ *

Enuncite provides a special content negotiation (conneg) to Jersey such that that each resource is mounted from the REST subcontext (see above) but + * ALSO from a subcontext that conforms to the id of each content type that the resource supports. So, if the content type id of the "application/xml" + * content type is "xml" then the resource at path "mypath" will be mounted at both "/rest/mypath" and "/xml/mypath". You can disable this path-based content + * negotiation feature by setting usePathBasedConneg="false".

* *

The content types for each JAX-RS resource are declared by the @Produces annotation. The content type ids are customized with the * "enunciate/services/rest/content-types" element in the Enunciate configuration. Enunciate supplies providers for the "application/xml" and "application/json" diff --git a/maven-enunciate-slim-plugin/src/main/java/org/codehaus/enunciate/ConfigMojo.java b/maven-enunciate-slim-plugin/src/main/java/org/codehaus/enunciate/ConfigMojo.java index 9c2d46266..abdf2fed8 100644 --- a/maven-enunciate-slim-plugin/src/main/java/org/codehaus/enunciate/ConfigMojo.java +++ b/maven-enunciate-slim-plugin/src/main/java/org/codehaus/enunciate/ConfigMojo.java @@ -172,6 +172,13 @@ public class ConfigMojo extends AbstractMojo { */ private String[] excludeProjectExtensions; + /** + * List of extra arguments to Enunciate's javac. + * + * @parameter + */ + private String[] javacArguments; + /** * Whether to include reference trail information in validation errors. * @@ -595,6 +602,9 @@ public MavenSpecificEnunciate(Collection rootDirs) { setSourceFiles(sources.toArray(new String[sources.size()])); setEncoding(compilationEncoding); + if (javacArguments != null) { + getConfiguredJavacArguments().addAll(Arrays.asList(javacArguments)); + } } public void loadMavenConfiguration() throws IOException {