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.transport.mail;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.context.MessageContext;
023: import org.apache.axis2.context.OperationContext;
024: import org.apache.axis2.description.AxisOperation;
025: import org.apache.axis2.description.AxisMessage;
026: import org.apache.axis2.wsdl.WSDLConstants;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: public class SynchronousMailListener {
031:
032: private static Log log = LogFactory
033: .getLog(SynchronousMailListener.class);
034: private boolean complete = false;
035: //To store out going messageconext
036: private MessageContext outMessageContext;
037: private MessageContext inMessageContext;
038:
039: private long timeoutInMilliseconds = -1;
040:
041: public SynchronousMailListener(MessageContext outMessageContext,
042: long timeoutInMilliseconds) {
043: this .outMessageContext = outMessageContext;
044: this .timeoutInMilliseconds = timeoutInMilliseconds;
045: }
046:
047: public void setInMessageContext(MessageContext inMessageContext)
048: throws AxisFault {
049: OperationContext operationContext = outMessageContext
050: .getOperationContext();
051: MessageContext msgCtx = operationContext
052: .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
053: if (msgCtx == null) {
054: inMessageContext.setOperationContext(operationContext);
055: inMessageContext.setServiceContext(outMessageContext
056: .getServiceContext());
057: if (!operationContext.isComplete()) {
058: operationContext.addMessageContext(inMessageContext);
059: }
060: AxisOperation axisOp = operationContext.getAxisOperation();
061: //TODO need to handle fault case as well ,
062: //TODO need to check whether the message contains fault , if so we need to get the fault message
063: AxisMessage inMessage = axisOp
064: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
065: inMessageContext.setAxisMessage(inMessage);
066: inMessageContext.setServerSide(false);
067: } else {
068: msgCtx.setOperationContext(operationContext);
069: msgCtx.setServiceContext(outMessageContext
070: .getServiceContext());
071: AxisOperation axisOp = operationContext.getAxisOperation();
072: AxisMessage inMessage = axisOp
073: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
074: msgCtx.setAxisMessage(inMessage);
075: msgCtx.setTransportIn(inMessageContext.getTransportIn());
076: msgCtx.setTransportOut(inMessageContext.getTransportOut());
077: msgCtx.setServerSide(false);
078: msgCtx
079: .setProperty(
080: org.apache.axis2.transport.mail.Constants.CONTENT_TYPE,
081: inMessageContext
082: .getProperty(org.apache.axis2.transport.mail.Constants.CONTENT_TYPE));
083: msgCtx
084: .setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
085: msgCtx.setEnvelope(inMessageContext.getEnvelope());
086: if (!operationContext.isComplete()) {
087: operationContext.addMessageContext(msgCtx);
088: }
089: }
090: this .inMessageContext = inMessageContext;
091: log
092: .info(" SynchronousMailListener found the required message.");
093: complete = true;
094: }
095:
096: public long getTimeoutInMilliseconds() {
097: return timeoutInMilliseconds;
098: }
099:
100: public void setTimeoutInMilliseconds(long timeoutInMilliseconds) {
101: this .timeoutInMilliseconds = timeoutInMilliseconds;
102: }
103:
104: public boolean isComplete() {
105: return complete;
106: }
107:
108: public MessageContext getInMessageContext() {
109: return inMessageContext;
110: }
111: }
|