newbie
newbie

Reputation: 14950

How to include constants class in generating a wsdl

Good day!

I have a constant class that I want to automatically include upon the creation of my wsdl.. But whenever I automatically generate the client on my IDE, the constant_class doesn't appear.. Why? How can i resolve this problem..

My code is as follows:

CONSTANT CLASS ...

public final class TestConstants {

    public static String TEST_CONSTANT = "TEST_CONSTANT";

}

Thank you.

Upvotes: 3

Views: 1695

Answers (2)

oiprado
oiprado

Reputation: 1

to include constants into wsdl you have to use enumeration to specifie your constants,adding restriction into xsd file and then, your web server avaluate the request before use java code.

use like this:

public enum ACTION {
        ADVERTENCIA("com.util.log.level.WARNING"),
        INFO("com.util.log.level.INFO");

        private String value;

        ACTION(String value){
            this.value = value;
        }

        public String getValue(){
            return value;
        }
    }

And finally, you can use the enum as parameter into the web service:

public String log(@WebParam(name = "action`enter code here`") ACTION action) {
}

Upvotes: 0

user159088
user159088

Reputation:

As far as I know you can't include constants in WSDL.

If you need to specify some set of constants to use, you might get away with it by using entities.

Another approach will be by use of enumerations to reduce the possible values:

<xsd:simpleType name="ConstantsType">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="TEST_CONSTANT_1" />
    <xsd:enumeration value="TEST_CONSTANT_2" />
    ....
    <xsd:enumeration value="TEST_CONSTANT_N" />
  </xsd:restriction>
</xsd:simpleType>

and then have some elements be of that type (i.e. their value is one of the constants):

<xsd:element name="SomeElement" type="ConstantsType" />

But besides these two solutions I don't really see how to include constants in WSDL.

That class does not seem to me that is has a relation with the message contract of a service so that it should belong in a WSDL. What are you trying to do? Maybe there is a better way to do it.

Upvotes: 1

Related Questions