0

I am having a maven build and project with a webservice client that will be deployed on a wildfly server. In my Client EJB, I have the following

@Stateless
public class MyClientEJB {

    @WebServiceRef(wsdlLocation = "http://localhost:8080/HelloWorld/HelloWorldService?wsdl")
    private HelloWorldService service;

I want to have different url for Test and Production, how can I have this url as a configurable entry. I tried creating profiles in my pom.xml file but that requires following code and I don't know how to use it in @WebServiceRef annotation.

private void initProperties() {
    InputStream is = getClass().getClassLoader().getResourceAsStream("application.properties");

    if (is != null) {
        try {
            properties.load(is);

            BASE_URL = (String)properties.getProperty("student.restws.url");    

        } catch (IOException e) {               
            logger.error("Error when reading properties: ", e);
            throw new RuntimeException("Can not load application.properties file.");
        }
    } else {        
        logger.error("Error when finding application.properties.");
        throw new RuntimeException("Error when finding application.properties.");
    }
} 

Any example would be appreciated. Thanks

Update:

I added wsdl folder under src/main/resources/META_INF and copied the wsdl file there. In the @WebServiceRef annotation then updated to @WebServiceRef(wsdlLocation = "META-INF/wsdl/HelloWorld.wsdl")

But I get the following runtime error when webservice is invoked.

Caused by: java.io.IOException: JBAS015526: Child 'META-INF/wsdl/HelloWorld.wsdl' not found for VirtualFile: "/C:/wildfly-8.1.0.Final/bin/content/hello-world.war"

wsdl file has the following defined:

<wsdl:service name="HelloWorldService">
  <wsdl:port name="HelloWorldPort" binding="tns:HelloWorldEndpointBinding" >
    <soap:address location="http://localhost:9090/HelloWorldPort"/>
  </wsdl:port>
</wsdl:service>
Nova Guy
  • 505
  • 2
  • 9
  • 16

3 Answers3

0

You cannot have dynamic strings in annotations.

But you could use @WebServiceRef(wsdlLocation = "META-INF/wsdl/service.wsdl") and use maven profiles to copy the right file to this location.

Hannes
  • 2,018
  • 25
  • 32
0

According to http://victor-ichim.blogspot.com/2012/02/dynamic-wsdl-location-with-jax-ws.html the correct approach is to:

Fix the wsdl location by saving the contract locally.

  1. Generate the JAX-WS artifacts and save the wsdl
  2. Point the service reference to the local wsdl
  3. Include the wsdl in the deployment unit
Gili
  • 86,244
  • 97
  • 390
  • 689
-1

I solved this problem. Put beans.xml to webapp/WEB-INF

beans.xml content:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="java.sun.com/xml/ns/javaee";
    xmlns:xsi="w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="java.sun.com/xml/ns/javaee java.sun.com/xml/ns/javaee/beans_1_0.xsd">;
</beans>
Orest Hera
  • 6,706
  • 2
  • 21
  • 35
Aibeke
  • 9
  • 2
  • Please re-edit your answer instead of putting a part of the answer in a comment. Answers are easier to format as well. – Daniel Nov 16 '15 at 15:54