Search in sources :

Example 1 with ClientCallback

use of org.apache.cxf.endpoint.ClientCallback in project cxf by apache.

the class ClientOutFaultObserver method onMessage.

/**
 * override the super class method
 */
public void onMessage(Message m) {
    if (m.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
        // it's outbound fault observer so only take care of outbound fault
        return;
    }
    Exception ex = m.getContent(Exception.class);
    // remove callback so that it won't be invoked twice
    ClientCallback callback = m.getExchange().remove(ClientCallback.class);
    if (callback != null) {
        Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>) m.getExchange().getOutMessage().get(Message.INVOCATION_CONTEXT));
        resCtx = CastUtils.cast((Map<?, ?>) resCtx.get(Client.RESPONSE_CONTEXT));
        callback.handleException(resCtx, ex);
    }
}
Also used : ClientCallback(org.apache.cxf.endpoint.ClientCallback) Map(java.util.Map)

Example 2 with ClientCallback

use of org.apache.cxf.endpoint.ClientCallback in project cxf by apache.

the class JaxWsDynamicClientTest method testInvocation.

@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());
}
Also used : JaxWsDynamicClientFactory(org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory) ClientCallback(org.apache.cxf.endpoint.ClientCallback) Operation1Response(org.apache.cxf.no_body_parts.types.Operation1Response) Operation1(org.apache.cxf.no_body_parts.types.Operation1) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ClientCallback

use of org.apache.cxf.endpoint.ClientCallback in project cxf by apache.

the class DispatchImpl method invokeAsync.

public Future<?> invokeAsync(T obj, AsyncHandler<T> asyncHandler) {
    checkError();
    client.setExecutor(getClient().getEndpoint().getExecutor());
    ClientCallback callback = new JaxwsClientCallback<T>(asyncHandler, this);
    Response<T> ret = new JaxwsResponseCallback<T>(callback);
    try {
        boolean hasOpName;
        QName opName = (QName) getRequestContext().get(MessageContext.WSDL_OPERATION);
        if (opName == null) {
            hasOpName = false;
            opName = INVOKE_QNAME;
        } else {
            hasOpName = true;
            BindingOperationInfo bop = client.getEndpoint().getBinding().getBindingInfo().getOperation(opName);
            if (bop == null) {
                addInvokeOperation(opName, false);
            }
        }
        Holder<T> holder = new Holder<T>(obj);
        opName = calculateOpName(holder, opName, hasOpName);
        client.invokeWrapped(callback, opName, holder.value);
        return ret;
    } catch (Exception ex) {
        throw mapException(ex);
    }
}
Also used : ClientCallback(org.apache.cxf.endpoint.ClientCallback) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Example 4 with ClientCallback

use of org.apache.cxf.endpoint.ClientCallback in project cxf by apache.

the class JaxWsClientProxy method invokeAsync.

@SuppressWarnings("unchecked")
private Object invokeAsync(Method method, 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);
    Response<Object> ret = new JaxwsResponseCallback<Object>(callback);
    client.invoke(callback, oi, params);
    return ret;
}
Also used : ClientCallback(org.apache.cxf.endpoint.ClientCallback) AsyncHandler(javax.xml.ws.AsyncHandler) Endpoint(org.apache.cxf.endpoint.Endpoint)

Aggregations

ClientCallback (org.apache.cxf.endpoint.ClientCallback)4 IOException (java.io.IOException)1 URL (java.net.URL)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 SOAPException (javax.xml.soap.SOAPException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 AsyncHandler (javax.xml.ws.AsyncHandler)1 Holder (javax.xml.ws.Holder)1 WebServiceException (javax.xml.ws.WebServiceException)1 HTTPException (javax.xml.ws.http.HTTPException)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Client (org.apache.cxf.endpoint.Client)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 JaxWsDynamicClientFactory (org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory)1 Operation1 (org.apache.cxf.no_body_parts.types.Operation1)1 Operation1Response (org.apache.cxf.no_body_parts.types.Operation1Response)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 Test (org.junit.Test)1