001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.client.async;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.client.async.AsyncResult;
023: import org.apache.axis2.client.async.Callback;
024: import org.apache.axis2.jaxws.core.InvocationContext;
025: import org.apache.axis2.jaxws.core.MessageContext;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: import javax.xml.ws.WebServiceException;
030:
031: public class PollingFuture extends Callback {
032:
033: private static final Log log = LogFactory
034: .getLog(PollingFuture.class);
035:
036: private AsyncResponse response;
037: private InvocationContext invocationCtx;
038:
039: public PollingFuture(InvocationContext ic) {
040: response = ic.getAsyncResponseListener();
041:
042: /*
043: * TODO review. We need to save the invocation context so we can set it on the
044: * response (or fault) context so the FutureCallback has access to the handler list.
045: */
046: invocationCtx = ic;
047: }
048:
049: @Override
050: public void onComplete(AsyncResult result) {
051: boolean debug = log.isDebugEnabled();
052: if (debug) {
053: log
054: .debug("JAX-WS async response listener received the response");
055: }
056:
057: MessageContext responseMsgCtx = null;
058: try {
059: responseMsgCtx = AsyncUtils
060: .createJAXWSMessageContext(result);
061: responseMsgCtx.setInvocationContext(invocationCtx);
062: // make sure request and response contexts share a single parent
063: responseMsgCtx.setMEPContext(invocationCtx
064: .getRequestMessageContext().getMEPContext());
065: } catch (WebServiceException e) {
066: response.onError(e, null);
067: if (debug) {
068: log
069: .debug("An error occured while processing the async response. "
070: + e.getMessage());
071: }
072: }
073:
074: if (response == null) {
075: // TODO: throw an exception
076: }
077:
078: response.onComplete(responseMsgCtx);
079: }
080:
081: @Override
082: public void onError(Exception e) {
083: // If a SOAPFault was returned by the AxisEngine, the AxisFault
084: // that is returned should have a MessageContext with it. Use
085: // this to unmarshall the fault included there.
086: if (e.getClass().isAssignableFrom(AxisFault.class)) {
087: AxisFault fault = (AxisFault) e;
088: MessageContext faultMessageContext = null;
089: try {
090: faultMessageContext = AsyncUtils
091: .createJAXWSMessageContext(fault
092: .getFaultMessageContext());
093: faultMessageContext.setInvocationContext(invocationCtx);
094: // make sure request and response contexts share a single parent
095: faultMessageContext.setMEPContext(invocationCtx
096: .getRequestMessageContext().getMEPContext());
097: } catch (WebServiceException wse) {
098: response.onError(wse, null);
099: }
100:
101: response.onError(e, faultMessageContext);
102: } else {
103: response.onError(e, null);
104: }
105: }
106:
107: }
|