Package org.apache.muse.test.http.testapp

Source Code of org.apache.muse.test.http.testapp.HttpServerTestApp

/*=============================================================================*
*  Copyright 2006 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*=============================================================================*/

package org.apache.muse.test.http.testapp;

import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;

import javax.xml.namespace.QName;

import org.apache.muse.core.routing.CounterResourceIdFactory;
import org.apache.muse.core.routing.ResourceIdFactory;
import org.apache.muse.ws.addressing.EndpointReference;

import org.apache.muse.test.http.SupportedLanguage;
import org.apache.muse.test.http.remote.HttpServerClient;

public class HttpServerTestApp
{
    public static void addReferenceParameter(EndpointReference epr)
    {
        ResourceIdFactory factory = new CounterResourceIdFactory();
        QName name = factory.getIdentifierName();
        URI value = factory.getNextIdentifier();
        epr.addParameter(name, value);
    }
   
    public static URI getLocalAddress(String contextPath, int port)
        throws UnknownHostException
    {
        String ip = InetAddress.getLocalHost().getHostAddress();
       
        StringBuffer address = new StringBuffer();
        address.append("http://");
        address.append(ip);
        address.append(':');
        address.append(port);
       
        if (contextPath.charAt(0) != '/')
            address.append('/');
           
        address.append(contextPath);
       
        return URI.create(address.toString());
    }
   
    public static void main(String[] args)
    {
        try
        {
            //
            // change these to point to different applications/servers
            //
            String contextPath = "/test-apache-httpd/services/http-server";
            int port = 8080;
           
            //
            // create EPR for test resource
            //
            URI address = getLocalAddress(contextPath, port);
            EndpointReference epr = new EndpointReference(address);
           
            addReferenceParameter(epr);
           
            //
            // create proxy - turn on tracing of SOAP messages
            //
            HttpServerClient http = new HttpServerClient(epr);
            http.setTrace(true);
           
            //
            // start server
            //
            http.start();
           
            //
            // read/print some property values
            //
            String httpName = http.getName();
            int httpPort = http.getPort();
            SupportedLanguage[] httpLang = http.getSupportedLanguage();
           
            System.out.println("Name: " + httpName);
            System.out.println("Port: " + httpPort);
           
            System.out.println("Supported Languages:");
           
            for (int n = 0; n < httpLang.length; ++n)
                System.out.println("\t" + httpLang[n]);
           
            //
            // stop server
            //
            http.stop();
        }
       
        catch (Throwable error)
        {
            error.printStackTrace();
        }
    }
}
TOP

Related Classes of org.apache.muse.test.http.testapp.HttpServerTestApp

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.