Apache CXF – JAX-WS – Simple Tutorial


A lot of Java Developers out there sees task with Web Service implementation daunting – well, nobody can blame them really, especially that it brings a lot of  complexity in development and design over the years of enterprise application development. For some though, learning it is somehow the next step in building a full blown enterprise application – Web Services – is one of the key schemes for implementing service oriented design – almost every platform available has support to the scheme, and that of course includes Java/J2EE.

In this tutorial, I will show how you will using Apache CXF to create  Web Servies using JAX-WS and the Apache CXF API to call specific service from a remote application.

  1. Building the Web Service Application : Server Side  - We need to build the application as well as the Web Services implementation code. This will be a generic WAR (Web Archive) that will house the actual implementation
  2. Building the Web Service Application: Client Side – Of course, we need to provide external clients a way for them to access the services – we will create a stub and give them out to clients for them to use the services.

FYI: I’m using Maven to simplify library definitions.

1st we create the Stub

this houses the interface and entities (Pojos) used to access the service. When you design your service – you usually create the class interfaces (reference) first and put it on another JAR file for re-distribution.

stub_1

2nd lets build the service.

We will be hosting the service from a Web Archive deployed to an application server.

POM. xml - We will be using Spring CDI and CXF – Might as well load up all the libraries needed.

server_1

We include the stub on the server as this will act as the reference of our implementation:

server_2

We now create the Service Implementation:

server_3

cxf-servlet (or beans.xml) – this is where we will call the factory that will publish the WSDL upon loading the context.

server_4

web.xml – we need to make sure that web service request will go thru CXF – since we are using its framework. Good thing about CXF is it does all the necessary binding, marshalling, unmarshalling as well as injecting the in / out interceptors.

server_5

Build and Deploy the WAR! – After deploying the war, view the context page. You should be seeing something like this:

server_6

If you manage to view the above URL – then you have successfully expose your service and can now be called by external clients

3rd we create the client app.

Now we create a standalone Java app to call the service – we will be using Spring again to context load client beans and we need include the stub so that we can have reference to the implementation.

beans.xml – create the xml and call the proxy factory bean to create the instance on runtime

client_1

Create the Client – We will now call the bean and use the reference to call the method.

client_2

4th Test! – Test your service!

You should now be able call the Service implementation!

client_3

Download the example here

With this simple example, its really a conclusive proof that creating Web Service now is just a breeze – We took advantage of Apache CXF as a service framework to simplify the development and Springs powerful CDI that almost took care the rest.

High Level Solutions Proposal – Adhoc experience


I was once challenge to create a proposal for a mid-size application that can have millions of potential users. The experience is not easy as I need to meet up with the same client over and over again to discuss the high level solution, innovations made, justify estimates, explain the overall process, expectation on both parties and what the solution will be the final solution be like after.

I will try to give out as much detail as I can, but I need to protect the integrity of my documents as well as my client.

Client Use Case: I want to create e-Learning System that will allow enthusiastic knowledge sharer to have a venue for them to teach and possibly earn.

With this client use case, I come up with a Conceptual System design. The Functional Aspects include  (note that what I’m going to show here is just a specific phase of the project):

  1. User Dashboards
  2. Learn – Venue for users that wants to learn
  3. Teach – Venue for users that wants to teach
  4. Community forum – discussions on topics, courses and other related activities
  5. Account Management – users will be able to manage their accounts using a specific sub-system
  6. Shopping Cart – Payment process
  7. Settlements – Settle accounts and payments, report generation for receipts and stubs
  8. Actual up front website of the system

What I did is separate these systems requirements and break them down to smaller manageable (yet still high level solutions) modules. I will not further elaborate how I did them but here is the screenshot of the documentation I made (with the break down). Basically, these are all intuition based, if you are knowledgable how Software Apps work – you’ll eventually end up having an idea on how to solve each specific case.

So to list all details that I did for the proposal:

  1. Details that as much as you can, can be explain or elaborated to the most non-technical person on the client side
  2. Complete Systems requirements versus technical solution
  3. list of solution and innovations (why does your solution stands out of the rest – what is special about it)
  4. Process / methodology – We need to give them a bit of how we do things and this is how effective we are – give them the benefits that they will acquire with your preferred methodology - not just your own benefit.
  5. Give them the comfortable detail they need for them to trust the solution

I tried preparing all of this items as it will give the client a better perspective and understanding on what and how are the projects will be executed:

I put up a list as of features with respect to its technical conceptual design. These features look a lot like functional ones but a closer look at each will give you the idea that they are also separated by technical implementation (how to implement each).

1_feat

Created Pre-requisites – to identify if there are features that needs to be done first before the feature is considering fully working. Description – is just the purpose of the module. Solution, Effort and Cost Driver – table that consist of the solution, explanation of effort and its cost driver.

Sample Feature breakdown – that includes, description and step by step sub-features:

feature_breakdown

Next is the cost breakdown – the cost break down is based on the average hourly rate of the developer – I wanted to make this project as formal as possible as I’m looking at it back then to be the initial pilot project and that the process established will be re-used for succeeding ones.

cost_1

effort_excel

The cost gives an overall breakdown of cost with respect to: technology stack, platform, effort resourcing and external service needed.

Technology Stack Diagram and implementation scheme – Its important that you align the methodology or at the very least, the strategy of implementation. I used Agile – and aligned its benefits and the high probably of quality result by using actual user stories.

Application Stack:

break_down

Since this is a Website: Systems Architecture (Hosting)

hosting_arch

Agile: Systems Integration Architecture / Process View

arch_sys

Traceability Matrix – Map System requirements to High Level Solution module (note that this is from a different project)

sys_vs_tech

The bottom line here is that: Give them the correct details they need for them to be comfortable with how you will do the solution and of course your depth knowledge to finish them off with the highest quality possible.

Calling SH Unix command via Java


By far, one of the most simple, yet overlooked simple solution to batch and process executions.

Running an SH via Java isn’t really hard – there’s already an existing Object Utility for it, just need to call it correctly though. Java Code:

java_code_call_sh

the samplescript.sh is a custom script I created using nano. Basically, I pass alvin jay and reyes as parameters and get them by using $1,2 and 3.

nano_script

Console Output: I manage to get the output from the output stream object of the Process.

dir_sh

Download the source code here:

Basics of all Basics – Relocate your Apache DocRoot


Sometimes, the exciting part in configuring a virtual software server (web or application) is the activity to understand how it works and how can you manipulate it the way you want. For this post, I would like to give a basic how to on relocating (or pointing) your apache to scan a specific directory as its DocRoot directory. :)

The DocRoot directory – Every PHP developer must ‘ve known or ask regarding about this. Did you ever wonder if you can customise your XAMPP/LAMP or MAMP to detect or interpret PHP files on a folder other than the docroot folder? Here is how!

Locate  httpd.conf file on the apache folder – This is where you can edit that settings!

 

1st) Go to the DocRoot line and change the location to your location

Screenshot_1_20_13_9_29_PM

 

2nd) and Edit the <directory “<location>”> with your location then

Screenshot_1_20_13_9_33_PM

 

3rd) restart!

Easy  easy easy right? Now you can put all your PHP apps there and run it smoothly by using: http://localhost <or whatever your host name is>:80 <or whatever your port is>/app <or whatever your app name is>

Screenshot_1_20_13_9_35_PM

 

 

Good Developer vs Bad Developer

Reblogged from Jelastic — Top Java and PHP Host, Java and PHP in the Cloud, Java and PHP Server Hosting, Java and PHP Cloud Computing:

This article was originally posted by Guy Nirpaz at his blog.

Good developer is an artist, a craftsman who enjoys the process of creation. Bad developer considers himself as a programmer, responsible for generating lines of code.

Good developer understands the problems of the customers. Bad developer understands only the technical problem at hand. Good developer does not define the why, but constantly strives to understand why.

Read more… 388 more words

Good developer versus bad developer