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: */package org.apache.geronimo.axis2.ejb;
019:
020: import javax.interceptor.AroundInvoke;
021: import javax.xml.ws.Binding;
022:
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.context.OperationContext;
025: import org.apache.axis2.description.AxisOperation;
026: import org.apache.axis2.description.WSDL2Constants;
027: import org.apache.axis2.engine.AxisEngine;
028: import org.apache.axis2.jaxws.core.InvocationContext;
029: import org.apache.axis2.jaxws.core.InvocationContextFactory;
030: import org.apache.axis2.jaxws.core.MessageContext;
031: import org.apache.axis2.jaxws.message.util.MessageUtils;
032: import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
033: import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004_Constants;
034: import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2006Constants;
035: import org.apache.commons.logging.Log;
036: import org.apache.commons.logging.LogFactory;
037:
038: public class EJBInterceptor {
039:
040: private static final Log LOG = LogFactory
041: .getLog(EJBInterceptor.class);
042:
043: private MessageContext requestMsgCtx;
044: private EJBWebServiceContainer container;
045:
046: public EJBInterceptor(EJBWebServiceContainer container,
047: MessageContext requestCtx) {
048: this .container = container;
049: this .requestMsgCtx = requestCtx;
050: }
051:
052: @AroundInvoke
053: public Object intercept(
054: javax.interceptor.InvocationContext invContext)
055: throws Exception {
056:
057: this .container.injectHandlers();
058:
059: AxisOperation operation = this .requestMsgCtx
060: .getAxisMessageContext().getAxisOperation();
061: String mep = operation.getMessageExchangePattern();
062:
063: EJBEndpointController controller = new EJBEndpointController(
064: invContext);
065:
066: Binding binding = (Binding) this .requestMsgCtx
067: .getAxisMessageContext().getProperty(
068: JAXWSMessageReceiver.PARAM_BINDING);
069: InvocationContext ic = InvocationContextFactory
070: .createInvocationContext(binding);
071: ic.setRequestMessageContext(this .requestMsgCtx);
072:
073: controller.invoke(ic);
074:
075: MessageContext responseMsgCtx = ic.getResponseMessageContext();
076:
077: //If there is a fault it could be Robust In-Only
078: if (!isMepInOnly(mep) || hasFault(responseMsgCtx)) {
079: // If this is a two-way exchange, there should already be a
080: // JAX-WS MessageContext for the response. We need to pull
081: // the Message data out of there and set it on the Axis2
082: // MessageContext.
083: org.apache.axis2.context.MessageContext axisResponseMsgCtx = responseMsgCtx
084: .getAxisMessageContext();
085:
086: MessageUtils.putMessageOnMessageContext(responseMsgCtx
087: .getMessage(), axisResponseMsgCtx);
088:
089: OperationContext opCtx = axisResponseMsgCtx
090: .getOperationContext();
091: opCtx.addMessageContext(axisResponseMsgCtx);
092:
093: // If this is a fault message, we want to throw it as an
094: // exception so that the transport can do the appropriate things
095: if (responseMsgCtx.getMessage().isFault()) {
096: throw new AxisFault(
097: "An error was detected during JAXWS processing",
098: axisResponseMsgCtx);
099: } else {
100: //Create the AxisEngine for the reponse and send it.
101: AxisEngine engine = new AxisEngine(axisResponseMsgCtx
102: .getConfigurationContext());
103: engine.send(axisResponseMsgCtx);
104: }
105: }
106:
107: // TODO: convert response into object?
108: return null;
109: }
110:
111: private boolean hasFault(MessageContext responseMsgCtx) {
112: if (responseMsgCtx == null
113: || responseMsgCtx.getMessage() == null) {
114: return false;
115: }
116: return responseMsgCtx.getMessage().isFault();
117: }
118:
119: private boolean isMepInOnly(String mep) {
120: boolean inOnly = mep
121: .equals(WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY)
122: || mep.equals(WSDL20_2004_Constants.MEP_URI_IN_ONLY)
123: || mep.equals(WSDL2Constants.MEP_URI_IN_ONLY)
124: || mep.equals(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY)
125: || mep
126: .equals(WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY)
127: || mep.equals(WSDL20_2006Constants.MEP_URI_IN_ONLY);
128: return inOnly;
129: }
130:
131: }
|