2012-12-12 60 views
3

我有WSDL文件下的src/WSDL,我不知道它是否可以讀取該WSDL文件中的屬性文件值如下:如何從wsdl文件內的屬性文件讀取?

<?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> 

我已經PropertyPlaceholderConfigurer中的applicationContext定義如下:

<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> 

當我試圖編譯我得到了在WSDL文件中的錯誤應用:

[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 

請告知如何完成,謝謝。

+0

您不應該這樣做。你能給更多的上下文嗎? – gpeche

回答

3

只需將WSDL文件定義爲一個資源,Maven就會使它更加生動。但屬性值應該在Maven配置文件中,而不是屬性文件中。

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

您確定Maven正在過濾WSDL文件?在目標文件夾中應該是其中'$ {wsdl.url}'被POM文件中的值替換的WSDL。 – jddsantaella

+0

@MahmoudSaleh這個建議應該有效。但是請注意,這是編譯時間的變化,而不是像Spring conf那樣的運行時/部署時間。 – eis

0

這假定您正在使用MessageDispatchServlet。

在你的web.xml中使用以下內容。這裏的重要部分是transformWsdlLocation和wsdlDefinitionHandlerAdapterBeanName。最近,TransformWsdlLocation作爲spring 2.1.2的一部分進行了修改,以便修改schemaLocation。 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> 

下一頁在Spring-WS-servlet.xml中的配置文件命名叫myWsdlDefinitionHandlerAdapter豆。您可以從屬性文件中獲取的值或需要從中獲取的值。

接下來是類MyWsdlDefinitionHandlerAdapter延伸彈簧WsdlDefinitionHandlerAdapter。在我的示例中,我通過修改服務器位置來更改wsdl位置。

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; 
} 
} 

希望這會有所幫助。

0

您必須啓用篩選廣告戰插件:

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

之後,您可能需要更新您的Maven項目配置。

enter image description here