Import org. apache. cxf. endpoint. Client;
Import org. apache. cxf. jaxws. JaxWsProxyFactoryBean;
Import org. apache. cxf. jaxws. endpoint. dynamic. JaxWsDynamicClientFactory;
Import org. springframework. core. io. ClassPathResource;
Import org. springframework. core. io. Resource;
/**
* <P>
* Title: WebServiceClientHelper. java
* </P>
* <P>
* Description:
* </P>
* <P>
* Copyright: Copyright (c) 2009-2011
* </P>
* <P>
* Company:
* </P>
*
* @ Author erdp
* @ Date 2011-8-7
* @ Version 1.0
*/
Public class WebServiceClientHelper {
/**
* Webservice public interface class
*
* @ Param url: webservice remote address
*
* @ Param cls Interface Parameters
*
* @ Return
*/
Public static <T> T getService (String url, Class <T> cls ){
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean ();
Factory. setServiceClass (cls );
Factory. setAddress (url );
@ SuppressWarnings ("unchecked ")
T service = (T) factory. create ();
Return service;
}
Public static String callService (String wsMethod, Object [] objArr) throws Exception {
Resource resource = new ClassPathResource (Constants. NC_WEBSERVICE_URL );
Org. codehaus. xfire. client. Client client = new org. codehaus. xfire. client. Client (resource. getInputStream (), null );
Object [] results = client. invoke (wsMethod, objArr );
System. out. println (String) results [0]);
Return (String) results [0];
}
/**
*
* @ Param wsUrl
* @ Param method
* @ Param arg
* @ Return
*/
Public static String callService (String wsUrl, String method, Object arg ){
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory. newInstance ();
Client client = dcf. createClient (wsUrl );
Object [] res = null;
Try {
Res = client. invoke (method, arg );
Client. destroy ();
System. out. println (String) res [0]);
} Catch (Exception e ){
E. printStackTrace ();
}
Return (String) res [0];
}
}
Author: ERDP Technical Architecture"