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: */package org.apache.cxf.jaxws;
19:
20: import java.lang.reflect.Method;
21: import java.util.HashMap;
22: import java.util.List;
23: import java.util.Map;
24:
25: import javax.xml.ws.handler.MessageContext;
26: import javax.xml.ws.handler.MessageContext.Scope;
27:
28: import org.apache.cxf.common.util.factory.Factory;
29: import org.apache.cxf.helpers.CastUtils;
30: import org.apache.cxf.jaxws.context.WebServiceContextImpl;
31: import org.apache.cxf.jaxws.context.WrappedMessageContext;
32: import org.apache.cxf.jaxws.support.ContextPropertiesMapping;
33: import org.apache.cxf.message.Exchange;
34: import org.apache.cxf.service.invoker.ApplicationScopePolicy;
35: import org.apache.cxf.service.invoker.FactoryInvoker;
36: import org.apache.cxf.service.invoker.ScopePolicy;
37:
38: public class JAXWSMethodInvoker extends FactoryInvoker {
39:
40: public JAXWSMethodInvoker(final Object bean) {
41: super (new Factory() {
42: public Object create() {
43: return bean;
44: }
45: }, ApplicationScopePolicy.instance());
46:
47: }
48:
49: public JAXWSMethodInvoker(Factory factory) {
50: super (factory, ApplicationScopePolicy.instance());
51: }
52:
53: public JAXWSMethodInvoker(Factory factory, ScopePolicy scope) {
54: super (factory, scope);
55: }
56:
57: protected Object invoke(Exchange exchange,
58: final Object serviceObject, Method m, List<Object> params) {
59: // set up the webservice request context
60: MessageContext ctx = ContextPropertiesMapping
61: .createWebServiceContext(exchange);
62:
63: Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>) ctx
64: .get(WrappedMessageContext.SCOPES));
65: Map<String, Object> handlerScopedStuff = new HashMap<String, Object>();
66: if (scopes != null) {
67: for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
68: if (scope.getValue() == Scope.HANDLER) {
69: handlerScopedStuff.put(scope.getKey(), ctx
70: .get(scope.getKey()));
71: }
72: }
73: for (String key : handlerScopedStuff.keySet()) {
74: ctx.remove(key);
75: }
76: }
77:
78: WebServiceContextImpl.setMessageContext(ctx);
79:
80: List<Object> res = CastUtils.cast((List) super .invoke(exchange,
81: serviceObject, m, params));
82:
83: for (Map.Entry<String, Object> key : handlerScopedStuff
84: .entrySet()) {
85: ctx.put(key.getKey(), key.getValue());
86: ctx.setScope(key.getKey(), Scope.HANDLER);
87: }
88:
89: //update the webservice response context
90: ContextPropertiesMapping.updateWebServiceContext(exchange, ctx);
91: //clear the WebServiceContextImpl's ThreadLocal variable
92: WebServiceContextImpl.clear();
93: return res;
94: }
95: }
|