Search in sources :

Example 1 with SimpleHTTPServer

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();
}
Also used : SimpleHTTPServer(org.apache.axis2.transport.http.SimpleHTTPServer)

Example 2 with SimpleHTTPServer

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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) HTTPWorkerFactory(org.apache.axis2.transport.http.HTTPWorkerFactory) AxisService(org.apache.axis2.description.AxisService) SimpleHttpServer(org.apache.axis2.transport.http.server.SimpleHttpServer) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) WorkerFactory(org.apache.axis2.transport.http.server.WorkerFactory) HTTPWorkerFactory(org.apache.axis2.transport.http.HTTPWorkerFactory)

Example 3 with SimpleHTTPServer

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");
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) OptionsParser(org.apache.axis2.util.OptionsParser) File(java.io.File) ListenerManager(org.apache.axis2.engine.ListenerManager)

Example 4 with SimpleHTTPServer

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;
}
Also used : LifecycleFixTransportListenerProxy(org.apache.axis2.transport.testkit.util.LifecycleFixTransportListenerProxy) Parameter(org.apache.axis2.description.Parameter) TransportInDescription(org.apache.axis2.description.TransportInDescription)

Example 5 with SimpleHTTPServer

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 ---------------");
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Options(org.apache.axis2.client.Options) TransportInDescription(org.apache.axis2.description.TransportInDescription) ObjectOutputStream(java.io.ObjectOutputStream) SimpleHTTPServer(org.apache.axis2.transport.http.SimpleHTTPServer) FileInputStream(java.io.FileInputStream) EndpointReference(org.apache.axis2.addressing.EndpointReference) HTTPClient4TransportSender(org.apache.axis2.transport.http.impl.httpclient4.HTTPClient4TransportSender) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)11 SimpleHTTPServer (org.apache.axis2.transport.http.SimpleHTTPServer)10 MessageContext (org.apache.axis2.context.MessageContext)8 TransportInDescription (org.apache.axis2.description.TransportInDescription)8 AxisService (org.apache.axis2.description.AxisService)7 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)6 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)5 RequestURIBasedDispatcher (org.apache.axis2.dispatchers.RequestURIBasedDispatcher)5 HTTPClient4TransportSender (org.apache.axis2.transport.http.impl.httpclient4.HTTPClient4TransportSender)5 File (java.io.File)4 AxisFault (org.apache.axis2.AxisFault)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 AxisServiceGroup (org.apache.axis2.description.AxisServiceGroup)4 AddressingBasedDispatcher (org.apache.axis2.dispatchers.AddressingBasedDispatcher)4 SOAPActionBasedDispatcher (org.apache.axis2.dispatchers.SOAPActionBasedDispatcher)4 SOAPMessageBodyBasedDispatcher (org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher)4 RawXMLINOnlyMessageReceiver (org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver)4 RawXMLINOutMessageReceiver (org.apache.axis2.receivers.RawXMLINOutMessageReceiver)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2