?
- 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; ?
- ?
-
?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
-
public?class?WebServiceClientHelper?{? ?
- ?
-
?????
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ?
-
????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]; ?
- ????} ?
- ?
-
?????
- ?
- ?
- ?
- ?
- ?
- ?
-
????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]; ?
- ????} ?
- }?