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.cxf.greeter_control;
019:
020: import java.util.List;
021: import java.util.concurrent.Future;
022: import java.util.logging.Logger;
023:
024: import javax.jws.WebService;
025: import javax.xml.ws.AsyncHandler;
026: import javax.xml.ws.Endpoint;
027: import javax.xml.ws.Response;
028:
029: import org.apache.cxf.Bus;
030: import org.apache.cxf.BusFactory;
031: import org.apache.cxf.configuration.Configurer;
032: import org.apache.cxf.greeter_control.types.FaultLocation;
033: import org.apache.cxf.greeter_control.types.StartGreeterResponse;
034: import org.apache.cxf.greeter_control.types.StopGreeterResponse;
035: import org.apache.cxf.interceptor.Interceptor;
036:
037: @WebService(serviceName="ControlService",portName="ControlPort",endpointInterface="org.apache.cxf.greeter_control.Control",targetNamespace="http://cxf.apache.org/greeter_control")
038: public class ControlImpl implements Control {
039:
040: private static final Logger LOG = Logger
041: .getLogger(ControlImpl.class.getName());
042: protected Object implementor;
043: protected String address;
044: protected Endpoint endpoint;
045: protected Bus greeterBus;
046:
047: public void setImplementor(Object i) {
048: implementor = i;
049: }
050:
051: public Object getImplementor() {
052: return implementor;
053: }
054:
055: public void setAddress(String a) {
056: address = a;
057: }
058:
059: public String getAddress() {
060: return address;
061: }
062:
063: public boolean startGreeter(String cfgResource) {
064: LOG.fine("Starting greeter with cfgResource: " + cfgResource);
065: greeterBus = null;
066: BusFactory.setDefaultBus(null);
067: String original = System
068: .clearProperty(Configurer.USER_CFG_FILE_PROPERTY_NAME);
069: try {
070: if (cfgResource != null && cfgResource.length() > 0) {
071: System.setProperty(
072: Configurer.USER_CFG_FILE_PROPERTY_NAME,
073: cfgResource);
074: }
075:
076: String a = address == null ? "http://localhost:9020/SoapContext/GreeterPort"
077: : address;
078: Object i = implementor == null ? new GreeterImpl()
079: : implementor;
080: endpoint = Endpoint.publish(a, i);
081: LOG
082: .info("Published greeter endpoint on bus with cfg file resource: "
083: + cfgResource);
084: greeterBus = BusFactory.getDefaultBus();
085: } finally {
086: System
087: .clearProperty(Configurer.USER_CFG_FILE_PROPERTY_NAME);
088: if (null != original) {
089: System.setProperty(
090: Configurer.USER_CFG_FILE_PROPERTY_NAME,
091: cfgResource);
092: }
093: }
094: if (implementor instanceof AbstractGreeterImpl) {
095: ((AbstractGreeterImpl) implementor).resetLastOnewayArg();
096: }
097:
098: return null != greeterBus;
099: }
100:
101: public boolean stopGreeter(String requestType) {
102: LOG.fine("Stopping greeter");
103:
104: if (null != endpoint) {
105: LOG.info("Stopping Greeter endpoint");
106: endpoint.stop();
107: } else {
108: LOG.info("No endpoint active.");
109: }
110: endpoint = null;
111: if (null != greeterBus) {
112: greeterBus.shutdown(true);
113: }
114: greeterBus = null;
115: return true;
116: }
117:
118: public void setFaultLocation(FaultLocation fl) {
119: List<Interceptor> interceptors = greeterBus.getInInterceptors();
120: FaultThrowingInterceptor fi = null;
121: for (Interceptor i : interceptors) {
122: if (i instanceof FaultThrowingInterceptor) {
123: interceptors.remove(i);
124: LOG.fine("Removed existing FaultThrowingInterceptor");
125: break;
126: }
127: }
128:
129: fi = new FaultThrowingInterceptor(fl.getPhase());
130: if (null != fl.getBefore() && !"".equals(fl.getBefore())) {
131: fi.addBefore(fl.getBefore());
132: }
133: if (null != fl.getAfter() && !"".equals(fl.getAfter())) {
134: fi.addAfter(fl.getAfter());
135: }
136:
137: interceptors.add(fi);
138: LOG.fine("Added FaultThrowingInterceptor to phase "
139: + fl.getPhase());
140: }
141:
142: public Future<?> startGreeterAsync(String requestType,
143: AsyncHandler<StartGreeterResponse> asyncHandler) {
144: // never called
145: return null;
146: }
147:
148: public Response<StartGreeterResponse> startGreeterAsync(
149: String requestType) {
150: // never called
151: return null;
152: }
153:
154: public Response<StopGreeterResponse> stopGreeterAsync(
155: String requestType) {
156: // never called
157: return null;
158: }
159:
160: public Future<?> stopGreeterAsync(String requestType,
161: AsyncHandler<StopGreeterResponse> asyncHandler) {
162: // never called
163: return null;
164: }
165:
166: @WebService(serviceName="GreeterService",portName="GreeterPort",endpointInterface="org.apache.cxf.greeter_control.Greeter",targetNamespace="http://cxf.apache.org/greeter_control")
167: class GreeterImpl extends AbstractGreeterImpl {
168: }
169:
170: }
|