AXIS2 + JIBX web service client step by step

Below a low level tutorial on generating web services clients based on AXIS2 and JIBX marshalling. In real world, many of this tasks can be automatized using some tool like ANT or MAVEN.

0. Required tools

1. Initial resources

  • XSD file for JIBX
  • WSDL file for AXIS2

 
service.xsd



  
    
      
        
          
            
              
              
            
          
        
        
          
            
              
            
          
        
      
    
  
  
    
      
        
          
            
              
              
              
              
            
          
        
        
          
            
              
              
            
          
        
      
    
  

service.wsdl



  
    
      
        
          
            
              
                
                  
                  
                
              
            
            
              
                
                  
                
              
            
          
        
      
      
        
          
            
              
                
                  
                  
                  
                  
                
              
            
            
              
                
                  
                  
                
              
            
          
        
      
    
  
  
    
  
  
    
  
  
    
      
      
    
  
  
    
    
      
      
        
      
      
        
      
    
  
  
    
      
    
  

Note. Character “:” changed by “_” for visualization purpouses in “service.wsdl”

2. Generate JIBX binding

[Previous tasks: copy service.xsd file on JIBX home directory]

Command line (JIBX home)

Input: java -jar xsd2jibx.jar service.xsd

Output: com/bar/foo/binding.xml, com/bar/foo/FooRequest.java, com/bar/foo/FooRequestRequestData.java, com/bar/foo/FooRequestRequestHeader.java, com/bar/foo/FooResponse.java, com/bar/foo/FooResponseResponseData.java, com/bar/foo/FooResponseResponseHeader.java

3. Java compiler

Command line (JIBX home)

Input: javac -sourcepath com/bar/foo/*.java

Output: com/bar/foo/FooRequest.class, com/bar/foo/FooRequestRequestData.class, com/bar/foo/FooRequestRequestHeader.class, com/bar/foo/FooResponse.class, com/bar/foo/FooResponseResponseData.class, com/bar/foo/FooResponseResponseHeader.class

4. Binding compiler

Command line (JIBX home)

Input: java -jar jibx-bind.jar com/bar/foo/binding.xml

Output: com/bar/foo/JiBX_com_bar_foo_bindingFactory.class, com/bar/foo/JiBX_com_bar_foo_bindingFooRequest_access.class, com/bar/foo/JiBX_com_bar_foo_bindingFooRequestRequestData_access.class, com/bar/foo/JiBX_com_bar_foo_bindingFooRequestRequestHeader_access.class, com/bar/foo/JiBX_com_bar_foo_bindingFooResponse_access.class, com/bar/foo/JiBX_com_bar_foo_bindingFooResponseResponseData_access.class, com/bar/foo/JiBX_com_bar_foo_bindingFooResponseResponseHeader_access.class

5. Generate AXIS2 client

[Previous tasks: copy service.wsdl file, binding.xml (generated on step 2) and “com” folder (generated on step 4) on AXIS2 home directory]

Command line (AXIS2 home)

Input: wsdl2java -uri service.wsdl -o build -ss -sd -g -d jibx -ssi -Ebindingfile binding.xml

Output: build/src/com/bar/foo/FooService.java, build/src/com/bar/foo/FooServiceCallbackHandler.java, build/src/com/bar/foo/FooServiceMessageReceiverInOut.java, build/src/com/bar/foo/FooServiceSkeleton.java, build/src/com/bar/foo/FooServiceSkeletonInterface.java, build/src/com/bar/foo/FooServiceStub.java

6. AXIS2 Client usage

[Previous tasks: config a Java project including all the resources generated by now, JIBX libraries and AXIS2 libraries.]

import com.bar.foo;

FooRequest fooRequest = new FooRequest();

FooRequestRequestHeader fooRequestHeader = new FooRequestHeader();
fooRequestHeader.setType("1");
fooRequestHeader.setVersion("1");

FooRequestRequestData fooRequestData = new FooRequestData();
fooRequestData.setIdObject(1);

fooRequest.setRequestHeader(fooRequestHeader);
fooRequest.setRequestData(fooRequestData);

FooServiceStub fooStub = new FooServiceStub();
FooResponse fooResponse = fooStub.foo(fooRequest);

System.out.println(fooResponse.getResponseData().getName());
System.out.println(fooResponse.getResponseData().getAttributes());

Un comentario en “AXIS2 + JIBX web service client step by step

  1. You allow it to be seem simple using your presentation but I find this topic to generally be really a thing that I think We would never understand. Seems like too complicated and extremely broad personally. I am looking forward for your forthcoming post, I’ll try and receive the hang of it!

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s