Question

I am encountering an error during integrating enunciate and ant for CXF REST service APIs project. Error exists in method getFeeItemsByCapID(). I try to find answer in source code, but without result. Who has any idea about the error? Thanks for your help. If you have any tips.

Ant Script

<path id="enunciate.classpath">
    <fileset dir="${enunciate.home}/lib">
        <include name="*.jar"/>
        </fileset>
        <!--include (optional) spring module-->
        <fileset dir="${enunciate.home}/lib/modules/cxf">
            <include name="*.jar"/>
        </fileset>
        <fileset dir="${java.home}">
            <include name="lib/tools.jar"/>
        </fileset>
    </path>

    <taskdef name="enunciate" classname="org.codehaus.enunciate.main.EnunciateTask">
        <classpath refid="enunciate.classpath"/>
    </taskdef>  

    <enunciate basedir="java/" configFile="enunciate.xml">
        <include name="**/*.java"/>
        <classpath refid="enunciate.classpath"/>
        <export artifactId="war.file" destination="d:/myapp.war"/>
        <javacArgument argument="-g"/>
    </enunciate>

Enunciate.xml

<?xml version="1.0"?>
<enunciate label="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
<namespaces>
    <namespace id="api" uri="http://api.example.com/" />
    <namespace id="link" uri="http://api.example.com/link" />
    <namespace id="persona" uri="http://api.example.com/persona" />
</namespaces>
<modules>
    <!-- Docs -->
    <docs splashPackage="org.codehaus.enunciate.api" title="test" copyright="test.com"/>
    <java-client disabled="false"/>
    <amf disabled="true"/>
    <c disabled="true"/>
    <obj-c disabled="true"/>
    <csharp disabled="true"/>
    <spring-app disabled="false"/>
    <cxf disabled="false"/>
    <gwt disabled="true"/>
    <jaxws-ri disabled="true"/>
    <jersey disabled="true"/>
</modules>

Java Code

@GET
@RecordDetailSecurity(RecordDetailSectionType.FEE)
@Path("/{recordIds}/fees/")
@Produces(MediaType.APPLICATION_JSON)
@JsonView(Views.PublicView.class)
public ResponseModel getFeeItemsByCapID(@PathParam("recordIds") String recordIds,
        @QueryParam("fields") @DefaultValue("") String fields) throws Exception
{

Exception:

java.lang.IllegalStateException: D:\AA7.2.0\main-dev\biz\modules\rest-apis\java\com\accela\restapis\jaxrs\agency\service\FeeWebService.java:76: the element 'value' must have a value specified.
    at net.sf.jelly.apt.decorations.declaration.DecoratedAnnotationMirror.<init>(DecoratedAnnotationMirror.java:66)
    at net.sf.jelly.apt.decorations.DeclarationDecorator.decorate(DeclarationDecorator.java:362)
    at net.sf.jelly.apt.decorations.DeclarationDecorator.decorateAnnotationMirrors(DeclarationDecorator.java:113)
    at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotationMirrors(DecoratedDeclaration.java:213)
    at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotations(DecoratedDeclaration.java:195)
    at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotation(DecoratedDeclaration.java:225)
    at org.codehaus.enunciate.contract.jaxrs.ResourceMethod.<init>(ResourceMethod.java:130)
    at org.codehaus.enunciate.contract.jaxrs.Resource.getResourceMethods(Resource.java:143)
    at org.codehaus.enunciate.contract.jaxrs.Resource.<init>(Resource.java:69)
    at org.codehaus.enunciate.contract.jaxrs.RootResource.<init>(RootResource.java:34)
    at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.getRootModel(EnunciateAnnotationProcessor.java:214)
    at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.process(EnunciateAnnotationProcessor.java:103)
    at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
    at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
    at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
    at com.sun.tools.apt.main.Main.compile(Main.java:1102)
    at com.sun.tools.apt.main.Main.compile(Main.java:964)
    at com.sun.tools.apt.Main.processing(Main.java:95)
    at com.sun.tools.apt.Main.process(Main.java:85)
    at com.sun.tools.apt.Main.process(Main.java:67)
    at org.codehaus.enunciate.main.Enunciate.invokeApt(Enunciate.java:777)
    at org.codehaus.enunciate.main.Enunciate.doGenerate(Enunciate.java:366)
    at org.codehaus.enunciate.main.Enunciate$Stepper.step(Enunciate.java:1735)
    at org.codehaus.enunciate.main.Enunciate$Stepper.stepTo(Enunciate.java:1767)
    at org.codehaus.enunciate.main.Enunciate.execute(Enunciate.java:174)
    at org.codehaus.enunciate.main.EnunciateTask.execute(EnunciateTask.java:156)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Source Code:

public DecoratedAnnotationMirror(AnnotationMirror delegate) {
if (delegate == null) {
  throw new IllegalArgumentException("A delegate must be provided.");
}

this.delegate = delegate;
AnnotationType annotationType = delegate.getAnnotationType();
Collection<AnnotationTypeElementDeclaration> allElements = annotationType.getDeclaration() != null? annotationType.getDeclaration().getMethods() : Collections.<AnnotationTypeElementDeclaration>emptyList();
Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = getElementValues();

put("annotationType", annotationType);
put("position", delegate.getPosition());
put("elementValues", elementValues);
allElementValues = new HashMap<String, Object>();
for (AnnotationTypeElementDeclaration element : allElements) {
  if (elementValues.containsKey(element)) {
    Object value = elementValues.get(element).getValue();
    allElementValues.put(element.getSimpleName(), value);
    put(element.getSimpleName(), value);
  }
  else {
    AnnotationValue defaultValue = element.getDefaultValue();
    if (defaultValue == null) {
      throw new IllegalStateException(delegate.getPosition() + ": the element '" + element.getSimpleName() + "' must have a value specified.");
    }
Was it helpful?

Solution 2

About annotation default value error, I have created a sample project to try again. It works well. Now, I need to change my original opinion. It's my fault. :) Firstly, my project compiling is successful without enunciate ant target before. However the enumeration "RecordDetailSectionType " belongs to another jar actually. I didn't include the jar in to enunciate class path, so enunciate cannot to recognize the customized annotation type value. Sorry for the misunderstanding.

OTHER TIPS

I have found root cause in my Customized Annotation. It seems because the annotation without default value. When I removed the customized annotation of method or append default value in annotation definition. the exception will be gone. But the annotation accept an enumeration, in business logic the annotation without default value. We always need to set enum value for using. But, why annotation always need default value? Anybody know the reason?

@Target( {ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RecordDetailSecurity
{
    RecordDetailSectionType value(); //append default value such as "default RecordDetailSectionType.ADDITIONAL_INFORMATION;"
}

@RecordDetailSecurity(RecordDetailSectionType.FEE)
public ResponseModel getFeeItemsByCapID(@PathParam("recordIds") String recordIds,
    @QueryParam("fields") @DefaultValue("") String fields) throws Exception
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top