本文整理了Java中org.apache.cxf.endpoint.Client.invoke()
方法的一些代码示例,展示了Client.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Client.invoke()
方法的具体详情如下:
包路径:org.apache.cxf.endpoint.Client
类名称:Client
方法名:invoke
[英]Invokes an operation synchronously
[中]同步调用操作
代码示例来源:origin: stackoverflow.com
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient("http://admin:password@localhost:8080"+
"/services/MyService?wsdl");
Object[] a = client.invoke("test", "");
System.out.println(a);
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
@SuppressWarnings("unchecked")
private Object invokeAsync(Method method, final BindingOperationInfo oi, Object[] params) throws Exception {
client.setExecutor(getClient().getEndpoint().getExecutor());
AsyncHandler<Object> handler;
if (params.length > 0 && params[params.length - 1] instanceof AsyncHandler) {
handler = (AsyncHandler<Object>)params[params.length - 1];
Object[] newParams = new Object[params.length - 1];
for (int i = 0; i < newParams.length; i++) {
newParams[i] = params[i];
}
params = newParams;
} else {
handler = null;
}
ClientCallback callback = new JaxwsClientCallback<Object>(handler, this) {
@Override
protected Throwable mapThrowable(Throwable t) {
if (t instanceof Exception) {
t = mapException(null, oi, (Exception)t);
}
return t;
}
};
Response<Object> ret = new JaxwsResponseCallback<>(callback);
client.invoke(callback, oi, params);
return ret;
}
代码示例来源:origin: apache/cxf
public Object invokeSync(Method method, BindingOperationInfo oi, Object[] params)
throws Exception {
if (client == null) {
throw new IllegalStateException("The client has been closed.");
}
Object[] rawRet = client.invoke(oi, params);
if (rawRet != null && rawRet.length > 0) {
return rawRet[0];
}
return null;
}
public Map<String, Object> getRequestContext() {
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-simple
public Object invokeSync(Method method, BindingOperationInfo oi, Object[] params)
throws Exception {
if (client == null) {
throw new IllegalStateException("The client has been closed.");
}
Object[] rawRet = client.invoke(oi, params);
if (rawRet != null && rawRet.length > 0) {
return rawRet[0];
}
return null;
}
public Map<String, Object> getRequestContext() {
代码示例来源:origin: stackoverflow.com
String methodName = "getSomethingFromMyWebService";
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient(ConsumeTest.class.getClassLoader().getResource("WebService.wsdl.xml"));
Object[] res = client.invoke(methodName,parameter1,parameter2, parameterN);
SomethingObject[] somethingObjectList = (SomethingObject[])res[0];
Class.forName(res.getClass().getName()).isArray();
for(SomethingObject so : somethingObjectList){
// do something!
}
代码示例来源:origin: stackoverflow.com
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("echo.wsdl");
Object[] res = client.invoke("echo", "test echo");
System.out.println("Echo response: " + res[0]);
代码示例来源:origin: stackoverflow.com
// webservice client from remote wsdl
String wsdlURL = "http://localhost:8080/test/test.wsdl"
ClassLoader loader = Thread.currentThread().getContextClassLoader();
DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, loader);
// accessing request object and setter method for count attribute and setting 666 value
Object requestObj = Thread.currentThread().getContextClassLoader().loadClass("pl.kago.stuff.RequestObj").newInstance();
Method setCount = requestObj.getClass().getMethod("setCount", Long.class);
setCount.invoke(requestObj, 666);
// "binding" new result object to webmethod result
Object responseObj = Thread.currentThread().getContextClassLoader() .loadClass("pl.kago.stuff.ResponseObj").newInstance();
responseObj = client.invoke("getCountAction", requestObj);
// getting count value
Method getCount = responseObj .getClass().getMethod("getCount");
Object count = getCount.invoke(responseObj);
代码示例来源:origin: com.github.dactiv/dactiv-common
/**
* 执行web service方法
* <pre>
* 例子:
* Object result = JaxWsProxyFactoryBeanMapper.invoke("http://192.168.0.63:8080/CXF_Server_01/cxf/WebService","method");
* System.out.println(result[0]);
* </pre>
*
* @param wsdlUrl web service地址
* @param operationName 要执行的方法名
* @param params 方法中的参数值
*
* @return Object[]
*
* @throws Exception
*/
public static Object[] invoke(String wsdlUrl, String operationName, Object...params) throws Exception {
return createDynamicClient(wsdlUrl).invoke(operationName, params);
}
代码示例来源:origin: stackoverflow.com
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient("WSDL Location");
AuthorizationPolicy authorization = ((HTTPConduit) client.getConduit()).getAuthorization();
authorization.setUserName(
"user name"
);
authorization.setPassword(
"password"
);
Object[] res = client.invoke(new QName("http://targetNameSpace/", "operationName"), params...);
System.out.println("Echo response: " + res[0]);
代码示例来源:origin: apache/cxf
@Test
public void testDynamicClient() throws Exception {
if (JavaUtils.isJava9Compatible()) {
System.setProperty("org.apache.cxf.common.util.Compiler-fork", "true");
}
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:" + PORT + "/jaxwsAndAegisSports?wsdl&dynamic");
Object r = client.invoke("getAttributeBean")[0];
Method getAddrPlainString = r.getClass().getMethod("getAttrPlainString");
String s = (String)getAddrPlainString.invoke(r);
assertEquals("attrPlain", s);
}
}
代码示例来源:origin: apache/cxf
@Test
public void testDynamicClientExceptions() throws Exception {
if (JavaUtils.isJava9Compatible()) {
System.setProperty("org.apache.cxf.common.util.Compiler-fork", "true");
}
JaxWsDynamicClientFactory dcf =
JaxWsDynamicClientFactory.newInstance();
URL wsdlURL = new URL(ServerMisc.DOCLIT_CODEFIRST_URL + "?wsdl");
Client client = dcf.createClient(wsdlURL);
try {
client.invoke("throwException", -2);
} catch (Exception ex) {
Object o = ex.getClass().getMethod("getFaultInfo").invoke(ex);
assertNotNull(o);
}
try {
client.getRequestContext().put("disable-fault-mapping", true);
client.invoke("throwException", -2);
} catch (SoapFault ex) {
//expected
}
}
代码示例来源:origin: apache/cxf
@Test
public void testArgfiles() throws Exception {
System.setProperty("org.apache.cxf.common.util.Compiler-fork", "true");
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(new URL("http://localhost:"
+ PORT1 + "/ArrayService?wsdl"));
String[] values = new String[] {"foobar", "something" };
List<String> list = Arrays.asList(values);
client.getOutInterceptors().add(new LoggingOutInterceptor());
client.getInInterceptors().add(new LoggingInInterceptor());
client.invoke("init", list);
}
代码示例来源:origin: apache/cxf
@Test
public void testArrayList() throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(new URL("http://localhost:"
+ PORT1 + "/ArrayService?wsdl"));
String[] values = new String[] {"foobar", "something" };
List<String> list = Arrays.asList(values);
client.getOutInterceptors().add(new LoggingOutInterceptor());
client.getInInterceptors().add(new LoggingInInterceptor());
client.invoke("init", list);
}
代码示例来源:origin: org.jbpm/jbpm-workitems-webservice
@Test
public void testExecuteCommand() throws Exception {
Object[] clientObject = Arrays.asList("testResults").toArray();
when(clients.containsKey(anyObject())).thenReturn(true);
when(clients.get(anyObject())).thenReturn(client);
when(client.invoke(anyString(),
any(Object[].class))).thenReturn(clientObject);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Interface",
"someInterface");
workItem.setParameter("Operation",
"someOperation");
when(commandContext.getData(anyString())).thenReturn(workItem);
WebServiceCommand command = new WebServiceCommand();
command.setClients(clients);
ExecutionResults results = command.execute(commandContext);
assertNotNull(results);
assertEquals("testResults",
results.getData("Result"));
}
代码示例来源:origin: apache/cxf
@Test
public void testDynamicClientFactory() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
String wsdlUrl = null;
wsdlUrl = wsdl.toURI().toString();
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdlUrl, serviceName, portName);
updateAddressPort(client, PORT);
client.invoke("greetMe", "test");
Object[] result = client.invoke("sayHi");
assertNotNull("no response received from service", result);
assertEquals("Bonjour", result[0]);
client = dcf.createClient(wsdlUrl, serviceName, portName);
new LoggingFeature().initialize(client, client.getBus());
updateAddressPort(client, PORT);
client.invoke("greetMe", "test");
result = client.invoke("sayHi");
assertNotNull("no response received from service", result);
assertEquals("Bonjour", result[0]);
}
代码示例来源:origin: org.mule.services/mule-service-soap
private Object[] invoke(SoapRequest request, Exchange exchange, MessageDispatcher dispatcher) {
String operation = request.getOperation();
XMLStreamReader xmlBody = getXmlBody(request);
try {
Map<String, Object> ctx = getInvocationContext(request, dispatcher);
return client.invoke(getInvocationOperation(), new Object[] {xmlBody}, ctx, exchange);
} catch (SoapFault sf) {
throw new SoapFaultException(sf.getFaultCode(), sf.getSubCode(), parseExceptionDetail(sf.getDetail()).orElse(null),
sf.getReason(), sf.getNode(), sf.getRole(), sf);
} catch (Fault f) {
if (f.getMessage().contains("COULD_NOT_READ_XML")) {
throw new BadRequestException("Error consuming the operation [" + operation + "], the request body is not a valid XML");
}
throw new SoapFaultException(f.getFaultCode(), parseExceptionDetail(f.getDetail()).orElse(null), f);
} catch (DispatchingException e) {
throw e;
} catch (OperationNotFoundException e) {
String location = wsdlModel.getLocation();
throw new BadRequestException("The provided [" + operation + "] does not exist in the WSDL file [" + location + "]", e);
} catch (Exception e) {
throw new SoapServiceException("Unexpected error while consuming the web service operation [" + operation + "]", e);
}
}
代码示例来源:origin: apache/cxf
@Test
public void testInvocation() throws Exception {
JaxWsDynamicClientFactory dcf =
JaxWsDynamicClientFactory.newInstance();
URL wsdlURL = new URL("http://localhost:" + PORT + "/NoBodyParts/NoBodyPartsService?wsdl");
Client client = dcf.createClient(wsdlURL);
byte[] bucketOfBytes =
IOUtils.readBytesFromStream(getClass().getResourceAsStream("/wsdl/no_body_parts.wsdl"));
Operation1 parameters = new Operation1();
parameters.setOptionString("opt-ion");
parameters.setTargetType("tar-get");
Object[] rparts = client.invoke("operation1", parameters, bucketOfBytes);
Operation1Response r = (Operation1Response)rparts[0];
assertEquals(md5(bucketOfBytes), r.getStatus());
ClientCallback callback = new ClientCallback();
client.invoke(callback, "operation1", parameters, bucketOfBytes);
rparts = callback.get();
r = (Operation1Response)rparts[0];
assertEquals(md5(bucketOfBytes), r.getStatus());
}
代码示例来源:origin: apache/cxf
@Test
public void testCXF4676Partial1() throws Exception {
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:"
+ PORT + "/AddNumbersImplPartial1Service?wsdl", serviceName1, portName1);
updateAddressPort(client, PORT);
Object[] result = client.invoke("addTwoNumbers", 10, 20);
assertNotNull("no response received from service", result);
assertEquals(30, result[0]);
}
代码示例来源:origin: apache/cxf
@Test
public void testCXF4676partial2() throws Exception {
DynamicClientFactory dcf = DynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:"
+ PORT + "/AddNumbersImplPartial2Service?wsdl", serviceName2, portName2);
updateAddressPort(client, PORT);
Object[] result = client.invoke("addTwoNumbers", 10, 20);
assertNotNull("no response received from service", result);
assertEquals(30, result[0]);
}
代码示例来源:origin: apache/cxf
@Test
public void verifyServices() throws Exception {
JaxWsClientFactoryBean cf = new JaxWsClientFactoryBean();
cf.setAddress("local://services/Alger");
cf.setServiceClass(IWebServiceRUs.class);
Client client = cf.create();
String response = (String)client.invoke("consultTheOracle")[0];
assertEquals("All your bases belong to us.", response);
Service service = WebServiceRUs.getService();
assertEquals(JAXBDataBinding.class, service.getDataBinding().getClass());
}
内容来源于网络,如有侵权,请联系作者删除!