Create a Web Service Client with JAX-WS

This example shows how to create a web service client using JAX-WS reference implementation and its tool 'wsimport'. JAX-WS RI can be downloaded from Sun (http://java.sun.com). To create the web service client we need an existing web service, so we will use the one created in the example 'Create a simple Web Service': Click here to go to the 'Create a simple Web Service' example So we assume the web service is deployed on our local computer and it listens to port 8080. Go to the bin directory in the jax-ws ri installation directory and run the command wsimport.bat (if Windows, else wsimport.sh) and pass the url to the wsdl-file as a parameter. wsimport http://localhost:8080/JavaDbExamplesWeb/JavadbWebServiceService?WSDL There are a number of options you can pass to the wsimport utility so you might want to run wsimport -help to find out more. For example, you might want to use the option -keep to prevent the wsimport utility to delete the .java files after compilation. Now the utility has read the wsdl-file, created the necessary classes and compiled them for us to use. We can now create the class that will use them and call the web service.

package com.javadb.examples;

import com.javadb.ws.example.JavadbWebService;
import com.javadb.ws.example.JavadbWebServiceService;

/**
 *
 * @author www.javadb.com 
 */
public class Main {

    public void callWebService() {

        /* Note, the JavadbWebServiceService class has two constructors.
         * The default one that we use here uses the wsdl-location that was
         * specified at the time of the generation of the client classes, 
         * i.e. localhost. If the service is deployed at 
         * another location you need to use the constructor:
         * public JavadbWebServiceService(URL wsdlLocation, QName serviceName)
         */
        JavadbWebServiceService service = new JavadbWebServiceService();
        JavadbWebService port = service.getJavadbWebServicePort(); 
        
        String currentTime = port.getTime();
        
        System.out.println("Current time is: " + currentTime);
        
        
    }

    public static void main(String[] args) {
        new Main().callWebService();
    }
}
Note that you need the genereated classes and the jax-ws libraries in the classpath when you compile and run the above class. That is easiest done by pointing them out in your project properties in the IDE. The output looks something like this: Current time is: 15:54
Read More... Create a Web Service Client with JAX-WS

Create a simple Web Service

This code example shows how to create a simple web service. We use the annotation @WebService to declare the class as a such. The annotation @WebMethod is provided at method level to declare it as an operation for the web service. The operation getTime of the JavadbWebService simply returns the current time.
package com.javadb.ws.example;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.jws.WebMethod;
import javax.jws.WebService;

/**
 *
 * @author www.javadb.com 
 */

@WebService()
public class JavadbWebService {
    
    @WebMethod
    public String getTime() {
        
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        return (sdf.format(calendar.getTime()));
        
    }

}
The result of a call to the operation getTime produces something like this: 14:15 This is the SOAP request and response to the web service:

    
    
        
    






    
        
            14:15
        
    



Article from www.javadb.com/create-a-simple-web-service
Read More... Create a simple Web Service

Using a Message Handler to alter the SOAP Header in a Web Service Client

Sometimes you need to insert information in the soap header when calling a web service. Perhaps the service needs authentication information that needs to be set. This example shows how to set the security information for a Web Service that is deployed on a Weblogic server using JAX-WS and SAAJ. First we need to create the actual handler which implements the SOAPHandler interface. Next we need to create the class that implements the HandlerResolver interface. This class decides what handlers should be called and in what specific order. The handler above is added to this class. Finally we need to add the HandlerResolver instance to the Web Service Client. By default the SOAP header is empty, but this is what we want the header to look like on the outbound call (the call to the web service):

                                   
                                        
               TestUser
               TestPassword
          
     

In our handler we need to do the implementation of a few methods but it is only the handleMessage() method that is of essence here. This is what our handler class looks like:
package com.javadb.ws.example;

import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

/**
 *
 * @author www.javadb.com
 */
public class HeaderHandler implements SOAPHandler {

    public boolean handleMessage(SOAPMessageContext smc) {

        Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        if (outboundProperty.booleanValue()) {

            SOAPMessage message = smc.getMessage();

            try {

                SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
                SOAPHeader header = envelope.addHeader();

                SOAPElement security =
                        header.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

                SOAPElement usernameToken =
                        security.addChildElement("UsernameToken", "wsse");
                usernameToken.addAttribute(new QName("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

                SOAPElement username =
                        usernameToken.addChildElement("Username", "wsse");
                username.addTextNode("TestUser");

                SOAPElement password =
                        usernameToken.addChildElement("Password", "wsse");
                password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
               password.addTextNode("TestPassword");

                //Print out the outbound SOAP message to System.out
                message.writeTo(System.out);
                System.out.println("");
                
            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            try {
                
                //This handler does nothing with the response from the Web Service so
                //we just print out the SOAP message.
                SOAPMessage message = smc.getMessage();
                message.writeTo(System.out);
                System.out.println("");

            } catch (Exception ex) {
                ex.printStackTrace();
            } 
        }


        return outboundProperty;

    }

    public Set getHeaders() {
        //throw new UnsupportedOperationException("Not supported yet.");
        return null;
    }

    public boolean handleFault(SOAPMessageContext context) {
        //throw new UnsupportedOperationException("Not supported yet.");
        return true;
    }

    public void close(MessageContext context) {
    //throw new UnsupportedOperationException("Not supported yet.");
    }
}
The handler resolver that is to contain the SOAP handler above looks like this:
package com.javadb.ws.example;

import java.util.ArrayList;
import java.util.List;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.PortInfo;

/**
 *
 * @author www.javadb.com
 */
public class HeaderHandlerResolver implements HandlerResolver {
    
public List getHandlerChain(PortInfo portInfo) {
      List handlerChain = new ArrayList();

      HeaderHandler hh = new HeaderHandler();

      handlerChain.add(hh);

      return handlerChain;
   }
}
Finally we need to add the handler resolver to our web service client class.
   JavadbWebServiceService service = new JavadbWebServiceService();

   HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
   service.setHandlerResolver(handlerResolver);

   JavadbWebService port = service.getJavadbWebServicePort();
        
   //Call web service
   String currentTime = port.getTime();
        
   System.out.println("Current time is: " + currentTime);
To find out how to generate the web service client classes check out this example: Create a Web Service Client with JAX-WS

This is an article from http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client
Read More... Using a Message Handler to alter the SOAP Header in a Web Service Client

Configure FTP ( Firewall ) - Windows Server 2008 R2

In the first place i tried this option :
Windows Firewall and non-secure FTP traffic Windows firewall can be configured from command line using netsh command. 2 simple steps are required to setup Windows Firewall to allow non-secure FTP traffic 1) Open port 21 on the firewall netsh advfirewall firewall add rule name="FTP (no SSL)" action=allow protocol=TCP dir=in localport=21 2) Activate firewall application filter for FTP (aka Stateful FTP) that will dynamically open ports for data connections netsh advfirewall set global StatefulFtp enable
but this only let me to connect sucessfully (with credentials), but allways gives me D ECONNABORTED - Connection aborted Erro: Failed to obtain the folder list so i search over the internet and found this tip,
You need to allow the ftp server through the firewall. The default entry in the firewall is incorrect. Assuming you already have the correct ports open, you also need to do the following: Search for 'firewall' in the start menu search Click on 'Allow a program through Windows Firewall' There is a default entry for 'FTP Server', however this is NOT the one you need. In fact, if you have a look at the windows service for the FTP server, it is invoked via svchost.exe. Click on the 'Allow another program...' button, and enter C:\Windows\System32\svchost.exe. Once you have added this entry, tick the checkbox for both Home/Work and Public profiles. This will allow you to successfully use the FTP server with the firewall turned on.
and now i can connect and get the folder list
Read More... Configure FTP ( Firewall ) - Windows Server 2008 R2

Remove aplications in Launchpad

If you upgraded to Mac OS Lion you certainly know Launchpad

, the “home for your apps” like Apple says.
A huge disadvantage of the Launchpad is that every app that is located in your Applications folder is in Launchpad. That means that you will see every .app like helper programs like uninstallers or updaters and these apps can’t be hidden easily from Launchpad because there are no such preferences.
So someone developed the Launchpad-Control




Launchpad-Control is a small tool which allows you to easily hide/unhide apps (and groups) from launchpad in Mac OS X Lion.
Update #1: This tool is now a system preference pane! No need to have an additional app on your mac. Once you open the file it “installs” itself into the system preferences where it can be found under “Launchpad”. Isn’t that great?
Features
▪ It’s a system preference pane (update #1)
▪ Displays a table with all apps that are in Launchpad
▪ Checkboxes for every app allow you to easily specify apps you want to hide or show
▪ Backups/Restores your original database file
▪ It’s completely free!
Download
Download Launchpad-Control now. It’s free!

Source: http://chaosspace.de/dev/launchpad-control-hide-apps-from-launchpad/
Read More... Remove aplications in Launchpad

Embed Code Syntax in your posts

Steps to Add it to Blogger:
To highlight your code you just need to follow this steps:

1. You need to login to you account;

2.After that, go the Blogger Dashboard ->Design->Edit HTML.

The first step is making a backup of your current theme;





3. Now you need to copy the fowling code, and this is importing, copy it to Above/Before tag.


 <link href='http://alexgorbatchev.com.s3.amazonaws.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
 <link href='http://alexgorbatchev.com.s3.amazonaws.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
 <script src='http://alexgorbatchev.com.s3.amazonaws.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/> 
 <script src='http://alexgorbatchev.com.s3.amazonaws.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
 <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>

4. Now we nee to include this scripts, copy this code to Above/Before the tag.

 <script language='javascript'>
 SyntaxHighlighter.config.bloggerMode = true;
 SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&#39;;
 SyntaxHighlighter.all();
 </script>

5. When you need to insert code, you just need to insert this tag, and paste it inside the tag:

 <pre class="brush: BRUSH-NAME">
  
 Paste Your Code Here
  
 </pre>


The "BRUSH-NAME" needs to be changes, so when your code is from a certain type, just change it to the right tag. For example, if is a xml code, change it to "BRUSH-NAME" with xml. All the code should be Escaped (Visit this Page to make your Code Escaped)

Note that there are a lot of different brush types that you can use:
• actionscript3, as3
• bash, shell
• c#, c-sharp, csharp
• coldfusion, cf
• cpp, c
• css
• delphi, pascal, pas
• diff, patch
• erl, erlang
• groovy
• java
• perl
• php
• plain
• powershell
• python
• ruby
• scala
• sql
• vb
• xml, html
The source list can be found at http://alexgorbatchev.com/pub/sh/



This is some features you can do:

This Line is Highlighted
This Line is not Highlighted
This Line is again Highlighted

You can hide the toolbar, if you want:

  
 If You observe ,there is no Toolbar
  
 

Read More... Embed Code Syntax in your posts

Add subtitles in quicktime (Mac OS)

By default Quicktime does not put the subtitles in movies. To insert subtitles when you watch movies, you must install a program called Perian.

Download - Perian Site

If we want to see movies in wmv Quictime or Mac OS have to install a necessary codec, Flip4Mac

Download – Site
Read More... Add subtitles in quicktime (Mac OS)