Tuesday, August 25, 2015

How to install Jenkins in Tomcat Apache

How to install Jenkins in Tomcat Apache

Continuous integration is now becoming a mandatory rule in Development.

With the help of tool like Jenkins and Hudson now developer can do automatically build and run Test case at predefined period.

The idea is that development errors are identified very early in the process.

ENVIRONMENT we need to install Jenkins

apache-tomcat-8.0.18 
jdk1.8.0_31  
Jenkins 1.626 (URL:- http://jenkins-ci.org/) 

Deployment Method

Their are different deployment method that can be used to run Jenkin

1- Jenkins can Run as a standalone application:

java -jar jenkins.war –httpPort=18080 –ajp13Port=18009

2- Or deploys in an application server as Tomcat:

This is the most simple method of deployment

Just copy the download jenkins.war inside your webapps folder of tomcat and restart the tomcat.

you will be able to see this screen.


Friday, August 21, 2015

How to validate WSDL file

1. Download and install Eclipse wtp

2. Open eclipse IDE

3. Start to create a new wsdl (File --> New --> other --> Web Services --> WSDL)

4. Give a name to the wsdl (you can provide the name of wsdl which needs to be validated) and click on next. Accept the default options and click on Finish.

5. You will see a design view of a new wsdl file. Move to source view by selecting "Source" tab.

6. You will see an skeleton source of the new wsdl. Just remove it. (remove all elements in the wsdl)

7. Copy the contents of your existing wsdl (Suppose it is Myservice.wsdl) and paste in the source tab.

8. Save it by selecting save button in eclipse tool bar.

9. Right click on the wsdl file and select Validate

If your wsdl has errors, those will be shown in problems pane.

Tuesday, August 18, 2015

Implement own CSS in htmlpanel inside Iframe in Google Web Toolkit (GWT)


Many times it happen we want to load external html file in iframe of GWT.
When we try to incorporate html file inside IFrame it become difficult to implement html file specific css. Reason parent GWT frame override the html css. To overcome it we can use following code of line.

Here we are using two static native method one is used to load iframe and another is to add our specific css to the html inside iframe.
private final native void fillIframe(IFrameElement iframe, String content) /*-{
    var doc = iframe.document;
  
    if(iframe.contentDocument)
      doc = iframe.contentDocument; // For NS6
    else if(iframe.contentWindow)
      doc = iframe.contentWindow.document; // For IE5.5 and IE6
  
     // Put the content in the iframe
    doc.open();
    doc.writeln(content);
    doc.close();
  }-*/;


private final native void addHeadElement(IFrameElement iframe, String cssUrl) /*-{
         setTimeout(function() {

           var body;
           if ( iframe.contentDocument ) {
             // FF
             iframe.contentDocument.designMode= "On";
             iframe.contentDocument.execCommand('styleWithCSS',false,'false');
             body= iframe.contentDocument.body;
           }
           else if ( iframe.contentWindow ) {
             // IE
             body = iframe.contentWindow.document.body;
           }

           if (body == null) {
             return;
           }

           body.className = "custom-body-classname";
           var head = body.previousSibling;
           if(head == null) {
             head = iframe.contentWindow.document.createElement("head");

             iframe.contentWindow.document.childNodes[0].insertBefore(head, body);
           }
           var fileref = iframe.contentWindow.document.createElement("link");
           fileref.setAttribute("rel", "stylesheet");
           fileref.setAttribute("type", "text/css");
           fileref.setAttribute("href", cssUrl);
           head.appendChild(fileref);
         }, 50);
       }-*/;

Make sure that we need to  call this above two static native method before using iframe concept.

This is the code which we use to insert html code in our IFrame.

final HTML htmlPanel = new HTML("

This is siddharatha

"
);
      
       FlowPanel innerBox = new FlowPanel() {
           @Override
           protected void onLoad() {
               super.onLoad();
        
               // Fill the IFrame with the content html
               
               fillIframe(iframe, htmlPanel.getHTML());
        
               // Add a HEAD element to the IFrame with the appropriate CSS
               
               addHeadElement(iframe, "siddhu.css");
           }
       };
       innerBox.getElement().appendChild(iframe);

       RootPanel.get().add(innerBox);





Monday, August 17, 2015

Calling GWT Function from JS in GWT Application

Calling GWT Function from JS in GWT Application
In our *.html file add this line of code

<script type="text/javascript" language="javascript">
 function localJavaScript() {
  var msg = window.gwtJSCall("SiddharthaDhumale");
  alert(msg);
 }
</script>

       <h1>Calling GWT Function from JS in GWT Application</h1>

       <table align="center">
              <tr>
                    
              </tr>
              <tr>
                     <button onclick="localJavaScript();">Button to execute Java function.</button>
              </tr>
              <tr>
                     <td colspan="2" style="color: red;" id="errorLabelContainer"></td>
              </tr>
       </table>
</body>
</html>
In our client side use this code

       public class TestExternalJS implements EntryPoint {
      
        public static String GWTClassFunction(String name) {
                return "HellGWTClassFunction called  " + name + "!";
               }

               public static native void exportMethod() /*-{
                $wnd.gwtJSCall = function(name) {
                 return @com.test.client.TestExternalJS::GWTClassFunction(Ljava/lang/String;)(name);
                };
               }-*/;
      
       /**
        * This is the entry point method.
        */
       public void onModuleLoad() {
              exportMethod();
             
             
       }
}




GWT Application calling JS Function written in External JS File

GWT Application calling JS Function written in External JS File
Lets create our own simple Js file named as MyJSTest.js
function count_siddhu() {
    for(var i=1; i<=3; i++) {
        alert("siddhu count "+i)
    }
}
      
In our *.html file add this line of code

<script type="text/javascript" language="javascript" src="MyJSTest.js"></script>

In our client side use this code

      
       public static native void onMyButtonClick() /*-{
     $wnd.count_siddhu();
       }-*/;
      
      
       /**
        * This is the entry point method.
        */
       public void onModuleLoad() {
              //onMyButtonClick();
              final Button sendButton = new Button("Send");         

              // We can add style names to widgets
              sendButton.addStyleName("sendButton");
             
              RootPanel.get("sendButtonContainer").add(sendButton);
             
              // Create a handler for the sendButton and nameField
              class MyHandler implements ClickHandler, KeyUpHandler {
                     /**
                      * Fired when the user clicks on the sendButton.
                      */
                     public void onClick(ClickEvent event) {
                           //sendNameToServer();
                            onMyButtonClick();
                     }

                     /**
                      * Fired when the user types in the nameField.
                      */
                     public void onKeyUp(KeyUpEvent event) {
                           if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                                  onMyButtonClick();
                           }
                     }

             
              }

              // Add a handler to send the name to the server
              MyHandler handler = new MyHandler();
              sendButton.addClickHandler(handler);
             
       }

In short

1-  Import the JS Lib in your .html file.
2-  Create a method like this:
public static native void onMyButtonClick() /*-{
     $wnd.count_siddhu();
       }-*/;

3-  Bind your button like this:
public void onClick(ClickEvent event) {
                           //sendNameToServer();
                            onMyButtonClick();
                     }

Please make sure javascript containing your function is loaded before the generated GWT javascript.




Thursday, August 06, 2015

SSL using Keytool and integrating it with Tomcat

use this command to create keystore in specific folder

C:\Certitificate>keytool -genkey -alias siddhu -keyalg RSA -keystore C:\Certitificate\siddhukeystore
fill all the necessary information it is asked

Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: siddharatha dhumale
What is the name of your organizational unit?
[Unknown]: test
What is the name of your organization?
[Unknown]: test
What is the name of your City or Locality?
[Unknown]: pune
What is the name of your State or Province?
[Unknown]: maharashtra
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=siddharatha dhumale, OU=test, O=test, L=pune, ST=maharashtra, C=IN correct?
[no]: yes
Enter key password for
(RETURN if same as keystore password):
Re-enter new password:
After this you will be able to see a file with name siddhukeystore inside C:\Certitificate folder
Verify the content using 
keytool -list -keystore C:\Certitificate\siddhukeystore
Change server.xml of Tomcat placed inside conf folder 
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="C:\Certitificate\siddhukeystore"
keystorePass="password" />

and restart server and finally check the url using https protocal.

Note: As this certificate is self authenticated it will ask the end user to add exception and allow them to move forward. 






Create WAR File for GWT project

First compile project with GWT Compile.

Go into project's war directory C:\workspace\TestGWTPRroject\war

Select all the files & folders available inside war directory.

Zip all the selected files & folders in a file called TestGWTProject.zip.

Rename TestGWTProject.zip to TestGWTProject.war.