use of org.apache.axis2.transport.http.SimpleHTTPServer in project axis-axis2-java-core by apache.
the class Axis2Server method startServer.
@Override
protected void startServer(ConfigurationContext configurationContext) throws Throwable {
port = PortAllocator.allocatePort();
server = new SimpleHTTPServer(configurationContext, port);
server.start();
}
use of org.apache.axis2.transport.http.SimpleHTTPServer in project axis-axis2-java-core by apache.
the class EndpointImpl method publish.
/*
* (non-Javadoc)
* @see javax.xml.ws.Endpoint#publish(java.lang.String)
*/
public void publish(String s) {
if (isPublishDisabled()) {
throw new UnsupportedOperationException("Endpoint publish not allowed in managed environment");
}
int port = -1;
String address = s;
try {
URI uri = new URI(s);
port = uri.getPort();
} catch (URISyntaxException e) {
}
// Default to 8080
if (port == -1) {
port = 8080;
address = s + ":" + port;
}
ConfigurationContext ctx = endpointDesc.getServiceDescription().getAxisConfigContext();
if (endpointDesc.getEndpointAddress() == null)
endpointDesc.setEndpointAddress(address);
try {
// For some reason the AxisService has not been added to the ConfigurationContext
// at this point, so we need to do it for the service to be available.
AxisService svc = endpointDesc.getAxisService();
ctx.getAxisConfiguration().addService(svc);
} catch (AxisFault e) {
throw ExceptionFactory.makeWebServiceException(e);
}
// Remove the default "axis2" context root.
ctx.setContextRoot("/");
WorkerFactory wf = new HTTPWorkerFactory();
try {
server = new SimpleHttpServer(ctx, wf, port);
server.init();
server.start();
} catch (IOException e) {
throw ExceptionFactory.makeWebServiceException(e);
}
published = true;
}
use of org.apache.axis2.transport.http.SimpleHTTPServer in project axis-axis2-java-core by apache.
the class SimpleHTTPServer method main.
/**
* Method main
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int port = DEFAULT_PORT;
OptionsParser optionsParser = new OptionsParser(args);
args = optionsParser.getRemainingArgs();
// first check if we should print usage
if ((optionsParser.isFlagSet('?') > 0) || (optionsParser.isFlagSet('h') > 0) || args == null || args.length == 0 || args.length > 3) {
printUsage();
}
String paramPort = optionsParser.isValueSet('p');
if (paramPort != null) {
port = Integer.parseInt(paramPort);
}
boolean startAllTransports = "all".equals(optionsParser.isValueSet('t'));
String repository = optionsParser.isValueSet('r');
if (repository == null) {
args = optionsParser.getRemainingArgs();
if (args != null && args[0] != null && !args[0].equals("")) {
repository = args[0];
} else {
printUsage();
}
}
System.out.println("[SimpleHTTPServer] Starting");
System.out.println("[SimpleHTTPServer] Using the Axis2 Repository " + new File(repository).getAbsolutePath());
System.out.println("[SimpleHTTPServer] Listening on port " + port);
try {
ConfigurationContext configctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository, null);
SimpleHTTPServer receiver = new SimpleHTTPServer(configctx, port);
Runtime.getRuntime().addShutdownHook(new ShutdownThread(receiver));
receiver.start();
ListenerManager listenerManager = configctx.getListenerManager();
TransportInDescription trsIn = new TransportInDescription(Constants.TRANSPORT_HTTP);
trsIn.setReceiver(receiver);
if (listenerManager == null) {
listenerManager = new ListenerManager();
listenerManager.init(configctx);
}
listenerManager.addListener(trsIn, true);
// should all transports be started? specified as "-t all"
if (startAllTransports) {
Iterator<String> iter = configctx.getAxisConfiguration().getTransportsIn().keySet().iterator();
while (iter.hasNext()) {
String trp = iter.next();
if (!Constants.TRANSPORT_HTTP.equals(trp)) {
trsIn = (TransportInDescription) configctx.getAxisConfiguration().getTransportsIn().get(trp);
listenerManager.addListener(trsIn, false);
}
}
}
System.out.println("[SimpleHTTPServer] Started");
} catch (Throwable t) {
log.fatal("Error starting SimpleHTTPServer", t);
System.out.println("[SimpleHTTPServer] Shutting down");
}
}
use of org.apache.axis2.transport.http.SimpleHTTPServer in project axis-axis2-java-core by apache.
the class HttpTransportDescriptionFactory method createTransportInDescription.
public TransportInDescription createTransportInDescription() throws Exception {
TransportInDescription desc = new TransportInDescription("http");
desc.setReceiver(new LifecycleFixTransportListenerProxy(new SimpleHTTPServer(), port));
desc.addParameter(new Parameter(SimpleHTTPServer.PARAM_PORT, String.valueOf(port)));
return desc;
}
use of org.apache.axis2.transport.http.SimpleHTTPServer in project axis-axis2-java-core by apache.
the class OptionsSaveTest method testSaveAndRestore.
public void testSaveAndRestore() throws Exception {
File theFile = null;
String theFilename = null;
boolean saved = false;
boolean restored = false;
boolean done = false;
boolean comparesOk = false;
AxisConfiguration axisConfiguration = new AxisConfiguration();
ConfigurationContext configurationContext = new ConfigurationContext(axisConfiguration);
log.debug("OptionsSaveTest:testSaveAndRestore(): BEGIN ---------------");
// ---------------------------------------------------------
// setup an options object to use
// ---------------------------------------------------------
Options options = new Options();
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setExceptionToBeThrownOnSOAPFault(true);
options.setTimeOutInMilliSeconds(5000L);
options.setUseSeparateListener(false);
options.setAction("SoapAction");
options.setFaultTo(new EndpointReference("http://ws.apache.org/axis2/faultTo"));
options.setFrom(new EndpointReference("http://ws.apache.org/axis2/from"));
options.setTo(new EndpointReference("http://ws.apache.org/axis2/to"));
options.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL));
TransportOutDescription transportOut = new TransportOutDescription("null");
TransportOutDescription transportOut2 = new TransportOutDescription("happy");
TransportOutDescription transportOut3 = new TransportOutDescription("golucky");
transportOut.setSender(new HTTPClient4TransportSender());
transportOut2.setSender(new HTTPClient4TransportSender());
transportOut3.setSender(new HTTPClient4TransportSender());
options.setTransportOut(transportOut);
axisConfiguration.addTransportOut(transportOut3);
axisConfiguration.addTransportOut(transportOut2);
axisConfiguration.addTransportOut(transportOut);
TransportInDescription transportIn = new TransportInDescription("null");
TransportInDescription transportIn2 = new TransportInDescription("always");
TransportInDescription transportIn3 = new TransportInDescription("thebest");
transportIn.setReceiver(new SimpleHTTPServer());
transportIn2.setReceiver(new SimpleHTTPServer());
transportIn3.setReceiver(new SimpleHTTPServer());
options.setTransportIn(transportIn);
axisConfiguration.addTransportIn(transportIn2);
axisConfiguration.addTransportIn(transportIn);
axisConfiguration.addTransportIn(transportIn3);
options.setMessageId("msgId012345");
options.setProperty("key01", "value01");
options.setProperty("key02", "value02");
options.setProperty("key03", "value03");
options.setProperty("key04", "value04");
options.setProperty("key05", "value05");
options.setProperty("key06", "value06");
options.setProperty("key07", "value07");
options.setProperty("key08", "value08");
options.setProperty("key09", "value09");
options.setProperty("key10", "value10");
// ---------------------------------------------------------
try {
theFile = File.createTempFile("optionsSave", null);
theFilename = theFile.getName();
log.debug("OptionsSaveTest:testSaveAndRestore(): temp file = [" + theFilename + "]");
} catch (Exception ex) {
log.debug("OptionsSaveTest:testSaveAndRestore(): error creating temp file = [" + ex.getMessage() + "]");
theFile = null;
}
if (theFile != null) {
// ---------------------------------------------------------
try {
// setup an output stream to a physical file
FileOutputStream outStream = new FileOutputStream(theFile);
// attach a stream capable of writing objects to the
// stream connected to the file
ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
// try to save the message context
log.debug("OptionsSaveTest:testSaveAndRestore(): saving .....");
saved = false;
outObjStream.writeObject(options);
// close out the streams
outObjStream.flush();
outObjStream.close();
outStream.flush();
outStream.close();
saved = true;
log.debug("OptionsSaveTest:testSaveAndRestore(): ....save operation completed.....");
long filesize = theFile.length();
log.debug("OptionsSaveTest:testSaveAndRestore(): file size after save [" + filesize + "] temp file = [" + theFilename + "]");
} catch (Exception ex2) {
if (saved != true) {
log.debug("OptionsSaveTest:testSaveAndRestore(): error during save [" + ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
ex2.printStackTrace();
} else {
log.debug("OptionsSaveTest:testSaveAndRestore(): error during restore [" + ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
ex2.printStackTrace();
}
}
assertTrue(saved);
// ---------------------------------------------------------
try {
// setup an input stream to the file
FileInputStream inStream = new FileInputStream(theFile);
// attach a stream capable of reading objects from the
// stream connected to the file
ObjectInputStream inObjStream = new ObjectInputStream(inStream);
// try to restore the options
log.debug("OptionsSaveTest:testSaveAndRestore(): restoring .....");
restored = false;
Options options_restored = (Options) inObjStream.readObject();
inObjStream.close();
inStream.close();
options_restored.activate(configurationContext);
restored = true;
log.debug("OptionsSaveTest:testSaveAndRestore(): ....restored operation completed.....");
comparesOk = options_restored.isEquivalent(options);
log.debug("OptionsSaveTest:testSaveAndRestore(): Options equivalency [" + comparesOk + "]");
} catch (Exception ex2) {
log.debug("OptionsSaveTest:testSaveAndRestore(): error during restore [" + ex2.getClass().getName() + " : " + ex2.getMessage() + "]");
ex2.printStackTrace();
}
assertTrue(restored);
assertTrue(comparesOk);
// if the save/restore of the object succeeded,
// then don't keep the temporary file around
boolean removeTmpFile = saved && restored && comparesOk;
if (removeTmpFile) {
try {
theFile.delete();
} catch (Exception e) {
// just absorb it
}
}
// indicate that the temp file was created ok
done = true;
}
// this is false when there are problems with the temporary file
assertTrue(done);
log.debug("OptionsSaveTest:testSaveAndRestore(): END ---------------");
}
Aggregations