Wednesday, July 24, 2013


opentravel web service - simple example

I'm going to show you how easy it is to write a REST and SOAP web service for opentravel messages using open source software.

By leveraging open source software, most of the difficult code is already written. All you have to do is implement a java interface to service the web service calls.

You don't have to worry about messy xml handling, you work with java classes. The framework does the work for you.

For this example we'll assume that you are a local sightseeing company. Your customers want to be able to access real-time pricing and availability for all of our tours.

They use the opentravel 2013A Tour Activity Availability message pair using SOAP and REST over HTTP.

This means you need a web server, a SOAP processing module, and a schema parser, as well as your code. Luckily open source software does most this.

If you're impatient and you just want this demo up and running with a just a few commands, click here for the schema library rest example.

I've created a template for your sample project. To create your project from this template, start eclipse and select:

File -> New -> Project -> Maven Project
On the Archetype screen, select the archetype: opentravel-touractivity-ws-service-archetype. If the artifact doesn't appear, click the 'add archetype' button; GroupId: org.jibx.schema.org.opentravel._2013A.ws, ArtifactId: opentravel-touractivity-ws-service-archetype, Version: 1.1.1 (Not the version show in this image)

On the Project screen, enter your group, artifact name, and version.

You can enter anything you want here. You will need your project group, artifact, and version when you deploy your project.
Click finish to build your project.

This project has three files.

The pom files is the maven project file. You will need to update the parent version number to version 1.1.1. The start of your pom file should look like this:
    <parent>
      <groupid>org.jibx.schema.org.opentravel._2013A.ws</groupid>
      <artifactid>opentravel-2013A-ws-reactor</artifactid>
      <version>1.1.1</version>    
   </parent>

The blueprint.xml file is the configuration file. This blueprint tells the system to register this service to handle opentravel touractivity messages.

The source file handles the actual messages. This code is expected to process request messages and return a response.

If you look at the source code, you will find the method:
public AvailRS avail(AvailRQ request)
I have included some sample code that returns availability and pricing for several fake tours. This is where you would access your inventory and pricing and populate the return message.
The cool part of using a java representation of the opentravel xml message is you can use all the eclipse programming shortcuts, such as auto-complete and documentation display. All the comments and xml snippets from the (complex) opentravel schema have been transferred to the java source code. Try to ctrl-click one of the request or response method names and you will be looking at the java source code model of the xml message.

To build the project, right-click the project name in the project explorer and select Run as -> Maven install

Now we are ready to deploy this code.

For this example, I'll use apache karaf and cxf. You can also use any one of the enhanced esb servers such as Talend or Fuse. In fact, this code uses only open specifications, so you should be able to run it with minor configuration changes on almost any java app server.

Download karaf, unzip, and run it:

tar zxvf apache-karaf-2.3.2.tar.gz
cd apache-karaf-2.3.2
bin/karaf
First, install apache cxf and a few support bundles.
features:addurl mvn:org.apache.cxf.karaf/apache-cxf/2.7.6/xml/features
features:install cxf cxf-databinding-jibx http obr
Now start the RESTful server and the SOAP server. These servers are configured to send incoming messages to a service registered to handle touractivity messages. (The blueprint.xml file does this) Type these command into the servicemix console.
obr:addurl http://www.jibx.org/repository.xml
obr:start -d org.jibx.schema.org.opentravel._2013A.touractivity.ws.soap
obr:start -d org.jibx.schema.org.opentravel._2013A.touractivity.ws.rest

# Enter the actual group/artifact/version of your project here:
start mvn:org.jibx.schema.org.opentravel.ws/org.jibx.schema.org.opentravel._2013A.touractivity.ws.service/0.0.1-SNAPSHOT


Give it a moment to start, then try out the rest service by clicking this link:
http://localhost:8092/rest/touractivity/avail/cityss/2013-04-12

You can test the SOAP service using soapui. The wsdl location is http://localhost:8092/soap/touractivity?wsdl.Try sending this soap message:

   <soapenv:header>
   <soapenv:body>
      <ns:ota_touractivityavailrq target="Production" timestamp="2012-04-19T05:16:51.353Z" version="1.0" xmlns:ns="http://www.opentravel.org/OTA/2003/05/common">
         <ns:touractivity>
            <ns:basicinfo touractivityid="CITYSS">
            <ns:schedule>
               <ns:starttime gt="" lt="" ns:starttime="">
            </ns:starttime></ns:schedule>
            <ns:participantcount quantity="1">
         </ns:participantcount></ns:basicinfo></ns:touractivity>
      </ns:ota_touractivityavailrq>
   </soapenv:body>
</soapenv:header>

Your response should look something like this:


Voilà

Monday, November 26, 2012

opentravel web service test suite

If you're a travel industry developer writing an opentravel client for any platform or language, you will need a test web services server as part of your development infrastructure.

The open source JiBX project contains tools for web services development, including a complete xml to java binding for the opentravel message schema.

When you combine the JiBX tools with an open source web services platform such as servicemix and the tools available for java, you have an excellent platform for testing your opentravel messaging.

Let's start with the JiBX web services framework. Click on this link, and follow the directions to set up your web service.

If you need help setting up your test environment, take a look at this blog entry for step-by-step instructions on setting up a JiBX maven project in eclipse.

Now you're ready to customize your test code. Let's start with the code from our repository.

Take a look at this source code. In the res and resmodify method you will see some code like this:
Properties properties = new Properties(); properties.setProperty(BaseClient.FILENAME, "/OTA_HotelResRS.xml"); properties.setProperty(BaseClient.CLASSNAME, ResRQ.class.getName()); if (request.getOTAPayloadStdAttributes() != null) if (request.getOTAPayloadStdAttributes().getEchoToken() != null) if (request.getOTAPayloadStdAttributes().getEchoToken().startsWith("/")) properties.setProperty(BaseClient.FILENAME, request.getOTAPayloadStdAttributes().getEchoToken()); response = (ResRS)this.createMessage(properties);
This code is using the framework's ability to read a local message and marshal it to a Java object. You will see that all that is needed is the message class and location (You will find this message in the https://github.com/jibx/schema-library/tree/master/org.opentravel/_2012A/opentravel-ws/opentravel-hotel-ws-test-service/src/main/resources directory). In this test scenario I also have the option to pass the pathname of the the response message in the request message's echotoken attribute.
If you look at the checkpaymentcard method, you can see the power of using java objects to test for xml elements. This would be difficult to do in XPATH or DOM.
public void checkPaymentCard(PaymentCard paymentCard) { if (paymentCard.getSeriesCode() != null) System.out.println("Good - Card info good"); else System.out.println("Error - Card info not good"); }
The utilities in the JiBX web services test suite can be used in the client and service modules. For a description of the other utilities, see my opentravel client test suite blog.
Cheers!
Don Corley
don@tourgeek.com

opentravel web services client test suite


If you're a travel industry developer writing an opentravel service on any platform or language, you will need a test web services client as part of your development infrastructure. Your client will send various messages to your service and then verify that the responses are correct.

The open source JiBX project contains tools for web services development, including a complete xml to java binding for the opentravel message schema.

When you combine the JiBX tools with all the of tools available for the java platform you have an excellent platform for testing your opentravel messaging.

Let's start with the JiBX web services client framework. The client framework is very flexible. It can be used by your client application, or used as a test platform. We'll be running our tests using the maven framework, but you can easily use straight java or run your tests in an OSGi container.

Now we're ready to customize our test code. Let's start with the code from our repository at: https://github.com/jibx/schema-library/tree/master/org.opentravel/_2012A/opentravel-ws/opentravel-hotel-ws-test-client. You should download this project and use it as your starting point.

Take a look at this source code here. Notice this source code in the start method:

Properties properties = new Properties();
properties.setProperty(ENDPOINT, endpoint);
properties.setProperty(FILENAME, "/OTA_HotelResRQ.xml");
properties.setProperty(CLASSNAME, ResRQ.class.getName());
runTest(properties); // By default, run the test once with no properties


This code is using the framework's ability to read a local message and marshal it to a Java object. You will see that all that is needed is the java class name and the message location (You will find these xml messages in the project's resource directory).

If you prefer unit tests, this project also contains a maven junit test. The source code is here.

If you scroll to the bottom of this code, you will see the checkResponseMessage method. You will notice that this method converts the java object to an xml string and prints it. It also converts the message to a DOM tree and does a test. The last line does an XPath test on the xml message.

This client code inherits code from the web services Utilities java class. Take a look at this code for the available tools.


This should be everything you need to write a web services client or a web services client test suite.
Don Corley
don@tourgeek.com

Friday, November 16, 2012

Creating an opentravel SOAP client and server for testing using soapui

If you are creating a web services client or server in the Travel Industry, you are probably using the opentravel messaging schema.

Sometimes the most difficult part of your project is creating a test client or server to verify your application code.

soapui is a great open source utility for easily creating manual and automated SOAP test suites.

I'm going to show you how to quickly set up a SOAP test client and a SOAP test server for an opentravel message pair using soapui.

The first thing you will need is a WSDL file. Luckily the ota-tools project has many open source resources for opentravel users, including a soapui project with sample WSDL file that we can use as a template.

You can download this WSDL file from the ota-tools source repository at:

This WSDL is currently configured for the 2012A version of the Ping message pair. If you would like to use a different message pair, just change the import statements to point to your root schema.

For example, if I want to test the cancellation message pair, I would change:

<xsd:import namespace="http://www.opentravel.org/OTA/2003/05"
  schemaLocation="http://www.opentravel.org/2012A/OTA_PingRQ.xsd" />
<xsd:import namespace="http://www.opentravel.org/OTA/2003/05"
  schemaLocation="http://www.opentravel.org/2012A/OTA_PingRS.xsd" />
to:

<xsd:import namespace="http://www.opentravel.org/OTA/2003/05"
  schemaLocation="http://www.opentravel.org/2012A/OTA_CancelRQ.xsd" />
<xsd:import namespace="http://www.opentravel.org/OTA/2003/05"
  schemaLocation="http://www.opentravel.org/2012A/OTA_CancelRS.xsd" />

Then change the message root elements to match the root elements of the schema that you are testing. In this example, I would change:

<wsdl:message name="Request">
<wsdl:part element="ota:OTA_PingRQ" name="payload">
</wsdl:part>
</wsdl:message>
<wsdl:message name="Response">
<wsdl:part element="ota:OTA_PingRS" name="payload">
</wsdl:part>
</wsdl:message>
 
to:

<wsdl:message name="Request">
<wsdl:part element="ota:OTA_CancelRQ" name="payload">
</wsdl:part>
</wsdl:message>
<wsdl:message name="Response">
<wsdl:part element="ota:OTA_CancelRS" name="payload">
</wsdl:part>
</wsdl:message>

Now you are ready to create a test client and server in soapui.

From the soapui main menu, select, File -> New soapui Project

In the dialog box, click the browse button and open the wsdl file that you just edited:

Give your project and name and click 'OK'

Generate a default service

and give it a name:

Now you are ready to start your mock service. Click on the green 'Go' button in the upper left. Now your service is running and you can call it from soapui or the opentravel client that you are developing.

Now let's test our service. Open the sample request and,

press the green 'Go' button in the upper left. You should have a response message on your screen.
 Voilà!

Now you are ready to add some logic to your soapui test server and create a soapui client test suite. You will find a nice project with examples in the ota-tools soapui project.

This sample project is located in our source repository at:

Just download the opentravel-soapui-project.xml file and import it into soapui.

Now you're ready to test your opentravel client or server code!






Tuesday, September 18, 2012

Opentravel Mobile Android App development with the JiBX open source framework

This example demonstrates how easy it is to create an Android app that can communicate with travel sites using the opentravel.org message schema.

The JiBX open source project is a java data-binding utility that simplifies handling of xml schema. The JiBX schema library includes pre-built bindings for many message schema, including the complete opentravel schema.

This app uses the 2011B version of the opentravel touractivities search request and reply.

Here is what this app looks like on my phone. Select a date and the available tour activities will display:
Tap on a tour for a detail display:


To illustrate what is happening, let's jump right into the actual source code. I create an opentravel xml touractivity search request and then read through the returned xml reply message.

// Populate the search request
SearchRQ searchRQ = new SearchRQ();
OTAPayloadStdAttributes payload = BaseService.createStandardPayload();
searchRQ.setOTAPayloadStdAttributes(payload);
DateTimePref dateTimePref = new DateTimePref();
searchRQ.setDateTimePref(dateTimePref);
dateTimePref.setStart(YMDdate);
dateTimePref.setEnd(YMDdate);

// Send it to the server and get the result
SearchRS searchRS = search(searchRQ);
if (searchRS == null)
return null;

// Extract the information from the results
List tourProducts = new Vector();
List tourActivities = searchRS.getTourActivityInfoList();
if ((tourActivities == null) || (searchRS.getErrors() != null))
return getErrorMessage(searchRS);
for (TourActivityInfo tourActivityInfo : tourActivities)
{
TourInfo tourInfo = new TourInfo();
TourActivityID tourActivityID = tourActivityInfo.getBasicInfo();
tourInfo.tourID = tourActivityID.getTourActivityID();
TourActivityDescription tourActivityDescription =  tourActivityInfo.getDescription();
if (tourActivityDescription != null)
tourInfo.description = tourActivityDescription.getShortDescription();
Pricing pricing = tourActivityInfo.getPricing();
if (pricing != null)
{
tourInfo.minPrice = pricing.getMinPrice();
tourInfo.maxPrice = pricing.getMaxPrice();
}
tourProducts.add(tourInfo);
}

// Return the tours to display
return tourProducts;

As you can see, manipulating the xml with java objects instead of xml makes the code easy to understand.

The rest of the code in this application handles the UI and the client calls. It should be familiar to any Android programmer. One of the nice features of Android is the inclusion of many popular open-source libraries, such as the Apache http Client library and the XMLPull parser.

This app is pretty simple. Setting up your development environment is a little tricky.

First, you will need a server that is set up to service your requests. Just follow the steps in my post here: http://blog.tourgeek.com/2012/04/creating-soap-and-rest-services-for.html . Make sure the server is working by pointing a browser to the server with this url (just replace this IP address with your server's IP): http://192.168.1.100:8181/cxf/touractivity/search/2012-09-04/2012-09-04 . You should get an XML reply message. Our app will be (html) posting a RESTful XML request rather than using url parameters.

Now we're ready to create our Android application.

Check out this example from github: https://github.com/jibx/schema-library/tree/master/schema-utilities/examples/android/org.jibx.android.demo.touractivity

I prefer maven for my Android development since it automatically includes all the correct opentravel binding modules automatically . You will need to set up maven for Android by following the directions here: http://www.sonatype.com/books/mvnref-book/reference/android-dev.html . Make sure you have deployed android 4.0_r3 into your local maven repo.

To build the code, just type:
mvn clean install

Now install your .apk file (from the maven target directory) onto your Android device.

Once you run the app, click the menu button to change the settings. Enter the IP address of your server and click okay:
You should see the tour display. Try changing the date to update the tour display (Some of the tours do not run on Tuesdays).

Voilà!

Take a look at the source code. You'll be amazed at how simple it is.

I hope this example helps you create your own app using the opentravel schema. If you have questions, contact me at don@tourgeek.com or place a comment in the space below.

Don

Wednesday, April 25, 2012

Creating SOAP and REST services for opentravel messages

I'm going to show you how easy it is to write a web service to access a travel product using open source software.

There are two parts to every software project.

First, you have to write the business logic. For example, return the price of a tour on a particular date. This is the fun part.

Second, you have to set up all the extra stuff to make your software work. Web servers, SOAP and REST configuration, etc. This is a pain.

By leveraging open source software, you can minimize the painful part.

For this example we'll assume that you are a local sightseeing company. Your customers want to be able to access real-time pricing and availability for all of our tours.

They use the opentravel 2012A Tour Activity Availability message pair using SOAP over HTTP.

This means you need a web server, a SOAP processing module, and a schema parser, as well as your code. Luckily open source software does most this.

If you're impatient and you just want this demo up and running with a just a few commands, click here for the schema library rest example.

I've created a template for your sample project. To create your project from this template, start eclipse and select:

File -> New -> Project -> Maven Project
On the Archetype screen, select the archetype: opentravel-touractivity-ws-service-archetype. If the artifact doesn't appear, click the 'add archetype' button; GroupId: org.jibx.schema.org.opentravel._2012A.ws, ArtifactId: opentravel-touractivity-ws-service-archetype, Version: 1.0.6 (Not the version show in this image)

On the Project screen, enter your group, artifact name, and version.

You can enter anything you want here. You will need your project group, artifact, and version when you deploy your project.
Click finish to build your project.

This project has two files.

The blueprint.xml file is the configuration file. This blueprint tells the system to register this service to handle opentravel touractivity messages.

The source file handles the actual messages. This code is expected to process request messages and return a response.

If you look at the source code, you will find the method:
public AvailRS avail(AvailRQ request)
I have included some sample code that returns availability and pricing for several fake tours. This is where you would access your inventory and pricing and populate the return message.
The cool part of using a java representation of the opentravel xml message is you can use all the eclipse programming shortcuts, such as auto-complete and documentation display. All the comments and xml snippets from the (complex) opentravel schema have been transferred to the java source code. Try to ctrl-click one of the request or response method names and you will be looking at the java source code model of the xml message. Nice!

To build the project, right-click the project name in the project explorer and select Run as -> Maven install

Now we are ready to deploy this code.

For this example, I'll use servicemix. You can also use any one of the enhanced esb servers such as Talend or Fuse. In fact, this code uses only open specifications, so you should be able to run it with minor configuration changes on almost any java app server.

Download servicemix, unzip, and run it:

tar zxvf apache-servicemix-4.4.2.tar.gz
cd apache-servicemix-4.4.2
bin/servicemix

Now start the RESTful server and the SOAP server. These servers are configured to send incoming messages to a service registered to handle touractivity messages. (The blueprint.xml file does this) Type these command into the servicemix console.
features:install obr
obr:addurl http://www.jibx.org/repository.xml
obr:deploy org.jibx.schema.org.opentravel._2012A.touractivity.ws.soap
obr:deploy org.jibx.schema.org.opentravel._2012A.touractivity.ws.rest
# Enter the actual group/artifact/version of your project here:
install mvn:org.jibx.schema.org.opentravel.ws/org.jibx.schema.org.opentravel._2012A.touractivity.ws.service/0.0.1-SNAPSHOT
# Note: Due to an OSGi issue, you will need to shutdown and restart servicemix here (ignore any errors on startup):
shutdown
bin/servicemix


# After it starts back up, start your services:
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.service
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.soap
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.rest

Give it a moment to start, then try out the rest service by clicking this link:
http://localhost:8181/cxf/touractivity/avail/cityss/2012-04-12

You can test the SOAP service using soapui. The wsdl location is http://localhost:8092/soap/touractivity?wsdl.Try sending this soap message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:OTA_TourActivityAvailRQ TimeStamp="2012-04-19T05:16:51.353Z" Target="Production" Version="1.0"
           xmlns:ns="http://www.opentravel.org/OTA/2003/05">
         <ns:TourActivity>
            <ns:BasicInfo TourActivityID="CITYSS"/>
            <ns:Schedule>
               <ns:StartTime>2012-05-11</ns:StartTime>
            </ns:Schedule>
            <ns:ParticipantCount Quantity="1"/>
         </ns:TourActivity>
      </ns:OTA_TourActivityAvailRQ>
   </soapenv:Body>
</soapenv:Envelope>
Your response should look something like this:
Voilà

Wednesday, December 14, 2011

XML Data Binding for Java on Android using JiBX

JiBX is an excellent tool for binding XML data to Java objects on the Android platform.

- JiBX is fast!
- JiBX has a small footprint (it will add only 60KB to your .apk)
- JiBX uses the Android XMLPull parser by default
- It's easy to use!

We all appreciate the advantages of being able to use java classes to do data manipulation. person.setFirstName("Don"); is much easier then messy DOM manipulation: document.getElementsByTagName("first").item(0).appendChild(document.createTextNode("Don"));

Let's create a sample project.

First, create java bindings for your XML schema using JiBX, or select a pre-build schema library.

For this example, we'll use a pre-built binding from the JiBX schema library. Our sample xsd file is an XML definition which includes a person's first and last name.

Click here to see our sample schema in the JiBX library. You may want to take a look at the schema and the JiBX generated java source code.

Download the java jar file by right-clicking this
link and select 'save as'.

Next, download the jibx runtime jar file by right-clicking this link and select 'save as'. We'll need these jars shortly.

Now we're ready to create our Android application. First you need to install eclipse and the Android SDK.

From Eclipse, select New -> Project -> Android Project.

I'm calling this project 'jibxapp'.

On the next screen, select your target api.


Finally, enter your java package name.


You project should appear in your workspace.

Navigate to jibxapp -> res -> layout and double-click main.xml to bring up the form editor.


Add a button, two medium static text fields, two data text boxes, and a multi-line text box so your screen looks something like this:


You may want to test your Android emulator here by right clicking the project name and selecting 'Debug as' -> 'Android Application'.

To add your java binding and the JiBX runtime, right-click your project name and select properties. Click 'java build path' -> Libraries -> 'Add external jars' and add the two jars that we downloaded earlier.


Navigate and open your Android source code file.


Add this test code to your java source file:

package org.jibx.android.test;

import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;
import org.jibx.schema.org.jibx.sampleschema.person.Person;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class JibxappActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mPickDate = (Button) findViewById(R.id.button1);
mFirstName = (EditText) findViewById(R.id.editText1);
mLastName = (EditText) findViewById(R.id.editText2);
mTextBox = (EditText) findViewById(R.id.editText3);
// add a click listener to the button
mPickDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
doJibxTest();
}
});
}

Button mPickDate = null;
EditText mFirstName = null;
EditText mLastName = null;
EditText mTextBox = null;

/**
* Add the test table records.
*/
public void doJibxTest() {
Person person = new Person();
person.setFirstName(mFirstName.getText().toString());
person.setLastName(mLastName.getText().toString());


String xml = marshalMessage(person);
mTextBox.setText(xml);

Person personOut = (Person) unmarshalMessage(xml);

mPickDate.setText(personOut.getFirstName() + ' ' + personOut.getLastName());
}

/**
* Marshal this message to xml .
*
* @param message
* @param system
* @return
*/
public final static String STRING_ENCODING = "UTF8";
public final static String URL_ENCODING = "UTF-8";
String bindingName = "binding";

public String marshalMessage(Object message) {
try {
IBindingFactory jc = BindingDirectory.getFactory(bindingName, Person.class);
IMarshallingContext marshaller = jc.createMarshallingContext();
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.marshalDocument(message, URL_ENCODING, null, out);
return out.toString(STRING_ENCODING);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (JiBXException e) {
e.printStackTrace();
}
return null;
}

/**
* Unmarshal this xml Message to an object.
* @param xml
* @param system
* @return
*/
public Object unmarshalMessage(String xml) {
try {
IBindingFactory jc = BindingDirectory.getFactory(bindingName, Person.class);
IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext();
return unmarshaller.unmarshalDocument(new StringReader(xml), bindingName);
} catch (JiBXException e) {
e.printStackTrace();
}
return null;
}
}


This program takes the First and Last Name entered, plugs them into a java data object, marshals the object to xml, and unmarshals the xml back to a data object and extracts the data from it. I made this program very simple, of course you would not do this kind of processing in the main thread.

Run your application by right clicking the project name and selecting 'Debug as' -> 'Android Application'. Enter your first and last name and click the button on the top.


Voilà!

Monday, January 31, 2011

Installing git-web on a java web server

Installing git-web on a java web server such as tomcat or jetty is pretty simple. All java web-servers have the capability to run cgi scripts such as git-web.

The difficult part of installing git-web is setting up all the configuration.

First, install git-web using your linux installation tool such as yast, yum, rpm, etc. Your install will assume you will use the apache web server.

Now for the hard part. Every linux distro installs the files in different locations. Here is where my files are installed:
The git-web config file:
/etc/apache2/conf.d/gitweb.conf (This tells git-web where your repositories are)
The git-web install directory:
/usr/share/git-web (The git-web cgi script and web files)

The next step is to get git-web working. There are a ton of tutorials out there. Most of them are pretty bad. I would just open up the gitweb.cgi file in a text editor and edit the parameters.

You will probably want to change the $projectroot variable to point to your git repository location.

Once you get git-web working, you are ready to install it in your java web server.

First, create a war directory (mine is called git-web) and move the git-web files to these locations:


Next, create the web.xml file in the WEB-INF directory. It should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi-bin</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/gitweb.cgi</url-pattern>
</servlet-mapping>
</web-app>

Voila! Install this war location on your java web server and git-web is ready to go: