Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 26305 invoked from network); 21 Feb 2011 12:26:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Feb 2011 12:26:40 -0000 Received: (qmail 32467 invoked by uid 500); 21 Feb 2011 12:26:40 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 32357 invoked by uid 500); 21 Feb 2011 12:26:37 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 32350 invoked by uid 99); 21 Feb 2011 12:26:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Feb 2011 12:26:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Feb 2011 12:26:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 959F62388A40; Mon, 21 Feb 2011 12:26:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1072945 - /cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Date: Mon, 21 Feb 2011 12:26:15 -0000 To: commits@cxf.apache.org From: cschneider@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110221122615.959F62388A40@eris.apache.org> Author: cschneider Date: Mon Feb 21 12:26:15 2011 New Revision: 1072945 URL: http://svn.apache.org/viewvc?rev=1072945&view=rev Log: extract sync and async implementation to one doInvoke as both were almost identical Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=1072945&r1=1072944&r2=1072945&view=diff ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Mon Feb 21 12:26:15 2011 @@ -394,159 +394,129 @@ public class ClientImpl Exchange exchange) throws Exception { invoke(callback, oi, params, null, exchange); } - - @SuppressWarnings("unchecked") + public void invoke(ClientCallback callback, BindingOperationInfo oi, Object[] params, Map context, Exchange exchange) throws Exception { - Bus origBus = BusFactory.getThreadDefaultBus(false); - BusFactory.setThreadDefaultBus(bus); - try { - if (exchange == null) { - exchange = new ExchangeImpl(); - } - exchange.setSynchronous(false); - Endpoint endpoint = getEndpoint(); - if (context == null) { - context = new HashMap(); - Map resp = new HashMap(); - resp.clear(); - Map reqContext = new HashMap(getRequestContext()); - context.put(RESPONSE_CONTEXT, resp); - context.put(REQUEST_CONTEXT, reqContext); - } - - Map reqContext = (Map)context.get(REQUEST_CONTEXT); - - Message message = endpoint.getBinding().createMessage(); - message.put(Message.INVOCATION_CONTEXT, context); - - //setup the message context - setContext(reqContext, message); - setParameters(params, message); - - if (null != reqContext) { - exchange.putAll(reqContext); - } - exchange.setOneWay(oi.getOutput() == null); - exchange.setOutMessage(message); - exchange.put(ClientCallback.class, callback); - - setOutMessageProperties(message, oi); - setExchangeProperties(exchange, endpoint, oi); - - // setup chain - - PhaseInterceptorChain chain = setupInterceptorChain(endpoint); - message.setInterceptorChain(chain); - - chain.setFaultObserver(outFaultObserver); - - // setup conduit selector - prepareConduitSelector(message); - - // add additional interceptors and such - modifyChain(chain, message, false); - - // execute chain - chain.doIntercept(message); - - } finally { - BusFactory.setThreadDefaultBus(origBus); - } + doInvoke(callback, oi, params, context, exchange); } public Object[] invoke(BindingOperationInfo oi, Object[] params, Map context, Exchange exchange) throws Exception { + return doInvoke(null, oi, params, context, exchange); + } + + private Object[] doInvoke(ClientCallback callback, + BindingOperationInfo oi, + Object[] params, + Map context, + Exchange exchange) throws Exception { Bus origBus = BusFactory.getThreadDefaultBus(false); BusFactory.setThreadDefaultBus(bus); try { if (exchange == null) { exchange = new ExchangeImpl(); } - exchange.setSynchronous(true); + exchange.setSynchronous(callback == null); Endpoint endpoint = getEndpoint(); - - Map reqContext = null; - Map resContext = null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params)); } Message message = endpoint.getBinding().createMessage(); - if (null != context) { - reqContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT)); - resContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT)); - message.put(Message.INVOCATION_CONTEXT, context); + + // Make sure INVOCATION CONTEXT, REQUEST_CONTEXT and RESPONSE_CONTEXT are present + // on message + Map reqContext = null; + Map resContext = null; + if (context == null) { + context = new HashMap(); + } + reqContext = CastUtils.cast((Map)context.get(REQUEST_CONTEXT)); + resContext = CastUtils.cast((Map)context.get(RESPONSE_CONTEXT)); + if (reqContext == null) { + reqContext = new HashMap(getRequestContext()); + context.put(REQUEST_CONTEXT, reqContext); } - //setup the message context + if (resContext == null) { + resContext = new HashMap(); + context.put(RESPONSE_CONTEXT, resContext); + } + + message.put(Message.INVOCATION_CONTEXT, context); setContext(reqContext, message); - setParameters(params, message); - if (null != reqContext) { exchange.putAll(reqContext); } + + setParameters(params, message); if (null != oi) { exchange.setOneWay(oi.getOutput() == null); } exchange.setOutMessage(message); - + exchange.put(ClientCallback.class, callback); + setOutMessageProperties(message, oi); setExchangeProperties(exchange, endpoint, oi); - // setup chain - PhaseInterceptorChain chain = setupInterceptorChain(endpoint); message.setInterceptorChain(chain); - chain.setFaultObserver(outFaultObserver); - - // setup conduit selector prepareConduitSelector(message); // add additional interceptors and such modifyChain(chain, message, false); try { - // execute chain chain.doIntercept(message); } catch (Fault fault) { - if (fault.getCause().getCause() instanceof IOException - || fault.getCause() instanceof IOException) { - String soap11NS = "http://schemas.xmlsoap.org/soap/envelope/"; - String soap12NS = "http://www.w3.org/2003/05/soap-envelope"; - QName faultCode = fault.getFaultCode(); - //for SoapFault, if it's underlying cause is IOException, - //it means something like server is down or can't create - //connection, according to soap spec we should set fault as - //Server Fault - if (faultCode.getNamespaceURI().equals( - soap11NS) - && faultCode.getLocalPart().equals("Client")) { - faultCode = new QName(soap11NS, "Server"); - fault.setFaultCode(faultCode); - } - if (faultCode.getNamespaceURI().equals( - soap12NS) - && faultCode.getLocalPart().equals("Sender")) { - faultCode = new QName(soap12NS, "Receiver"); - fault.setFaultCode(faultCode); - } - } + enrichFault(fault); throw fault; } - - return processResult(message, exchange, oi, resContext); - + + if (callback != null) { + return null; + } else { + return processResult(message, exchange, oi, resContext); + } } finally { BusFactory.setThreadDefaultBus(origBus); } } + /** + * TODO This is SOAP specific code and should not be in cxf core + * @param fault + */ + private void enrichFault(Fault fault) { + if (fault.getCause().getCause() instanceof IOException + || fault.getCause() instanceof IOException) { + String soap11NS = "http://schemas.xmlsoap.org/soap/envelope/"; + String soap12NS = "http://www.w3.org/2003/05/soap-envelope"; + QName faultCode = fault.getFaultCode(); + //for SoapFault, if it's underlying cause is IOException, + //it means something like server is down or can't create + //connection, according to soap spec we should set fault as + //Server Fault + if (faultCode.getNamespaceURI().equals( + soap11NS) + && faultCode.getLocalPart().equals("Client")) { + faultCode = new QName(soap11NS, "Server"); + fault.setFaultCode(faultCode); + } + if (faultCode.getNamespaceURI().equals( + soap12NS) + && faultCode.getLocalPart().equals("Sender")) { + faultCode = new QName(soap12NS, "Receiver"); + fault.setFaultCode(faultCode); + } + } + } + protected Object[] processResult(Message message, Exchange exchange, BindingOperationInfo oi,