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: */
019: package org.apache.axis2.jaxws.server.endpoint;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.context.ConfigurationContext;
023: import org.apache.axis2.description.AxisService;
024: import org.apache.axis2.jaxws.ExceptionFactory;
025: import org.apache.axis2.jaxws.binding.BindingImpl;
026: import org.apache.axis2.jaxws.binding.BindingUtils;
027: import org.apache.axis2.jaxws.description.DescriptionFactory;
028: import org.apache.axis2.jaxws.description.EndpointDescription;
029: import org.apache.axis2.jaxws.description.ServiceDescription;
030: import org.apache.axis2.transport.http.HTTPWorkerFactory;
031: import org.apache.axis2.transport.http.server.SimpleHttpServer;
032: import org.apache.axis2.transport.http.server.WorkerFactory;
033:
034: import javax.xml.transform.Source;
035: import javax.xml.ws.Binding;
036:
037: import java.io.IOException;
038: import java.util.List;
039: import java.util.Map;
040: import java.util.concurrent.Executor;
041:
042: public class EndpointImpl extends javax.xml.ws.Endpoint {
043:
044: private boolean published;
045: private Object implementor;
046: private EndpointDescription endpointDesc;
047: private Binding binding;
048: private SimpleHttpServer server;
049:
050: public EndpointImpl(Object o) {
051: implementor = o;
052: initialize();
053: }
054:
055: public EndpointImpl(Object o, Binding bnd, EndpointDescription ed) {
056: implementor = o;
057: endpointDesc = ed;
058: initialize();
059: }
060:
061: private void initialize() {
062: if (implementor == null) {
063: throw ExceptionFactory
064: .makeWebServiceException("The implementor object cannot be null");
065: }
066:
067: // If we don't have the necessary metadata, let's go ahead and
068: // create it.
069: if (endpointDesc == null) {
070: ServiceDescription sd = DescriptionFactory
071: .createServiceDescription(implementor.getClass());
072: endpointDesc = sd.getEndpointDescriptions_AsCollection()
073: .iterator().next();
074: }
075:
076: if (endpointDesc != null && binding == null) {
077: binding = BindingUtils.createBinding(endpointDesc);
078: }
079:
080: published = false;
081: }
082:
083: /*
084: * (non-Javadoc)
085: * @see javax.xml.ws.Endpoint#getMetadata()
086: */
087: public List<Source> getMetadata() {
088: return null;
089: }
090:
091: /*
092: * (non-Javadoc)
093: * @see javax.xml.ws.Endpoint#setMetadata(java.util.List)
094: */
095: public void setMetadata(List<Source> list) {
096: return;
097: }
098:
099: /*
100: * (non-Javadoc)
101: * @see javax.xml.ws.Endpoint#getProperties()
102: */
103: public Map<String, Object> getProperties() {
104: return null;
105: }
106:
107: /*
108: * (non-Javadoc)
109: * @see javax.xml.ws.Endpoint#setProperties(java.util.Map)
110: */
111: public void setProperties(Map<String, Object> properties) {
112: return;
113: }
114:
115: /*
116: * (non-Javadoc)
117: * @see javax.xml.ws.Endpoint#getBinding()
118: */
119: public Binding getBinding() {
120: return binding;
121: }
122:
123: /*
124: * (non-Javadoc)
125: * @see javax.xml.ws.Endpoint#getExecutor()
126: */
127: public Executor getExecutor() {
128: return null;
129: }
130:
131: /*
132: * (non-Javadoc)
133: * @see javax.xml.ws.Endpoint#getImplementor()
134: */
135: public Object getImplementor() {
136: return implementor;
137: }
138:
139: /*
140: * (non-Javadoc)
141: * @see javax.xml.ws.Endpoint#isPublished()
142: */
143: public boolean isPublished() {
144: return published;
145: }
146:
147: /*
148: * (non-Javadoc)
149: * @see javax.xml.ws.Endpoint#publish(java.lang.Object)
150: */
151: public void publish(Object obj) {
152:
153: }
154:
155: /*
156: * (non-Javadoc)
157: * @see javax.xml.ws.Endpoint#publish(java.lang.String)
158: */
159: public void publish(String s) {
160: ConfigurationContext ctx = endpointDesc.getServiceDescription()
161: .getAxisConfigContext();
162:
163: try {
164: // For some reason the AxisService has not been added to the ConfigurationContext
165: // at this point, so we need to do it for the service to be available.
166: AxisService svc = endpointDesc.getAxisService();
167: ctx.getAxisConfiguration().addService(svc);
168: } catch (AxisFault e) {
169: throw ExceptionFactory.makeWebServiceException(e);
170: }
171:
172: // Remove the default "axis2" context root.
173: ctx.setContextRoot("/");
174:
175: WorkerFactory wf = new HTTPWorkerFactory();
176:
177: try {
178: server = new SimpleHttpServer(ctx, wf, 8080); //TODO: Add a configurable port
179: server.init();
180: server.start();
181: } catch (IOException e) {
182: throw ExceptionFactory.makeWebServiceException(e);
183: }
184:
185: published = true;
186: }
187:
188: /*
189: * (non-Javadoc)
190: * @see javax.xml.ws.Endpoint#setExecutor(java.util.concurrent.Executor)
191: */
192: public void setExecutor(Executor executor) {
193:
194: }
195:
196: /*
197: * (non-Javadoc)
198: * @see javax.xml.ws.Endpoint#stop()
199: */
200: public void stop() {
201: try {
202: server.destroy();
203: } catch (IOException e) {
204: e.printStackTrace();
205: } catch (InterruptedException e) {
206: e.printStackTrace();
207: }
208: }
209: }
|