01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.server.cxf.pojo;
18:
19: import org.apache.cxf.Bus;
20: import org.apache.cxf.jaxws.JAXWSMethodInvoker;
21: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
22: import org.apache.openejb.InjectionProcessor;
23: import org.apache.openejb.core.webservices.JaxWsUtils;
24: import org.apache.openejb.core.webservices.PortData;
25: import org.apache.openejb.server.cxf.CxfEndpoint;
26: import org.apache.openejb.server.cxf.CxfServiceConfiguration;
27: import org.apache.openejb.server.cxf.JaxWsImplementorInfoImpl;
28:
29: import javax.naming.Context;
30: import javax.xml.ws.WebServiceException;
31:
32: public class PojoEndpoint extends CxfEndpoint {
33: private InjectionProcessor<Object> injectionProcessor;
34:
35: public PojoEndpoint(Bus bus, PortData port, Context context,
36: Class<?> instance) {
37: super (bus, port, context, instance);
38:
39: String bindingURI = null;
40: if (port.getBindingID() != null) {
41: bindingURI = JaxWsUtils.getBindingURI(port.getBindingID());
42: }
43: implInfo = new JaxWsImplementorInfoImpl(instance, bindingURI);
44:
45: serviceFactory = new JaxWsServiceFactoryBean(implInfo);
46: serviceFactory.setBus(bus);
47:
48: // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
49: CxfServiceConfiguration configuration = new CxfServiceConfiguration(
50: port);
51: serviceFactory.getConfigurations().add(0, configuration);
52:
53: service = serviceFactory.create();
54:
55: // instantiate and inject resources into service
56: try {
57: injectionProcessor = new InjectionProcessor<Object>(
58: instance, port.getInjections(), null, null, context);
59: injectionProcessor.createInstance();
60: injectionProcessor.postConstruct();
61: implementor = injectionProcessor.getInstance();
62: } catch (Exception e) {
63: throw new WebServiceException(
64: "Service resource injection failed", e);
65: }
66:
67: service.setInvoker(new JAXWSMethodInvoker(implementor));
68: }
69:
70: protected void init() {
71: // configure and inject handlers
72: try {
73: initHandlers();
74: } catch (Exception e) {
75: throw new WebServiceException("Error configuring handlers",
76: e);
77: }
78: }
79:
80: public void stop() {
81: // call handler preDestroy
82: destroyHandlers();
83:
84: // call service preDestroy
85: if (injectionProcessor != null) {
86: injectionProcessor.preDestroy();
87: }
88:
89: // shutdown server
90: super.stop();
91: }
92: }
|