Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create a WSDM interface for an HTTP server using Apache Muse

Exposing the manageability of a common product with Web services standards

Dan Jemiolo, Advisory Software Engineer, EMC
Photo of Dan Jemiolo
Dan Jemiolo is an Advisory Software Engineer on IBM's Autonomic Computing team in Research Triangle Park, NC. He led the design and development of Apache Muse 2.0 and continues to work on the project today. Dan also participates in the WS-RF TC as editor of the WS-ResourceMetadataDescriptor specification and is involved in IBM's strategy for increasing adoption of Web services standards. He came to IBM just over two years ago after earning his Master of Science degree in Computer Science from Rensselaer Polytechnic Institute.
(An IBM developerWorks Contributing Author)

Summary:  Learn how you can use Apache Muse to create a WS-DistributedManagement (WSDM)-compliant interface for a manageable resource. In this tutorial, you'll see how to design the Web service interface for the resource, generate code for the implementation, and deploy the code as a Web application. The manageable resource focus of this tutorial is the ubiquitous Apache HTTP Server, commonly-referred to as "httpd." After completing this tutorial, you should have a Muse-based application that lets any WSDM-compliant management client manipulate the httpd resource.

Date:  21 Nov 2006
Level:  Intermediate PDF:  A4 and Letter (72 KB | 22 pages)Get Adobe® Reader®

Activity:  25544 views
Comments:  

Implementing the HTTP Server operations

In this section you'll use the httpd.conf file to fill in the values of the resource property fields. The implementation defines the three properties as read-only to remote clients so that you don't have to introduce WS-Security authentication; keeping the properties read-only also allows you to avoid the checks that would be needed to prevent changes while the httpd process is running.

Because your properties won't change after startup, you can read them in from httpd.conf once during initialization and keep them in the fields that WSDL2Java created in the MyCapability class. You should copy and paste the implementation code into your MyCapability.java file.


Listing 8. Implementation code
    public void initialize()
        throws SoapFault
    {
        super.initialize();
        
        Map configParams = null;
	        
	try
	{
	    configParams = readConfigFile("/apache-2.2/conf/httpd.conf");
	}

	catch (IOException error)
	{
	    throw new SoapFault("Error while reading httpd.conf.", error);
	}

	_ServerName = (String)configParams.get("ServerName");
	
	String portString = (String)configParams.get("Listen");
	String threadsString = (String)configParams.get("ThreadsPerChild");
	
	_PortNumber = Integer.valueOf(portString);
        _ThreadsPerChild = Integer.valueOf(threadsString);
    }
    
    protected Map readConfigFile(String filePath)
        throws IOException
    {
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        String nextLine = null;
        
        Map configParams = new HashMap();
        
        while ((nextLine = reader.readLine()) != null)
        {
            nextLine = nextLine.trim();
            
            // ignore comments and blank lines
            if (nextLine.length() == 0 || 
                nextLine.charAt(0) == '#' || 
                nextLine.charAt(0) == '<')
                continue;
            
            int space = nextLine.indexOf(' ');
            String name = nextLine.substring(0, space);
            String value = nextLine.substring(space + 1);
            configParams.put(name, value);
        }
        
        return configParams;
    }

Allowing for mutable resource properties

If your properties were dynamic, you would remove the fields and instead read the property values from httpd.conf in each getter method. If you end up extending this application to make the properties mutable, both the getter and setter methods will be implemented using the java.io package to read in the httpd.conf file at the time of the request.

The first method overrides the base class's initialize method, which is where capabilities can perform all of their self-contained startup tasks; this method simply reads the name-value pairs in the httpd.conf file into a java.util.Map and then sets the class's fields using the values it finds. The initialize method is called before any SOAP requests are serviced by the Muse application.

The second method performs the actual task of parsing the file into java.util.Map, taking care to remove comments and blank lines from the input. Finally, the getter methods should remain exactly as they are -- they simply return the values that were read in from httpd.conf when called by Muse's GetResourceProperty implementation.

9 of 15 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Tivoli, SOA and web services
ArticleID=175541
TutorialTitle=Create a WSDM interface for an HTTP server using Apache Muse
publish-date=11212006
author1-email=danjemiolo@us.ibm.com
author1-email-cc=

IBM SmartCloud trial. No charge.

IBM PureSystems on a kaleideoscope background

Unleash the power of hybrid cloud computing today!


Special offers