Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SimpleServiceServer.java
Go to the documentation of this file.
1 
2 package vmi1;
3 
4 import vmi1.*;
5 
6 import java.io.File;
7 import java.util.List;
8 import java.util.Map;
9 import java.util.Iterator;
10 
11 import java.net.URL;
12 
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.apache.axis2.util.LoggingControl;
16 
17 import org.apache.axis2.AxisFault;
18 import org.apache.axis2.Constants;
19 import org.apache.axis2.context.ConfigurationContext;
20 import org.apache.axis2.context.ConfigurationContextFactory;
21 import org.apache.axis2.engine.ListenerManager;
22 import org.apache.axis2.transport.TransportListener;
23 import org.apache.axis2.description.TransportInDescription;
24 
25 import org.apache.axis2.engine.AxisConfigurator;
26 import org.apache.axis2.deployment.FileSystemConfigurator;
27 import org.apache.axis2.engine.AxisConfiguration;
28 import org.apache.axis2.engine.AxisServer;
29 import org.apache.axis2.description.AxisService;
30 import org.apache.axis2.description.Parameter;
31 import org.apache.axis2.engine.MessageReceiver;
32 import org.apache.axis2.AxisFault;
33 import org.apache.axis2.transport.http.SimpleHTTPServer;
34 import org.apache.axis2.description.java2wsdl.SchemaGenerator;
35 import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
36 
37 import org.apache.axis2.deployment.util.Utils;
38 
39 public class SimpleServiceServer extends SimpleHTTPServer {
40  private static final Log log = LogFactory.getLog(SimpleServiceServer.class);
41 
42  public SimpleServiceServer(ConfigurationContext cctx,int port)
43  throws AxisFault {
44  super(cctx,port);
45  }
46 
47  public void start() throws AxisFault {
48  try {
49  ConfigurationContext cctx = getConfigurationContext();
50  super.start();
51  ListenerManager listenerManager = cctx.getListenerManager();
52  TransportInDescription trsIn =
53  new TransportInDescription(Constants.TRANSPORT_HTTP);
54  trsIn.setReceiver(this);
55  if (listenerManager == null) {
56  listenerManager = new ListenerManager();
57  listenerManager.init(cctx);
58  }
59  listenerManager.addListener(trsIn, true);
60 
61  Iterator<String> iter = cctx.getAxisConfiguration().
62  getTransportsIn().keySet().iterator();
63  while (iter.hasNext()) {
64  String trp = iter.next();
65  if (!Constants.TRANSPORT_HTTP.equals(trp)) {
66  trsIn = (TransportInDescription)
67  cctx.getAxisConfiguration().getTransportsIn().get(trp);
68  listenerManager.addListener(trsIn, false);
69  }
70  }
71  }
72  catch (Exception ex) {
73  log.error(ex.getMessage(),ex);
74  throw AxisFault.makeFault(ex);
75  }
76  }
77 
78  public AxisService buildService(String className)
79  throws Exception,ClassNotFoundException,InstantiationException,
80  IllegalAccessException,AxisFault {
81  return buildService((SimpleService)Class.forName(className,true,this.getClass().getClassLoader()).newInstance());
82  }
83 
84  public AxisService buildService(SimpleService ss)
85  throws Exception,ClassNotFoundException,AxisFault {
86  String resourcePath = ss.getSchemaResourcePath();
87  Class implClass = ss.getClass();
88  String implClassName = implClass.getCanonicalName();
89  int index = implClassName.lastIndexOf(".");
90  String serviceName = ss.getServiceName();
91  if (serviceName == null) {
92  if (index > 0) {
93  serviceName =
94  implClassName.substring(index + 1,implClassName.length());
95  } else {
96  serviceName = implClassName;
97  }
98  }
99 
100  SchemaGenerator sg = null;
101  AxisService as = null;
102  if (resourcePath != null) {
103  AxisConfiguration ac =
104  getConfigurationContext().getAxisConfiguration();
105  as = new AxisService();
106  as.setParent(ac);
107  as.setName(serviceName);
108 
109  URL rurl = null;
110 
111  if (java.lang.Thread.currentThread().getContextClassLoader() != null) {
112  ClassLoader cl =
113  java.lang.Thread.currentThread().getContextClassLoader();
114  rurl = cl.getResource(resourcePath);
115  }
116  else if (implClass != null) {
117  rurl = implClass.getResource(resourcePath);
118  }
119  else {
120  rurl = implClass.getClassLoader().getResource(resourcePath);
121  }
122 
123  sg = new ResourceSchemaGenerator(implClass.getClassLoader(),
124  implClassName,
125  rurl,
126  ss.getSchemaNamespace(),
127  ss.getSchemaNamespacePrefix(),
128  ss.getMethodClassNameMapping(),
129  ss.getDynamicTypeMapping(),
130  ss.getStaticTypeMapping(),
131  as);
132  sg.setElementFormDefault(Java2WSDLConstants.FORM_DEFAULT_UNQUALIFIED);
133  }
134 
135  return buildService(ss.getClass().getCanonicalName(),serviceName,
136  //serviceURL,isRootService,
137  ss.getMessageReceiverClassMap(),
138  ss.getTargetNamespace(),ss.getSchemaNamespace(),sg,as);
139  }
140 
141  public AxisService buildService(String implClass,String serviceName,
142  Map<String,MessageReceiver> msgReceiverClassMap,
143  String targetNamespace,String schemaNamespace,
144  SchemaGenerator sg,AxisService as)
145  throws Exception,ClassNotFoundException,AxisFault {
146  AxisConfiguration ac = getConfigurationContext().getAxisConfiguration();
147 
148  if (sg != null) {
149  as = AxisService.createService(implClass,serviceName,
150  ac,msgReceiverClassMap,targetNamespace,
151  this.getClass().getClassLoader(),
152  sg,as);
153  }
154  else
155  as = AxisService.createService(implClass,ac,msgReceiverClassMap,
156  targetNamespace,schemaNamespace,
157  this.getClass().getClassLoader());
158 
159  ac.addService(as);
160 
161  return as;
162  }
163 
169  public static void main(String[] args) {
170  AxisConfigurator ac;
171  ConfigurationContext cctx;
173 
174  try {
175  ac = new FileSystemConfigurator(null,null);
176  //ac.getAxisConfiguration().addParameter(Constants.PARAM_SERVICE_PATH,
177  // "/");
178  //ac.getAxisConfiguration().addParameter(Constants.PARAM_CONTEXT_ROOT,
179  // "/");
180  cctx = ConfigurationContextFactory.createConfigurationContext(ac);
181 
182  ss = new SimpleServiceServer(cctx,3952);
183 
184  //Parameter servicePath = ac.getAxisConfiguration().getParameter(Constants.PARAM_SERVICE_PATH);
185  //Parameter contextPath = ac.getAxisConfiguration().getParameter(Constants.PARAM_CONTEXT_ROOT);
186 
187  /*
188  * NB: must set contextRoot after servicePath to ensure an
189  * internal cache is updated.
190  *
191  * More importantly, you must set root to /, and servicePath
192  * to some relative path ***that is part of your namespace
193  * string!***
194  *
195  * Well, at least one path through axis's dispatchers
196  * considers this valid; there may be other ways!
197  */
198  ss.getConfigurationContext().setServicePath("vmi/1");
199  ss.getConfigurationContext().setContextRoot("/");
200 
201  for (int i = 0; i < args.length; ++i) {
202  ss.buildService(args[i]);
203  }
204 
205  ss.start();
206  System.out.println("Started HTTP server on port "
207  + ss.getHttpFactory().getPort());
208  }
209  catch (Throwable t) {
210  System.err.println("Could not start server:");
211  t.printStackTrace();
212  System.exit(6);
213  }
214  }
215 
216 }
217 
AxisService buildService(String implClass, String serviceName, Map< String, MessageReceiver > msgReceiverClassMap, String targetNamespace, String schemaNamespace, SchemaGenerator sg, AxisService as)
static uint64_t unsigned int i
AxisService buildService(String className)
SimpleServiceServer(ConfigurationContext cctx, int port)
static void main(String[] args)
AxisService buildService(SimpleService ss)
struct target * t
Definition: dumptarget.c:48