當前位置:首頁 » 操作系統 » cxf源碼

cxf源碼

發布時間: 2025-07-09 18:49:19

『壹』 Mule ESB使用了中文,則返回亂碼,怎麼解決

解決這個問題有兩種方案:
1. 改變jvm的默認字元編碼。
2. 修改CxfInboundMessageProcessor類的源代碼。
第一種方案通過修改伺服器的啟動參數,追加一段「-Dfile.encoding=UTF-8」,就可以改變伺服器的java運行環境。
此時啟動伺服器時會發現,雖然WSDL中文不再出現亂碼了,但是伺服器控制台顯示的中文 卻全都成了亂碼 。wsdl 是否出現亂碼依賴於運行伺服器的默認字元集,對於OECP平台來說是不可控的。OECP平台使用什麼樣的字元編碼應該依賴於應用自己的配置。
修改mule 的源代碼,CxfInboundMessageProcessor這個類,在升級的過程中沒有改動,不然就要反編譯來獲取源碼了。
將201行的msg = out.toString();修改為如下代碼:
java 代碼
String enc = event.getMuleContext().getConfiguration().getDefaultEncoding(); msg = out.toString(enc);

從mule 的配置中得到配置的編碼格式,並在將Stream轉換為String的時候指定使用此編碼格式.至此問題解決了.

『貳』 java調用webservice例子

現在大多數項目都會用到spring,所以選擇 CXF 框架,cxf能很好的和spring結合


在官網下載最新版 xcf 3.0.3 網站 http://cxf.apache.org/


MyEclipse項目結構圖


結構圖中各個文件源碼

HelloWorldImpl.java

---------

import javax.jws.WebService;


@WebService(endpointInterface = "IHelloWorld", serviceName = "HelloWorld")

public class HelloWorldImpl implements IHelloWorld {

@Override

public String sayHello(String text) {

return "serviceSay: " + text;

}

}

------------------------------------------------------------------------------------------------



IHelloWorld.java

---------

import javax.jws.WebService;


@WebService

public interface IHelloWorld {

public String sayHello(String text);

}

------------------------------------------------------------------------------------------------


Test.java

---------

import org.apache.cxf.endpoint.Client;

import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;


public class Test {

public static void main(String[] args) throws Exception {

DynamicClientFactory dcf = DynamicClientFactory.newInstance();

Client c = dcf.createClient("http://localhost:8080/cxf/ws/hwUrl?wsdl");

Object[] param = new Object[] { "----test....." };

Object[] result = c.invoke("sayHello", param);

System.out.println(result[0].toString());

}


}

------------------------------------------------------------------------------------------------



cxf-servlet.xml

-----------------

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"

xmlns:soap="http://cxf.apache.org/bindings/soap"

xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:server id="hwService" serviceClass="IHelloWorld"

address="/hwUrl">

<jaxws:serviceBean>

<bean class="HelloWorldImpl" />

</jaxws:serviceBean>

</jaxws:server>

</beans>

------------------------------------------------------------------------------------------------


web.xml

---------

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<display-name></display-name>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

<servlet>

<servlet-name>cxfS</servlet-name>

<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>cxfS</servlet-name>

<url-pattern>/ws/*</url-pattern>

</servlet-mapping>

</web-app>

------------------------------------------------------------------------------------------------



部署項目,然後運行Test.java

在瀏覽器裡面輸入http://localhost:8080/cxf/ws/hwUrl?wsdl 可查看webservice服務介面信息

『叄』 記一次生產系統每隔10小時(36000000毫秒)固定進行一次Full GC排查思路

在生產環境中,應用每10小時固定觸發一次Full GC操作。然而,系統監控數據顯示,應用業務量不大且常規情況下不應觸發Full GC,直覺告訴我這可能由定時任務引起,但未發現相關業務代碼。

深入排查後,注意到Java中的`Daemon`類,發現其繼承自`Thread`類並調用`System.gc()`方法。通過測試環境驗證,應用中確有名為`GC Daemon`的守護線程在運行。

源碼解析顯示,`LogUtils`類載入時,通過靜態代碼塊調用`JDKBugHacks.doHacks()`方法。此方法根據`org.apache.cxf.JDKBugHacks.gcRequestLatency`系統環境變數,決定是否執行`sun.misc.GC.requestLatency`方法。初始化時,若未設置該變數,默認執行邏輯,創建`GC Daemon`守護線程。

為解決固定Full GC問題,需在項目啟動腳本中添加代碼跳過創建守護線程的邏輯,避免不必要的Full GC觸發,提升應用性能。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:585
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:881
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:574
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:761
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:677
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1005
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:250
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:108
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:799
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:705