Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

How to read from property file inside wsdl file?

i have wsdl file under src/wsdl and i was wondering if it's possible to read value from property file inside this wsdl file as follows:

<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-b02-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-b02-. --><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://AXLInterface.jaxws.AllInOne.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://AXLInterface.jaxws.AllInOne.org/" name="AXLInterfaceService">
<types>
<xsd:schema>
<xsd:import namespace="http://AXLInterface.jaxws.AllInOne.org/" schemaLocation="${wsdl.url}/AXLInterface?xsd=1"></xsd:import>
</xsd:schema>

</definitions>

i have PropertyPlaceholderConfigurer defined in applicationContext as follows:

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:messages/application.properties</value>
                <value>file:${APP_HOME}/Common/Conf/app.properties
                </value>
            </list>
        </property>

        <property name="ignoreResourceNotFound" value="true" />
        <property name="searchSystemEnvironment" value="true" />
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    </bean>

when i tried to compile the application i got an error in the wsdl file:

[ERROR] Unable to parse "${wsdl.url}/AXLInterface?xsd=1" : Illegal character in path at index 1: ${wsdl.url}/AXLInterface?xsd=1

[ERROR] java.net.URISyntaxException: Illegal character in path at index 1: ${wsdl.url}/AXLInterface?xsd=1

please advise how to accomplish that, thanks.

Upvotes: 3

Views: 3026

Answers (3)

asgoth
asgoth

Reputation: 35829

You have to enable filtering for your war plugin:

<plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1.1</version>
   <configuration>
      <webResources>
         <resource>
            <directory>src/wsdl</directory>
            <filtering>true</filtering>
         </resource>
      </webResources>
      ...

Afterwards you probably will need to update your maven project configuration.

enter image description here

Upvotes: 0

Manuel Quinones
Manuel Quinones

Reputation: 4246

This is assuming you are using the MessageDispatchServlet.

In your web.xml use the following. The important parts here is the transformWsdlLocation and the wsdlDefinitionHandlerAdapterBeanName. TransformWsdlLocation was recently changed as part of spring ws 2.1.2 to modify schemaLocation as well. https://jira.springsource.org/browse/SWS-791

<servlet>
    <servlet-name>spring-ws</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
       <param-name>wsdlDefinitionHandlerAdapterBeanName</param-name>
       <param-value>myWsdlDefinitionHandlerAdapter</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Next in your spring-ws-servlet.xml config file name a bean called myWsdlDefinitionHandlerAdapter. The value you can pull from a properties file or wherever you need to get it from.

Next is the class MyWsdlDefinitionHandlerAdapter that extends the spring WsdlDefinitionHandlerAdapter. In my example I am changing the wsdl location by modifiying the server location.

public class MyWsdlDefinitionHandlerAdapter extends WsdlDefinitionHandlerAdapter {

private String serverAlias;

@Override
protected String transformLocation(String location, HttpServletRequest request) {
    if(StringUtils.hasText(getServerAlias())){
        StringBuilder url = new StringBuilder(request.getScheme());
        url.append("://").append(getServerAlias());
        if (location.startsWith("/")) {
            // a relative path, prepend the context path
            url.append(request.getContextPath()).append(location);
            return url.toString();
        }
        else {
            int idx = location.indexOf("://");
            if (idx != -1) {
                // a full url
                idx = location.indexOf('/', idx + 3);
                if (idx != -1) {
                    String path = location.substring(idx);
                    url.append(path);
                    return url.toString();
                }
            }
        }
    } else {
        return super.transformLocation(location, request);
    }

    // unknown location, return the original
    return location;
}

public String getServerAlias() {
    return serverAlias;
}

public void setServerAlias(String serverAlias) {
    this.serverAlias = serverAlias;
}
}

Hope this helps.

Upvotes: 0

jddsantaella
jddsantaella

Reputation: 3687

Just define the WSDL file as a resource so Maven will firter it. But property value should be in a Maven profile, not in a property file.

<resource>
    <directory>src/wsdl</directory>
    <filtering>true</filtering>
</resource>

Upvotes: 3

Related Questions