001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: SoapInOnlyMessageReceiver.java 11798 2008-02-01 03:59:19Z lzheng $
023: */
024: package com.bostechcorp.cbesb.runtime.component.http.server;
025:
026: import javax.jbi.component.ComponentContext;
027: import javax.jbi.messaging.InOnly;
028: import javax.jbi.messaging.NormalizedMessage;
029: import javax.jbi.servicedesc.ServiceEndpoint;
030:
031: import org.apache.axis2.AxisFault;
032: import org.apache.axis2.context.MessageContext;
033: import org.apache.axis2.receivers.AbstractMessageReceiver;
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: import com.bostechcorp.cbesb.common.constant.MetadataConstants;
038: import com.bostechcorp.cbesb.runtime.ccsl.lib.ISoapConsumerMarshaller;
039: import com.bostechcorp.cbesb.runtime.component.http.HttpEndpoint;
040:
041: public class SoapInOnlyMessageReceiver extends AbstractMessageReceiver {
042:
043: protected final transient Log logger = LogFactory
044: .getLog(getClass());
045:
046: protected HttpEndpoint endpoint;
047: protected ISoapConsumerMarshaller marshaller;
048:
049: /**
050: *
051: */
052: public SoapInOnlyMessageReceiver(HttpEndpoint endpoint) {
053: this .endpoint = endpoint;
054: marshaller = endpoint.getSoapConsumerMarshaller();
055: }
056:
057: /* (non-Javadoc)
058: * @see org.apache.axis2.receivers.AbstractMessageReceiver#invokeBusinessLogic(org.apache.axis2.context.MessageContext)
059: */
060: @Override
061: protected void invokeBusinessLogic(MessageContext inMsgContext)
062: throws AxisFault {
063: long startTime = System.currentTimeMillis();
064:
065: try {
066: InOnly me = null;
067: ComponentContext context = endpoint.getServiceUnit()
068: .getComponent().getComponentContext();
069: me = endpoint.getChannel().createExchangeFactory()
070: .createInOnlyExchange();
071: String endpointKey = "{"
072: + endpoint.getService().getNamespaceURI() + "}"
073: + endpoint.getService().getLocalPart() + ":"
074: + endpoint.getEndpoint();
075: me.setProperty(MetadataConstants.SENDER_ENDPOINT_PROPERTY,
076: endpointKey);
077: NormalizedMessage inMsg = me.createMessage();
078: me.setMessage(inMsg, "in");
079: //Call marshaller
080: marshaller.SoapToNormalizedMessage(inMsgContext, inMsg, me,
081: endpoint.getSvcDescHandler(), endpoint
082: .isUsingMTOM(), endpoint.isUsingSwA());
083:
084: logger.debug("Consumer endpoint service="
085: + endpoint.getService() + " endpoint="
086: + endpoint.getEndpoint());
087: ServiceEndpoint linkedEndpoint = context.getEndpoint(
088: endpoint.getService(), endpoint.getEndpoint());
089: logger
090: .debug("Got target endpoint " + linkedEndpoint
091: + " service="
092: + linkedEndpoint.getServiceName()
093: + " endpoint="
094: + linkedEndpoint.getEndpointName());
095:
096: me.setEndpoint(linkedEndpoint);
097: me.setService(endpoint.getService());
098:
099: long timeout;
100: if (endpoint.getTimeout() < 0)
101: timeout = 0; //indefinite
102: else
103: timeout = endpoint.getTimeout();
104:
105: endpoint.getChannel().sendSync(me, timeout);
106: this .endpoint.sendMessageProcessedNotification(System
107: .currentTimeMillis()
108: - startTime);
109:
110: } catch (Exception e) {
111: logger.error("Exception while sending InOnly exchange", e);
112: throw new AxisFault(e.getMessage());
113: }
114: }
115: }
|