Results 1 to 6 of 6
  1. #1
    yhqian99 is offline Member
    Join Date
    Feb 2009
    Posts
    14
    Rep Power
    0

    Default @WebServiceClient Annotation

    Hi all,

    I have a web service client code with Annotation like the following, as you can see the web service IP ( 192.168.31.229 ) is hard coded, and it appears in three places in the code. I need to update code and compile it again when the IP has changed . now I am trying to store the IP in a configuration file and read the IP from it when the application started.

    My question is:
    do I need to replace the IP in the @WebServiceClient annotation? if yes, how to do it? Thanks a lot! ----Yhqian



    @WebServiceClient(name = "TelWebServiceImplService", targetNamespace = "http://impl.service.bsi.com/", wsdlLocation = "http://192.168.31.229:8888/SCSERC_CHK/ws/telWebService?wsdl")

    public class TelWebServiceImplService extends Service {

    .........................

    static {
    URL url = null;
    try {
    URL baseUrl;
    baseUrl = com.ictbox.acc.trigger.ggxx.TelWebServiceImplServi ce.class
    .getResource(".");
    url = new URL(baseUrl,
    "http://192.168.31.229:8888/SCSERC_CHK/ws/telWebService?wsdl");
    } catch (MalformedURLException e) {
    logger.warning("Failed to create URL for the wsdl Location: 'http://192.168.31.229:8888/SCSERC_CHK/ws/telWebService?wsdl', retrying as a local file");
    logger.warning(e.getMessage());
    }
    TELWEBSERVICEIMPLSERVICE_WSDL_LOCATION = url;
    }

    .........................

    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: @WebServiceClient Annotation

    If the value is a String, then it must be a compile time constant. You can't have dynamic String values in annotations.

    See also, the tough read: Chapter*9.*Interfaces
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    yhqian99 is offline Member
    Join Date
    Feb 2009
    Posts
    14
    Rep Power
    0

    Default Re: @WebServiceClient Annotation

    you said :You can't have dynamic String values in annotations

    In what condition we can have dynamic values in annotations?

  4. #4
    yhqian99 is offline Member
    Join Date
    Feb 2009
    Posts
    14
    Rep Power
    0

    Default Re: @WebServiceClient Annotation

    Quote Originally Posted by SurfMan View Post
    If the value is a String, then it must be a compile time constant. You can't have dynamic String values in annotations.

    See also, the tough read: Chapter*9.*Interfaces

    I think this requirement is quite general, for example, the test IP and production IP is different,
    is there a way to dynamically reference web service? My application is just a java standalone application, not dependent on some framework.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: @WebServiceClient Annotation

    Quote Originally Posted by yhqian99 View Post
    you said :You can't have dynamic String values in annotations

    In what condition we can have dynamic values in annotations?
    None.

    The spec says:
    T is not an array type, and the type of V is assignment compatible (5.2) with T, and:
    - If T is a primitive type or String, then V is a constant expression (15.28).
    - If T is Class or an invocation of Class (4.5), then V is a class literal (15.8.2).
    - If T is an enum type (8.9), then V is an enum constant (8.9.1).
    - V is not null.
    So, this annotation has three Strings:
    Java Code:
    @WebServiceClient(name = "TelWebServiceImplService", 
                                  targetNamespace = "http://impl.service.bsi.com/", 
                                  wsdlLocation = "http://192.168.31.229:8888/SCSERC_CHK/ws/telWebService?wsdl")
    - They all must be literal as they are now, or some static final String "constant" MyClass.SOME_STRING_CONSTANT.
    - If it's a primitive, then the value must be a literal, like 1 or true, or MyClass.MY_INT_CONSTANT
    - If it's a Class, then the value must be a class literal in the form of String.class, MyObject.class, etc
    - If it's an enum, then the value must be an enum, Directions.WEST, Directions.NORTH, whatever enum you have...
    - and the value can't be null, so this is illegal: wsdlLocation=null
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: @WebServiceClient Annotation

    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. annotation error
    By simar in forum New To Java
    Replies: 11
    Last Post: 09-15-2014, 11:21 AM
  2. annotation help
    By javastuden in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2013, 11:37 AM
  3. Use of @Before and @After annotation with example..
    By dhavalthakor28 in forum Struts
    Replies: 4
    Last Post: 09-07-2012, 05:38 PM
  4. what is annotation? what is the use?
    By java_no1 in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •