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