
今天在服務里啟動OracleOraHome92TNSListener服務時出現“
本地計算機上的OracleOraHome92TNSListener服務啟動后又停止了,一些服務自動停止,如果它們沒有什么可做的,例如"性能日志和警報服務"。因為前兩天更改了計算機名,于是打Net Manager重新設定之后,就OK啦。
instantclient-basic-win32-10.1.0.2.zip 這是最核心的包
instantclient-jdbc-win32-10.1.0.2.zip 包含JDBC Driver的包
instantclient-sqlplus-win32-10.1.0.2.zip 最簡單的SQLPLUS包
下載之后,解壓到一個單獨的目錄里,如:D:\dev\oraclient
2、配置tnsnames.ora,如果本機上沒有安裝oracle,可以從安裝了oracle的機上拷貝一個(tnsnames.ora文件在%ORACLE_HOME%\network\admin下)放在上面的目錄D:\dev\oraclient下。
oracledata =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.58)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = oracledata)
)
)
3、添加一個環境變量,名為TNS_ADMIN,值為tnsnames.ora文件所在路徑(如:D:\dev\oraclient),這是為了能夠找到上面說的tnsnames.ora。如果本機上安裝了ORACLE,并且設置了ORACLE_HOME環境變量,那么會自動在%ORACLE_HOME%/network/admin/位置查找tnsnames.ora文件。
4、設置ORACLE的語言,添加注冊表項:“NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK”,位于 HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE。如果本機沒有安裝ORACLE,在H_L_M\SOFTWARE\下是沒有"ORACLE"這一項的,需要手動創建,然后再在ORACLE項下創建鍵NLS_LANG,鍵值為:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
5、下載并安裝PL.SQL.Developer配置應用
配置tools->preferences->connection
Oracle Home=D:\dev\oracleclient
OCI library=D:\dev\oracleclient\oci.dll
6、再次打開plsql則會在database中有oracledata 選項輸入用戶名密碼就可以登陸。
XFire開發Web服務的基本步驟
1) 檢驗JAVA類的方法和構造函數是否是公共的,一定要是公開的。
2) 將XFire Servlet相關的入口添加到web.xml中。
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
3) 創建services.xml并把它放到WEB-INF/classes/META-INF/xfire目錄下,這是默認的做法;也可以將services.xml的路徑配置到web.xml文件中。
<servlet-name>XFire</servlet-name>
<display-name>XFire Servlet</display-name>
<servlet-class>
org.codehaus.xfire.transport.http.XFireConfigurableServlet
</servlet-class>
<!--
The servlet will by default look for the configuration on
the classpath in "META-INF/xfire/services.xml". You can
override it with this parameter. Seperate multiple configuration files with a comma.
-->
<!-- 默認會在classpath的META-INF/xfire/下查找services.xml文件,
可以覆蓋這個參數,指定多個配置文件-->
<init-param>
<param-name>config</param-name>
<param-value>services.xml</param-value>
</init-param>
</servlet>
4) 將XFire和其它第三方庫添加到Web應用的WEB-INF/lib目錄下。
FAQ
1) Weblogic8.1中應用XFire,啟動wls時,出現java.lang.NoSuchMethodError的解決辦法。
首先,將XFire提供的QName JAR(qname.jar)放進WEB-INF/lib目錄下。然后,將weblogic.xml文件放到WEB-INF下。
weblogic.xml的內容為:
"-//BEA Systems, Inc.//DTD Web Application 8.1//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">
<weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
具體的詳細解說,請看XFire的User's Guide.
技巧
1. 如果Web Services的方法的參數是Collections,那就需要建一個Mapping文件,而且Mapping文件的命名為className.aegis.xml,并且與class放在同一個package下。
如:
public interface IConstraceSerice {
boolean editConstraceInfo(List aList);
}
Mapping文件如下:IConstraceService.aegis.xml
<?xml version="1.0" encoding="utf-8"?>
<mappings>
<mapping>
<method name="editConstraceInfo">
<parameter index="0" componentType="java.lang.String"/>
</method>
</mapping>
</mappings>
<parameter index="0" componentType="java.lang.String"/>表示第一個參數,里面實際值的類型,這里實際值的類型是java.lang.String.
如果是一個JavaBean,如com.test.TestBean,那以就要寫成<parameter index="0" compentType="com.test.TestBean"/>
2. 如果返回類型是List或Map,并且里面存放的是自定義類的話,則需要增加一個對于服務接口的配置文件。該文件的命名規則是 接口文件名.aegis.xml。例如接口是UserService.java的話,則此配置文件命名為UserService.aegis.xml。注意此配置文件須與接口放在同一目錄下面。
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping >
<method name="getUsers">
<return-type componentType="com.test.domain.User"/>
</method>
</mapping>
</mappings>
getUsers方法返回類型是List,里面裝的User對象。對于這種類型的方法,在配置文件中描述了它的返回值類型。
如果返回的類型是Map的話,做法和List一樣。但定義的類型,是Map中的Value部分,并且這樣的話,Map中Value所存放的對象就必須全部是同一種類啦。
下面給出一個詳細的例子:
1)服務接口:
public interface MyService2
{
boolean getInfo();
Collection getCollection(); //method 1
Collection getCollection(int id); //method 2
Collection getCollection(String id); //method 3
Collection getCollectionForValues(String id, Collection c); //method 4
Collection getCollectionForValues(int value, Collection c); //method 5
}
2) Mapping文件內容:
<mappings>
<mapping>
<!-- mapping 1 -->
<method name="getCollection">
<return-type componentType="java.lang.Double"/>
</method>
<!-- mapping 2 -->
<method name="getCollection">
<return-type componentType="java.lang.Float"/>
<parameter index="0" class="int"/>
</method>
<!-- mapping 3 -->
<method name="getCollectionForValues">
<return-type componentType="java.math.BigDecimal"/>
</method>
<!-- mapping 4 -->
<method name="getCollectionForValues">
<parameter index="0" class="java.lang.String"/>
<parameter index="1" componentType="java.util.Date"/>
</method>
<!-- mapping 5 -->
<method name="getCollectionForValues">
<return-type componentType="java.util.Calendar"/>
<parameter index="0" class="int"/>
<parameter index="1" componentType="java.lang.Bit"/>
</method>
</mapping>
</mappings>
3. 如果一個方法的返回類型是一個JavaBean,而這個JavaBean當中又存在Collections,那么就需要定義一個與JavaBean相關的Mapping文件,文件名要與JavaBean名相同,如:User.aegis.xmll,并且與JavaBean放在同一個目錄.
例子:
1) 服務接口
public interface IYMServiceFacade {
User getUser();
}
2) JavaBean
public class User {
private Strirng userName;
// 這里是一個Collection
private Set rooms;
.....
.....
}
3) Mapping文件(User.aegis.xml)
<?xml version="1.0" encoding="utf-8"?>
<mappings>
<mapping>
<property name="rooms" componentType="com.powerunion.ymservice.dto.Room"/>
</mapping>
</mappings>
介紹:<property name="rooms" componentType="com.powerunion.ymservice.dto.Room"/>
其中的name屬性就是JavaBean里面定義的rooms,componentType上面的相同,表示Collections里真正存儲的類型.
注:如果服務接口的參數或者返因類型是基本類型(int, float, double等)就不需要創建Mapping文件。
詳細的信息見XFire的User's Guide.
4.如果Web Services和客戶端運行在同一個JVM上,可以選擇使用本地傳輸,可以大幅提升性能。如:以下指定服務端URL的這行。
String serviceUrl = "http://localhost:8080/YM/services/ContractService";
替換為
String serviceUrl = "xfire.local://ContractService";
5. 用ant task 生成xfire 客戶端代碼
用xfire不管是配置web service,還是生成客戶代碼都很方便.
生成客戶代碼只要在用ant生成就可以了!
build.xml
代碼
<?xml version="1.0"?>
<project default="genfiles" basedir=".">
<property name="lib" value="WebRoot/WEB-INF/lib" />
<path id="myclasspath">
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
<pathelement location="${genfiles}" />
</path>
<property name="code_path" value="src" />
<property name="wsdl_path" value="Echo1Service.xml" />
<property name="code_package" value="com.client" />
<target name="genfiles" description="Generate the files">
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="myclasspath" />
<wsgen outputDirectory="${code_path}" wsdl="${wsdl_path}" package="${code_package}" binding="xmlbeans" />
</target>
</project>