четверг, 28 марта 2013 г.

Tricky Swagger

Hello.
I was faced with a task to create a documentation for our new developing REST service. Search revealed two technologies at hand: JSON-WSP and Swagger.
I liked more Swagger,  because:
1) I can dynamically define documentation with annotations in java
2) relatively simple syntax allows to define the documentation by hand
3) there is a good application Swagger UI which allows to explore the service documentation and more important play with your api.

So here are some tricky moments I was faced during the development of specification and using Swagger UI:
1) If you use Swagger UI with documents other than English then you have to insert into Swagger UI index file the meta 'Content-Type' tag.
2) For your convenience set the 'discoveryUrl' in Swagger UI to your resource listing file.
3) When developing the documentation by hand check your json with validators like http://jsonlint.com/. Because errors in Swagger UI are not displayed.
4) When defining parameters in spec you can use path, query, body, or header AND form. The latter allows you to send json into multipart request. The 'form' argument is not mentioned  in https://github.com/wordnik/swagger-core/wiki/Parameters.
5) When defining you api you should point out the 'responseClass'. If you want your method to return an array of objects you can use the following construction: responseClass: 'List[Item]', where Item is your domain model. This moment is not well documented in documentation.

That's all for now.

среда, 13 марта 2013 г.

OCAJP 7 Passed!

Today I successfully passed Oracle 1Z0-803 and earned OCA level. I got 95%. Good result.
For preparation I used tests from http://enthuware.com/. It is a good buy for your money. If you can pass enthuware test, then you can pass the real exam.

понедельник, 4 марта 2013 г.

Setup new version of xalan and xerces libs on WebSphere Portal 6.0

1) login as root
2) mkdir /opt/endorsed.
3) copy
xalan-2.7.1.jar
serializer-2.7.1.jar
xml-resolver-1.1.jar
xercesImpl-2.8.1.jar
xml-apis-1.3.04.jar
to /opt/endorsed.
4) open /opt/IBM/WebSphere/AppServer/bin/startServer.sh.
5) find #Common args...
D_ARGS="-Dws.ext.dirs="$WAS_EXT_DIRS" $DELIM -Dwas.install.root="$WAS_HOME" $DELIM -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager $DELIM -Djava.util.logging.configureByServer=true"
6) replace with
D_ARGS="-Djava.endorsed.dirs=/opt/endorsed -Dws.ext.dirs="$WAS_EXT_DIRS" $DELIM -Dwas.install.root="$WAS_HOME" $DELIM -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager $DELIM -Djava.util.logging.configureByServer=true"

7) restart portal.
Now identity transformation will work as expected.

вторник, 19 февраля 2013 г.

Apache CXF integration testing

Sometimes it is necessary to make the test of web-service client and service.
If you have an Apache CXF service and client then you can try to use local transport for your test.
So, here is an example.

The client you define like this:
 <jaxws:client id="client" serviceClass="IIdentificationService"  address="local://test"/>.

And here is how you test the integration:

IIdentificationServiceImpl impl = new IIdentificationServiceImpl();
Endpoint ep = Endpoint.publish("local://test", impl);
IIdentificationService client = (IIdentificationService) context.getBean("client");
Result res = client.call("123");
ep.stop();


What is important here is the address of endpoint and client. Both uses the prefix "local". This means that messages will transport inside the JVM.
For reference see http://cxf.apache.org/docs/local-transport.html.

четверг, 14 февраля 2013 г.

Challenges in WS development


1) Work with large and user base.
Solution:
Audit & monitoring.
Multifactor authentication.

2) Long life cycle.
Solution:
Choose solution based on industry standards.

3) Robustness.
Solution:
Architect the solution that will work even if some of it components will go down.

4) Manageability.
Solution:
Take care at monitoring, backup, upgrade.

 5) Integration with legacy applications.
Solution:
Look for interface of other applications.

WS stack technologies review

Recently I started to invest time in learning of web services.
I have learnt the basics of WSDL 1.1.
Now I'm trying to understand other aspects of WS. Where are a lot of WS-* technologies. Some of them are obsolete, some are not supported. So the aim of this post is to understand the widely adopted specifications and the possible use cases for them.

воскресенье, 10 февраля 2013 г.

Ajax and ActiveMQ

Sometimes you need to notify users (browsers) about some events occurred on the server side. For example someone has added the row into the table and you need to be notified about it.
Also the client could be not just the browser but any program component. And this components can be dynamically connected and disconnected.
The solution could be the message queue and publish subscribe pattern.
 After some research I managed to work the solution based of ActiveMQ 5.7.0 and Apache Tomcat 6.0.35. Here is how I did it.

пятница, 8 февраля 2013 г.

JStree AJAX lazy loading and submitting of selected nodes to server

Sometimes your need to work with trees.
After some time of research I could find 2 implementations of javascript trees: jsTree (http://www.jstree.com/) and Dynatree (http://code.google.com/p/dynatree/).

I could only try jsTree because of limited time.
So, here are my requirements:
1) lazy loading of selected nodes. It's because tree size can be quite big. And store all the tree is unnecessary.
2) one can choose any number of nodes and submit selected nodes of the tree to server.

четверг, 24 января 2013 г.

Thoughts after reading "Practical TDD and Acceptance TDD for developers"

TDD for web applications

After reading the book «Practical TDD and Acceptance TDD fot developers» I decided to write some thoughts about testing.

TDD Steps

  1. Write the Test.
  2. Write the code that will pass the test.
  3. Refactor the test and the code. Watch carefully what dependencies can be eliminated or restructed.
The real question is how to write code that can be tested? Not how to test the written code. If code can't be tested — nobody needs such code.

Therefore when writing the code one should rely on the technical solutions that allow you to test the code.

Testing servlets

There is no universal solution to testing the servlets.

The main obstacle — how to make servlet that it could support dependency injection.
Following choices are available:
  • use the interface HttpRequestHandler from Spring library,
  • use methods get and set for setting the dependencies.

Unit testing database access code

How to test jdbc? One can test the code that use the services to access the data or the code that directly work with database.
One can use spring jdbctemplate or hibernate. Along with it you can use EasyMock for testing the code, that access the database.

Hibernate allows you to offload from controlling the differencies in SQL among the databases. Also it looks for opening and closing the resources

Testing database access code in memory database

Testing in HSQLDB. Hibernate settings:
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:mem:testdb
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create-drop

Automating database schema configuration

Solutions: http://dbdeploy.com/ , http://www.liquibase.org/.
Testing Database access code: http://dbunit.sf.net .

Testing code working with files

For working with files it is better to use http://commons.apache.org/vfs/.
One can use RAM filesystem for unit testing.

Testing code dealing with time

One of the solutions is to create your onw interface and substitute different implementations on the demand. Also you can take a look at joda-time library. Also watch for the strategy pattern.

четверг, 17 января 2013 г.

Axis 2 basic authentication on client

Some time ago I need to connect to web-service which use HTTP basic authentication. I had an Axis 2 client. So, here what I did:
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setPreemptiveAuthentication(true);
auth.setUsername(login);
auth.setPassword(password);
stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE,auth); 

Now you can connect to protected services.