Updates from October, 2009 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 11:46 am on October 29, 2009 Permalink |
    Tags: , , , ,   

    Coding is fun. Really :D 

    I used to put some stupid test cases to unit-test my code and I usually don’t forget to remove ’em before review. But last time when my customer reviewed my code, he found the following segment at the end of a Java file. He laughed and asked “Is that true Subin?” 😀

    //------------------------ Test methods ---------------------------
    
    static class TestClass
    {
     public TestClass(String name)
     {
     this.name = name;
     }
    
     private String name;
    
     @Override
     public boolean equals(Object anObject)
     {
     return (true);
     }
    
     @Override
     public int hashCode()
     {
     return (1);
     }
    }
    
    public static void main(String[] args)
    {
     Set<TestClass> aSet = new HashSet<TestClass>();
     aSet.add(new TestClass("Subin "));
     aSet.add(new TestClass("is in "));
     aSet.add(new TestClass("a "));
     aSet.add(new TestClass("big "));
     aSet.add(new TestClass("big "));
     aSet.add(new TestClass("trouble"));
    
     System.out.println(aSet.size());
    }
    
     
  • Subinkrishna Gopi 3:26 pm on October 13, 2009 Permalink |
    Tags: , , , , , ,   

    How-to: Write web services using Axis2 (Part 2) 

    In my previous post I wrote about writing a web service provider using axis. But I did not mention a few things in that post.

    1. How to make the service accessible to the outside world
    2. How to write a Java client to avail the services

    1. How to make the service accessible to the outside world?

    As we are using the axis2.war as the way to deploy the services, we don’t really need to do anything. The deployment descriptor (web.xml) of axis2.war is equipped to handle it. But we need to make some URL mapping and stuffs like that.

    • Add appropriate URL-servlet mapping  in the web.xml
    • Add the name of the AAR in the service list

    a. Deployment descriptor changes:

     <servlet>
       <servlet-name>AxisServlet</servlet-name>
       <display-name>Apache-Axis Servlet</display-name>
       <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
     </servlet>
    
     <servlet-mapping>
       <servlet-name>AxisServlet</servlet-name>
       <url-pattern>/servlet/AxisServlet</url-pattern>
     </servlet-mapping>
    
     <servlet-mapping>
       <servlet-name>AxisServlet</servlet-name>
       <url-pattern>/services/*</url-pattern>
     </servlet-mapping>
    

    b. Add the name of the AAR in WEB-INF/services/services.list.

    2. Writing a Java client to access the services

    We have several ways to create the client stubs – JiXB, ADB etc. I followed ADB – Axis Data Binding. Axis provides a WSDL2Java tool to create client stubs from an existing WSDL. We can get the WSDL from http://localhost/services/SampleWs?wsdl.

    WSDL2Java -uri SampleWs.wsdl -p subin.rnd.ws.client -d adb -s -o clientStubSrcDirectory_name

    This will create the stub in the specified directory with name SampleWsStub.java. Once the stub is ready, we can write a client module which tries to access the deployed services.

    WsClient.java

    package subin.rnd.ws.client;
    
    import subin.rnd.ws.client.SampleWsStub.WsInput;
    import subin.rnd.ws.client.SampleWsStub.WsOutput;
    
    public class WsClient
    {
     public static void main(String[] args)
     throws Exception
     {
       SampleWsStub stub = new SampleWsStub("http://localhost/services/SampleWs");
    
       // Send the request
       SampleWsStub.DoSomething request = new SampleWsStub.DoSomething();
       WsInput anInput = new WsInput();
       anInput.setName("subin");
       request.setAnInput(anInput);
    
       // Get the response
       SampleWsStub.DoSomethingResponse response = stub.doSomething(request);
       WsOutput anOutput = response.get_return();
    
       System.out.println(anOutput.getResponseString());
     }
    }
    

    And that’s it !!!

     
  • Subinkrishna Gopi 10:47 am on October 6, 2009 Permalink |
    Tags: , , , , , ,   

    Todays read: Mastering CSS Coding 

    Mastering CSS Coding: Getting Started

    An amazingly simple and useful article from Smashing Magazine.

    CSS has become the standard for building websites in today’s industry. Whether you are a hardcore developer or designer, you should be familiar with it. CSS is the bridge between programming and design, and any Web professional must have some general knowledge of it. If you are getting your feet wet with CSS, this is the perfect time to fire up your favorite text editor and follow along in this tutorial as we cover the most common and practical uses of CSS.

    Read it here: http://www.smashingmagazine.com/2009/10/05/mastering-css-coding-getting-started/
    Follow them in twitter

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel