Translate

Writing a simple web service and a client with Axis2

1. The service

Here a simple POJO service will be created. For simplicity the service will have only two operations.

1. Save an order which consists of an index(String) and a price(Double)
The order will be saved to an xml file.

2. Retrieve the price given the index.



First create a Java Project.

Now inside package orderprocessing.data I create the Order POJO.

Inside the package orderprocessing.service I create OrderProcessingService Class.

In order to save orders to an XML file I create XMLWriterDOM.java.
To retrieve orders from the XML file I create XMLReader.java
Create an XML file orders.xml somewhere and change the "savePath", and "retrievePath" attributes inside the above two classes according to that.


Now create a folder META-INF at the src folder level and create services.xml inside META-INF.

Here, If you do not specify the message receiver, then the default message receiver which is RawXMLINOutMessageReceiver will perform the operation[1]

And since the service implementation class is in Java, all the public methods in that service will be exposed. No need to specifically include them in services.xml[1]


This is the folder structure of my service.


Now export the project as a jar. In eclipse this can be done by, right click on the project->export
Save it to somewhere and change it's extension to .aar (eg: if your jar is OrderProcessingService.jar rename it as OrderProcessingService.aar ) and save it to axis2-1.6.2/repository/services
(I am using axis2-1.6.2)

Start the axis2server. (In linux run axis2server.sh inside axis2-1.6.2/bin)



Now if you go to http://localhost:8080/axis2/services/ it should be shown as below.



And you can access the wsdl at, http://localhost:8080/axis2/services/OrderProcessingService?wsdl


2. The client

Create another Java project.

Now in order to use the service we need to create the stub.

Go to axis2-1.6.2/bin in the terminal and run,
Now create another package orderprocessing.client inside your client project and create OrderProcessingClient.java

This is my folder structure of the client

Run the client and see if it works.

Making SBT(Simple Build Tool) use JDK 7 having both JDK 7 and 8 installed

I was following a scala tutorial and I was using SBT as the build tool. This SBT version required JDK 7 but I had environmental variables set for JDK8 even though I had both installed on my machine.

To make SBT use JDK7 without changing JAVA_HOME environmental variable, this is what I did.

First created a new environmental variable JAVA_HOME7(any name which is not already being used) with the path to JDK7 as the value.

Then replaced JAVA_HOME in the sbt.bat file(which is inside the sbt folder inside program files folder) with JAVA_HOME7.

MATLAB - Applying a function for each element in an array using arrayfun

I'm not a big matlab fan. For a project I needed to apply a function for each element in an array. For that arrayfun can be used.

Here is a simple example.

Say you have 3 arrays as follows.

A = [1,2,3,4]
B = [5,6,7,8]
C = [9,10,11,12]

And you need to calculate the value of a function myf, for A[i], B[i] and C[i] (i=1,2,3,4) which returns A[i] x B[i] + C[i]

You can do it as follows.

First define your function considering a single element.

function output=myf(a,b,c)
  output=a*b + c;
end

Then,

A = [1,2,3,4]
B = [5,6,7,8]
C = [9,10,11,12]

D = arrayfun(@myf,A,B,C)


Remember to have "@" before myf. It denotes a handle in matlab. If you forget it, matlab will try to evaluate the function instead of considering its handle, which may result in "Not enough input arguments" error.



Because a bit of Art must be a part :) - No 2

The Cycle

He cried in a rhythm when he was born
It’s the joke among his peers
When he sings the wind slows down
Hares freeze and turn their ears

He is singing, just singing
He never knew the meaning of the song
He doesn't try, he never did
Bewitching the world, sings along

Charming young ladies,
Dancing like glimmering flames
Neither they ever knew
What’s the meaning? Is it deep or lame?

The lyricists, did they know?
Their only aim, do words rhyme?
Are they hollow, are they rich?
Who cares? It’s not a crime

Some wrote, he sang, all danced
The cycle went on and on…
No one asked why,
‘cause no danger was yet known…

Scroll to a given item in a dataview - Sencha Touch

In my Sencha Touch app I had a component dataview. I had included an index bar and I needed to scroll to the relevant items when I click on index bar. This is what I did.

Here recordIndex is the index of the component in dataview that we need to scroll to.

Adding a custom theme for the android preview screen in a Sencha Touch - Cordova app

In android on app launch, a preview screen is shown. This is before the splash screen. In a Sencha - Cordova app even if we have added the splash screen plugin, before the splash screen this preview window will appear. In my last post I have written how to change the theme of this preview screen in a pure Sencha Touch app. Here I'm writing how to add a custom theme for Sencha Touch+cordova app.

First create an xml file inside,

project-folder/cordova/platforms/android/res/values

The name of the XML file could be anything. Let's call it themes.xml. Then define your theme inside it.

Eg:
I'm going to override the NoTitleBar theme.. To do that this is what we should put inside themes.xml

Now, in the android manifest XML file which is inside,

project-folder/cordova/platforms/android

change the theme as follows.
android:theme="@style/MyTheme"



Black screen before splash screen in Sencha Touch android app?

I built a native Sencha Touch app using Sencha cmd.

I was having a problem. When I open the app before my splash screen loads a black screen was appearing. I found that the reason for this black screen is that on app launch, Android displays a simple preview window (based on your activity theme) as an immediate response to the user action. Then the preview window crossfades with the actual UI, once that has fully loaded [1].  


I could not find a "nice" way to get rid of this black preview window. This is the only solution I found.

1. Go to AndroidManifest.xml inside the path_to_sencha_cmd/Sencha/Cmd/4.0.4.84/stbuild/st-res/android/
(I was using the version 4.0.4.84. The path depends on that.)

2. Inside application tag change the theme as android:theme="@android:style/Theme.Light"

If you do not want the title bar use this instead of the above one.
android:theme="@android:style/Theme.Light.NoTitleBar"

I don't think this is a good way to solve the problem. But I could not find a better way rather than changing Sencha cmd code.


References

[1] https://plus.google.com/+AndroidDevelopers/posts/VVpjo7KDx4H