Java and Soap

Since JDK 6 you have built in support for SOAP (SAAJ ).

There are many services that still use it, therefore consuming soap service is always usefull.

By creating a SOAP message you can add some attributes to the evlelop.

    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        soapMessage.getSOAPHeader().detachNode();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.setAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema");
        envelope.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
    } catch(SOAPException e) {
        e.printStackTrace();
    }

Then you can add your elements to the soap body.

    try {

        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(envelope.createName("Connect" , "ns1", ""));                                                      
        SOAPElement findItem = bodyElement.addChildElement("ItemName");
        findItem.setAttribute("xsi:type", "xsd:string");
        findItem.setTextContent("JAX-WS");

    } catch(SOAPException e) {
        e.printStackTrace();
    }

After you are done you can use SOAPConnection to send your message and get the response as a SOAP message.

    try {

        SOAPConnection soapConnection = SOAPConnectionFactory.newInstance().createConnection();
        SOAPMessage returnMessage = soapConnection.call(soapMessage,serverUrl);
    } catch(SOAPException e) {
        e.printStackTrace();
    }

Git repositories through ssh.

So you have an ssh server?
Great!!! Time to setup some git repos.

If you don’t already have a git user and git installed

sudo adduser -m git
sudo apt-get install git

You can use the git account either through normal password authentication or by using private and public ssh keys. Your choice 🙂

Then set up the repo.

cd /home/git/
mkdir mygit.git
cd mygit.git
git --bare init

And you are ready to go.
Open a terminal on your pc and just do

git clone git@yourserverip:/home/git/mygit.git

In order to share the project with other users you can share the project with a specific group, for example the ‘developers’ group.

chgrp -R developers gitrepo
chmod -R g+swX gitrepo