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:
020: package org.apache.axis2.transport.local;
021:
022: import org.apache.axiom.om.OMXMLParserWrapper;
023: import org.apache.axiom.soap.SOAPEnvelope;
024: import org.apache.axis2.AxisFault;
025: import org.apache.axis2.Constants;
026: import org.apache.axis2.util.Utils;
027: import org.apache.axis2.util.MessageContextBuilder;
028: import org.apache.axis2.addressing.EndpointReference;
029: import org.apache.axis2.builder.BuilderUtil;
030: import org.apache.axis2.context.ConfigurationContext;
031: import org.apache.axis2.context.MessageContext;
032: import org.apache.axis2.description.TransportInDescription;
033: import org.apache.axis2.description.TransportOutDescription;
034: import org.apache.axis2.engine.AxisEngine;
035:
036: import javax.xml.stream.FactoryConfigurationError;
037: import javax.xml.stream.XMLStreamException;
038: import java.io.InputStream;
039: import java.io.InputStreamReader;
040:
041: public class LocalTransportReceiver {
042: public static ConfigurationContext CONFIG_CONTEXT;
043: private ConfigurationContext confContext;
044: private LocalTransportSender sender;
045:
046: public LocalTransportReceiver(ConfigurationContext configContext) {
047: confContext = configContext;
048: }
049:
050: public LocalTransportReceiver(LocalTransportSender sender) {
051: this (CONFIG_CONTEXT);
052: this .sender = sender;
053: }
054:
055: public void processMessage(InputStream in, EndpointReference to,
056: String action) throws AxisFault {
057: MessageContext msgCtx = confContext.createMessageContext();
058: TransportInDescription tIn = confContext.getAxisConfiguration()
059: .getTransportIn(Constants.TRANSPORT_LOCAL);
060: TransportOutDescription tOut = confContext
061: .getAxisConfiguration().getTransportOut(
062: Constants.TRANSPORT_LOCAL);
063: try {
064:
065: tOut.setSender(new LocalResponder(sender));
066:
067: msgCtx.setTransportIn(tIn);
068: msgCtx.setTransportOut(tOut);
069: msgCtx.setProperty(MessageContext.TRANSPORT_OUT, sender
070: .getResponse());
071:
072: msgCtx.setTo(to);
073: msgCtx.setWSAAction(action);
074: msgCtx.setServerSide(true);
075:
076: InputStreamReader streamReader = new InputStreamReader(in);
077: OMXMLParserWrapper builder;
078: try {
079: builder = BuilderUtil.getBuilder(streamReader);
080: } catch (XMLStreamException e) {
081: throw AxisFault.makeFault(e);
082: }
083: SOAPEnvelope envelope = (SOAPEnvelope) builder
084: .getDocumentElement();
085:
086: msgCtx.setEnvelope(envelope);
087:
088: AxisEngine.receive(msgCtx);
089: } catch (AxisFault e) {
090: // write the fault back.
091: try {
092: MessageContext faultContext = MessageContextBuilder
093: .createFaultMessageContext(msgCtx, e);
094:
095: faultContext.setTransportOut(tOut);
096: faultContext.setProperty(MessageContext.TRANSPORT_OUT,
097: sender.getResponse());
098:
099: AxisEngine.sendFault(faultContext);
100: } catch (AxisFault axisFault) {
101: // can't handle this, so just throw it
102: throw axisFault;
103: }
104: }
105: }
106: }
|