01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.core.util;
20:
21: import org.apache.axis2.AxisFault;
22: import org.apache.axis2.jaxws.ExceptionFactory;
23: import org.apache.axis2.jaxws.core.MessageContext;
24: import org.apache.axis2.util.MessageContextBuilder;
25:
26: /** A utility class for handling some of the common issues related to the JAX-WS MessageContext. */
27: public class MessageContextUtils {
28:
29: /**
30: * Given a request MessageContext, create a new MessageContext from there with the necessary
31: * information to make sure the new MessageContext is related to the existing one.
32: *
33: * @param mc - the MessageContext to use as the source
34: * @return
35: */
36: public static MessageContext createResponseMessageContext(
37: MessageContext mc) {
38: try {
39: org.apache.axis2.context.MessageContext sourceAxisMC = mc
40: .getAxisMessageContext();
41:
42: // There are a number of things that need to be copied over at the
43: // Axis2 level.
44: org.apache.axis2.context.MessageContext newAxisMC = MessageContextBuilder
45: .createOutMessageContext(sourceAxisMC);
46:
47: MessageContext newMC = new MessageContext(newAxisMC);
48: newMC.setOutbound(true);
49: newMC.setMEPContext(mc.getMEPContext());
50: newMC.setEndpointDescription(mc.getEndpointDescription());
51: newMC.setOperationDescription(mc.getOperationDescription());
52: return newMC;
53: } catch (AxisFault e) {
54: throw ExceptionFactory.makeWebServiceException(e);
55: }
56: }
57:
58: /*
59: * special messagecontext that has no AxisContext associated with it. Typically, this
60: * would be used in a "client outbound handler throws exception" case since that would
61: * mean we never hit the InvocationController and thus never hit the Axis layer.
62: */
63: public static MessageContext createMinimalResponseMessageContext(
64: MessageContext mc) {
65: org.apache.axis2.context.MessageContext sourceAxisMC = mc
66: .getAxisMessageContext();
67: MessageContext newMC = new MessageContext(sourceAxisMC);
68: newMC.setMEPContext(mc.getMEPContext());
69: newMC.setEndpointDescription(mc.getEndpointDescription());
70: newMC.setOperationDescription(mc.getOperationDescription());
71: return newMC;
72: }
73:
74: /**
75: * Given a request MessageContext, create a new MessageContext for a fault response.
76: *
77: * @param mc
78: * @return
79: */
80: public static MessageContext createFaultMessageContext(
81: MessageContext mc) {
82: try {
83: org.apache.axis2.context.MessageContext faultMC = MessageContextBuilder
84: .createFaultMessageContext(mc
85: .getAxisMessageContext(), null);
86: MessageContext jaxwsFaultMC = new MessageContext(faultMC);
87: jaxwsFaultMC.setOutbound(true);
88: jaxwsFaultMC.setMEPContext(mc.getMEPContext());
89: jaxwsFaultMC.setEndpointDescription(mc
90: .getEndpointDescription());
91: jaxwsFaultMC.setOperationDescription(mc
92: .getOperationDescription());
93: return jaxwsFaultMC;
94: } catch (AxisFault e) {
95: throw ExceptionFactory.makeWebServiceException(e);
96: }
97: }
98:
99: }
|