19

I am trying to develop a IBM JAX_WS web service using RSA 7.5 and Websphere 7 server. Since I am a beginner, hence I am following Java-class first approach i.e. I am creating the Java classes first and then generating the WSDL file.

When i try to create the wsdl file, i am getting an exception:

java.security.PrivilegedActionException:com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationsException Class has two properties of the same name "planId"

My class refered here looks something like this:

public class MemberDetails{
    @XMLElement(required=true)
    private String planId;
    //public getters and setters for the planId;
}

I dont have any idea like why is this exception happening. Via Google search I tried a few alternatives to resolve it but none of them worked for me :(

Note:

This is the only annotation I am using throughout my workspace. I am not sure if this is dependent on some other annotations or not. But I tried with a few such as @XMLElement(name="Plan",required=true), @XMLType, etc but every time I am getting this exception.

This exception is occuring during wsgen. (java.lang.reflect.InvocationTargetException)

EDIT

Basically, when we create a wsdl from java service method and open that WSDL in SOAP UI, then we get <!--Optional--> at the top of every element. I want to remove this option tag <!--Optional--> tag, hence I am trying for @XMLElement(required=true) approach so that when I open the WSDL in SOAP UI <!--Optional--> does not appears for compulsary elements.

According to my concept, @XMLElement(required=true) will set the minOccurs to 1 i.e. greater than zero and hence the optional comment will be removed from WSDL when I open it in SOAP UI. But Unfortunately its not working hence my concept is incorrect. After the WSDL is generated, I can see that the minOccurs is still 0.

Please explain how can I remove the optional tag when I open the WSDL in SOAP UI.

Regards,

Gijs Overvliet
  • 2,643
  • 3
  • 28
  • 35
user182944
  • 7,897
  • 33
  • 108
  • 174

2 Answers2

44

By default JAXB (JSR-222) implementations process public accessor methods and annotated fields. If you annotate a field that you also have get/set methods for you will get this exception:

If you are going to annotate fields then you should specify @XmlAccessorType(XmlAccessType.FIELD)

@XmlAccessorType(XmlAccessType.FIELD)
public class MemberDetails{
    @XMLElement(required=true)
    private String planId;
    //public getters and setters for the planId;
}

Or you can annotate the property

public class MemberDetails{

    private String planId;

    @XMLElement(required=true)
    public String getPlanId() {
        return planId;
    }
}

For More Information

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Thanks for the response. FOllowing the way you suggested, the WSDL is getting created without any wsgen exception. But my target is not achieved. I have edited my above post to describe what I am trying to achieve any why. Please have a look at the edited section of the 1st post and help. – user182944 Sep 13 '12 at 15:45
0

For JAXB2.0 annotating with @XmlTransient on getter or setter will prevent the conflict.

See more here: http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/XmlTransient.html

kmaziarz
  • 154
  • 5