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.cxf.pojo;
019:
020: import java.net.URL;
021:
022: import javax.naming.Context;
023: import javax.xml.ws.WebServiceException;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.cxf.Bus;
028: import org.apache.cxf.jaxws.JAXWSMethodInvoker;
029: import org.apache.cxf.jaxws.context.WebServiceContextImpl;
030: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
031: import org.apache.geronimo.cxf.CXFEndpoint;
032: import org.apache.geronimo.cxf.CXFServiceConfiguration;
033: import org.apache.geronimo.cxf.GeronimoJaxWsImplementorInfo;
034: import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
035: import org.apache.geronimo.jaxws.JNDIResolver;
036: import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
037:
038: public class POJOEndpoint extends CXFEndpoint {
039:
040: private static final Log LOG = LogFactory
041: .getLog(POJOEndpoint.class);
042:
043: private AnnotationHolder holder;
044:
045: public POJOEndpoint(Bus bus, URL configurationBaseUrl,
046: Class instance) {
047: super (bus, instance);
048:
049: implInfo = new GeronimoJaxWsImplementorInfo(instance,
050: this .portInfo, instance.getClassLoader());
051:
052: serviceFactory = new JaxWsServiceFactoryBean(implInfo);
053: serviceFactory.setBus(bus);
054:
055: String wsdlLocation = null;
056: if (this .portInfo.getWsdlFile() != null) {
057: wsdlLocation = this .portInfo.getWsdlFile();
058: } else {
059: wsdlLocation = implInfo.getWsdlLocation();
060: }
061: URL wsdlURL = getWsdlURL(configurationBaseUrl, wsdlLocation);
062:
063: // install as first to overwrite annotations (wsdl-file, wsdl-port, wsdl-service)
064: CXFServiceConfiguration configuration = new CXFServiceConfiguration(
065: this .portInfo, wsdlURL);
066: serviceFactory.getConfigurations().add(0, configuration);
067:
068: service = serviceFactory.create();
069:
070: this .holder = bus.getExtension(AnnotationHolder.class);
071:
072: Context context = bus.getExtension(Context.class);
073:
074: // instantiate and inject resources into service
075: try {
076: this .implementor = this .holder.newInstance(instance
077: .getName(), instance.getClassLoader(), context);
078: } catch (Exception e) {
079: throw new WebServiceException(
080: "Service resource injection failed", e);
081: }
082:
083: service.setInvoker(new JAXWSMethodInvoker(this .implementor));
084:
085: JNDIResolver jndiResolver = (JNDIResolver) bus
086: .getExtension(JNDIResolver.class);
087: this .annotationProcessor = new JAXWSAnnotationProcessor(
088: jndiResolver, new WebServiceContextImpl());
089: }
090:
091: protected void init() {
092: // configure and inject handlers
093: try {
094: initHandlers();
095: injectHandlers();
096: } catch (Exception e) {
097: throw new WebServiceException("Error configuring handlers",
098: e);
099: }
100: }
101:
102: public void stop() {
103: // call handler preDestroy
104: destroyHandlers();
105:
106: // call service preDestroy
107: if (this .implementor != null) {
108: try {
109: this .holder.destroyInstance(this .implementor);
110: } catch (Exception e) {
111: LOG.warn("Error calling @PreDestroy method", e);
112: }
113: }
114:
115: // shutdown server
116: super.stop();
117: }
118: }
|