29 Haziran 2009 Pazartesi

a sample web based application

i am developping a homework web based application by using the following technologies:
  • apache tomcat 6.0.18, installed with Netbeans 6.5.1
  • toplink (with jpa annotations) for persistence, netbeans automatically creates jpa controller classes
  • jsf, using jsf framework of netbeans, netbeans automatically creates jsf classes and crud pages
  • derby database, coming bundled with netbeans and can be easily managed inside the ide
  • web services, jaxws, using netbeans facilities during development (actually independent from jpa part)
Steps for jpa part:
  1. create a web application with jsf framework added, select tomcat as server runtime.
  2. create a database from databases under services tab. (use that db in the following step) (http://www.netbeans.org/kb/60/ide/java-db.html may help)
  3. create a persistence unit, selecting toplink, the created db in the above step and drop and create as table generation strategy.
  4. create entity classes
  5. generate jsf faces from entity classes
  6. deploy and try from localhost something like that : http://localhost:8084/Registration/faces/welcomeJSF.jsp, do not forget to put faces in the address, that makes the faces servlet deal with that page.
  7. add derbyclient.jar manually (under /opt/sun/javadb/lib in my linux environment ) if you get the following error during run:

Exception [TOPLINK-4003] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.


and deploy and try again!

my project is working :)

Steps for web service part:

  1. create the web service and deploy again.. if successful, you should see the wsdl at somewhere like that http://localhost:8084/Registration/RegistrationWS?wsdl, generated jpa controller classes can be used within web service operations.
  2. create an other web aplication project. this will be the client that makes use of all deployed web services.
  3. in the client web app, generate the web service client from wsdl.
  4. crate a .jsp file in which you call the web service. this can be done automatically by right clicking in jsp and selecting 'Web Services Client Resources -> Call Web Servicve Operation'
  5. deploy the client web app and test from localhost..

Edit on 20.15 : if you get the following error while generating jsf from entity classes,

Could not find Id property. Be sure the accessor method name matches the variable name.

just move the jpa annotations from variable declarations to accessor methods. That fixed the problem in my case. btw, i faced this problem in Windows Xp, but in OpenSuse everything was fine already..


26 Haziran 2009 Cuma

troubleshooting: Glassfish deployment error

The Error:
While trying to deploy a composite application to glassfish server (Netbeans 6.5 is used), i got the following error:
ERROR: Successful execution of Start: SecondCompositeApp
WARNING: (JBIMA0405) Start of service assembly SecondCompositeApp succeeded partially; some service units failed to start.
    * Component: sun-http-binding
      ERROR: (SOAPBC_START_1) HTTPBC-E00205: Start failed. java.lang.Exception: LifecycleException:  PWC3985: Protocol handler initialization failed: java.net.BindException: Address already in use: 8080
    * Component: sun-bpel-engine
      INFO: (JBIMA0409) Lifecycle operation start succeeded for Service Unit SecondCompositeApp-SecondBpelModule.

The Solution:

Just change the http-listener port in glassfish-v2.1/domains/domain1/config/domain.xml from 8080 to 9090.  Luckily,  this fixed the problem in my case :)

23 Haziran 2009 Salı

more notes on Jbossws + Eclipse


Unfortunately, i did not notice that the client stubs were generated by Axis2 not jax-ws (wsit runtime). Therefore, the solution is still incomplete :(

Now, extra steps are:
  • download jboss tools from http://www.jboss.org/tools/download/stable/3_0_GA.html (i downloaded all plugins part, the first part..)
  • install the plugins on eclipse ganymede by extracting the zip and copying plugins and features folders in the extracted package to your eclipse folder 
  • install stp (soa tools project) plugin to eclipse via software updates. the update site is http://download.eclipse.org/stp/updates/ganymede/
  • window --> preferences --> web services --> Jbossws preferences  : add ... /jbossws-metro-bin-dist/output/deploy-jboss500
  •  restart eclipse
Now the environment seems ready..  however, there exists problems that i can not overcome :( for instance while generating a bottom up web service using the jbossws runtime, i get the following error:
error: Could not find class file for com.example.Eval
1 error
Error: Could not generate. (use --show-traces to see full traces)
Error: Wsgen invocation failed. Try the '-verbose' switch for more information

i could not solve the error :(
however, this post is just to note down the preparation of the eclipse environment for web service development :)

some notes on Jbossws + Eclipse

I want to make effective use of metro web service stack and eclipse ide (together). Netbeans support for jaxws is excellent but i have a limitation that all code will be developped with eclipse, so lets move..


My environment is Eclipse Ganymede + Jboss 5.0.0. app. server + Sun jdk on x64 linux machine (open suse).

The steps:
1) Download and install Jboss 5.0.0


3) In jbossws package (extracted) copy ant.properties.example as ant.properties

4) change the server location as follows (appropriately):
jboss500.home=/usr/share/myprograms/ECLIPSEHOME/ECLIPSEHOME/server/jboss-5.0.0.GA

5) execute ant deploy-jboss500 command. ant must be installed and the command must be executed inside the package structure(since build.xml is at that path..)
at this point, jbossws is installed at jboss app server..
btw, jboss server does not work properly with ibm jdk, so use sun jdk instead..

6) open eclipse and add the jboss v5.0 server you installed jbossws on top of.
while trying to do this this error message may appear:
 Missing classpath entry /home/hilal.tarakci/ECLIPSEHOME/server/jboss-5.0.0.GA/server/default/lib/mail.jar
This is due to this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=257823
One of the workarounds: copy mail.jar from jboss-5.0.0.GA/common/lib to /jboss-5.0.0.GA/server/default/lib.
i started the server for test purpose and got the following warning:
11:52:49,509 WARN  [AbstractDeploymentContext] Unable to register deployment mbean vfszip:/home/hilal.tarakci/ECLIPSEHOME/server/jboss-5.0.0.GA/server/default/deployers/jbossws.deployer/jaxb-xjc.jar/1.0/
javax.management.InstanceAlreadyExistsException: jboss.deployment:id="vfszip:/home/hilal.tarakci/ECLIPSEHOME/server/jboss-5.0.0.GA/server/default/deployers/jbossws.deployer/jaxb-xjc.jar/1.0/",type=SubDeployment already registered.
at org.jboss.mx.server.registry.BasicMBeanRegistry.add(BasicMBeanRegistry.java:767)
i just ignored the warning..

7) create a dynamic web project with jboss v5 as target runtime. 

8) add the sample TestWs.java to the project. (The sample code is at JBossWs Code sample with annotations: (TestWs.java)  part at http://www.javabeat.net/articles/40-creating-webservice-using-jboss-and-eclipse-europa-2.html )


10) start jboss inside eclipse. deploy the created project (by adding project to the server.)
Doing this, the following error may appear if project workspace and eclipse are on seperate disks:
Publish failed using Ant publisher
  Could not replace with temp file /tmp/tmp27108.MF.
So, put them on the same disk..

the deployed web service should appear in this list: http://localhost:8080/jbossws/services and wsdl at http://127.0.0.1:8080/JbossWsEval/TestWs?wsdl
Now, it is time to create a client for this web service. 

12) create another dynamic web project, this will include client. right click the project and select new Web Service Client (under Web Services) enter the above wsdl as service definition.
the generated stubs are under src.

13) a sample client code is as follows:
import java.rmi.RemoteException;

import com.test.dhanago.TestWs;
import com.test.dhanago.TestWsProxy;

public class TheClient {
public static void main(String[] args) {
try {
TestWsProxy aProxy = new TestWsProxy();
TestWs service = aProxy.getTestWs();
System.out.println(service.greet(" Stranger"));
} catch (RemoteException e) {
e.printStackTrace();
}
}
}

If this java app prints "Hello Stranger" , then fine :)

19 Haziran 2009 Cuma

Troobleshooting: Date becomes XMLGregorianCalendar when stubs are generated at client side, how to prevent this?

The Problem Part:

The environment: Netbeans 6.5 Ide and Glassfish as, on x64 linux machine (open suse).

Here is the sample web service with java.util.Date type:

package com.example.date;

import java.util.Date;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

@WebService()

public class DateWebService {

@WebMethod(operationName = "dateOperation")

public Date dateOperation(@WebParam(name = "date")

Date date) {

return date;

}

}

The wsdl is at http://localhost:8080/DateProject/DateWebServiceService?WSDL

The dependent xsd is at http://localhost:8080/DateProject/DateWebServiceService?xsd=1

The input and output types for dateOperation is as follows:

<xs:complexType name="dateOperation">

<xs:sequence>

<xs:element name="date" type="xs:dateTime" minOccurs="0"/>

(<xs:sequence>

</xs:complexType>

<xs:complexType name="dateOperationResponse">

<xs:sequence>

<xs:element name="return" type="xs:dateTime" minOccurs="0"/>

</xs:sequence>

<xs:complexType>

It is obvious that java.util.Date is mapped to xs:dateTime.

Lets see what happens when we generate the client stubs from the wsdl. (This is done by right clicking the project in Netbeans and selecting New Web Service Client and entering the wsdl to the related input.)

The generated stubs are at the following location:



Java.util.Date becomes javax.xml.datatype.XMLGregorianCalendar when xml is mapped to Java types againL (Comments are omitted from the following generated code for simplicity..)

package com.example.date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.datatype.XMLGregorianCalendar;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation {

@XmlSchemaType(name = "dateTime")

protected XMLGregorianCalendar date;

public XMLGregorianCalendar getDate() {

return date;

}


public void setDate(XMLGregorianCalendar value) {

this.date = value;

}

}

The reason for this is explained here: http://forums.java.net/jive/message.jspa?messageID=166006

So, the question is what sould be done to get java.util.Date instead of XMLGregorianCalendar when the stubs are generated at the client side?


The Solution Part:

Data conversion at the client side is a solution: http://www.velocityreviews.com/forums/t462336-convert-jaxb-xmlgregoriancalendar-to-javasqldate.html

However, this may not be the case if you definitely want to get Date back when stubs are generated..

Prepare the following file i named jax-ws-jaxb-customization.xml:


<?xml version="1.0" encoding="UTF-8"?>

<jaxws:bindings  node="wsdl:definitions/wsdl:types/xsd:schema"

                                xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"

                                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"

                                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

                                xmlns:xsd="http://www.w3.org/2001/XMLSchema" wsdlLocation="../wsdl/localhost_8080/DateProject/DateWebServiceService.wsdl">

<jaxb:globalBindings>

                               <jaxb:serializable/>

                               <jaxb:javaType name="java.util.Date"

                                                      xmlType="xsd:dateTime"/>

                </jaxb:globalBindings>

</jaxws:bindings>

Use Netbeans Wsdl Customizer :

Right click the web service under Web Service References, seleck Edit Web Service Attributes and select the second tab named WSDLCustomization

Select the below External Binding File part and add jax-ws-jaxb-customization.xml as follows:

Now, examine the generated stubs again, DateOperation is now as follows (again comments are removed for simplicity):

package com.example.date;

import java.io.Serializable;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.w3._2001.xmlschema.Adapter1;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation

implements Serializable

{

@XmlElement(type = String.class)

@XmlJavaTypeAdapter(Adapter1 .class)

@XmlSchemaType(name = "dateTime")

protected Date date;

public Date getDate() {

return date;

}

public void setDate(Date value) {

this.date = value;

}

}

And now there is a difference in the generated stubs, an Adapter1 is also generated:

package com.example.date;

import java.io.Serializable;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlSchemaType;

import javax.xml.bind.annotation.XmlType;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.w3._2001.xmlschema.Adapter1;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "dateOperation", propOrder = {

"date"

})

public class DateOperation

implements Serializable

{

@XmlElement(type = String.class)

@XmlJavaTypeAdapter(Adapter1 .class)

@XmlSchemaType(name = "dateTime")

protected Date date;

public Date getDate() {

return date;

}

public void setDate(Date value) {

this.date = value;

}

}

So, problem solved for now :)

Edit on 22.06.2009  14.15 : The display problem in xml part of the post is fixed by now :)

12 Haziran 2009 Cuma

An example expert system with CLIPS - domain: ballistics

ast night, i developped a rule based system for balistics domain with clips. actually, i had developped an analog project with ESB (Expert System Builder) and the post is here: http://hilaltarakci.blogspot.com/2009/05/how-to-develop-expert-system.html

this is just a simple project to discover usage of rule based systems and expert system tools. this post includes the steps of development and the project files..

clips is a tool for building rule based systems and can be downloaded fromhttp://clipsrules.sourceforge.net/
i do not want to reinvent the wheel, so read this tutorial for using clips :http://iweb.tntech.edu/bhuguenard/ds6530/ClipsTutorial/CLIPS%20tutorial%201.htmthe tutorial consists of 6 parts. (try the addresses ....02.htm to ...06.html) a short and disciplinary tutorial, it helped me a lot..

the domain of the proposed system is balistics and the decision tree for the system is as follows:

In the above tree, rectangles represent the questions and triangles are the -probable- answers.

The .clp file for the above decision tree is:

(defrule compare-object
=>
(printout t "What do you want to compare (cartridge-case or bullet)?")
(assert (object-to-compare (read))))


(defrule comparable-ejector-mark
(object-to-compare cartridge-case)
=>
(printout t "Are the ejector marks comparable (yes or no)?")
(assert (ejector-mark-comparable (read))))


(defrule similar-ejector-mark
(and (object-to-compare cartridge-case)
(ejector-mark-comparable yes))
=>
(printout t "What is the similarity ratio of the ejector marks (high or low)?")
(assert (ejector-mark-similarity (read))))

(defrule comparable-pin-mark
(object-to-compare cartridge-case)
=>
(printout t "Are the pin marks comparable (yes or no)?")
(assert (pin-mark-comparable (read))))


(defrule similar-pin-mark
(and (object-to-compare cartridge-case)
(pin-mark-comparable yes))
=>
(printout t "What is the similarity ratio of the pin marks (high or low)?")
(assert (pin-mark-similarity (read))))

(defrule similar-breech-face
(object-to-compare cartridge-case)
=>
(printout t "What is the similarity ratio of the breech faces (high or low)?")
(assert (breech-face-similarity (read))))

(defrule comparable-set-mark
(object-to-compare bullet)
=>
(printout t "Is there a comparable set mark (yes or no)?")
(assert (set-mark-comparable (read))))


(defrule similar-set-mark
(and (object-to-compare bullet)
(set-mark-comparable yes))
=>
(printout t "Is there a highly similar set mark on the other bullet (yes or no)?")
(assert (set-mark-similarity (read))))

(defrule similar-other-set-marks
(and (object-to-compare bullet)
(set-mark-similar yes))
=>
(printout t "What is the similarity ratio when all the set marks are compared to their matching set marks taking the previously similar set mark as pivot (high or low)?")
(assert (other-set-marks-similarity (read))))

(defrule related-cartridge-cases1
(and (ejector-mark-similarity low)
(pin-mark-similarity low)
(breech-face-similarity low))
=>
(printout t "The cartridge cases are not related.")
(assert (related-cartridge-cases no)))

(defrule related-cartridge-cases2
(and (or (ejector-mark-similarity high)
(pin-mark-similarity high) )
(breech-face-similarity high))
=>
(printout t "The cartridge cases are highly probable that related, but better to consult an expert.")
(assert (related-cartridge-cases highly-probably-yes))))


(defrule related-cartridge-cases3
(and (or (ejector-mark-similarity high)
(pin-mark-similarity high) )
(breech-face-similarity low))
=>
(printout t "The cartridge cases are possible related, but better to consult an expert.")
(assert (related-cartridge-cases possibly-yes)))

(defrule related-cartridge-cases4
(and (ejector-mark-similarity low)
(pin-mark-similarity low)
(breech-face-similarity high))
=>
(printout t "The cartridge cases are possible not related, but better to consult an expert.")
(assert (related-cartridge-cases possibly-no)))

(defrule related-cartridge-cases5
(and (ejector-mark-similarity high)
(pin-mark-similarity high)
(breech-face-similarity low))
=>
(printout t "The cartridge cases are highly probably related, but consult to an expert for breech face differences.")
(assert (related-cartridge-cases highly-probably-yes))))

(defrule related-cartridge-cases6
(and (ejector-mark-similarity high)
(pin-mark-similarity high)
(breech-face-similarity high))
=>
(printout t "The cartridge cases are definitely related")
(assert (related-cartridge-cases yes)))

(defrule related-bullets1
(and (other-set-marks-similarity high)
(set-marks-similarity yes) )

=>
(printout t "The bullets are definitely related")
(assert (related-bullets yes)))

(defrule related-bullets2
(set-marks-similarity no)
=>
(printout t "The bullets are definitely not related")
(assert (related-bullets no)))


Open CLIPSWin.exe and load the above .clp file. You can examine facst and rules by (facts) and (rules) commands. Then type (run). The system will ask questions and generates the facts base according to the questions. You can examine the facts base after the run and you will see a set of facts are asserted during the run.. Here is a screenshot from CLIPS:

the end :)

5 Haziran 2009 Cuma

Ubuntu 8.04 & Windows XP dual boot

I want to install both Ubuntu 8.04 and Windows xp sp3 on my laptop. Here is a good step by step guide : http://apcmag.com/how_to_dual_boot_linux_and_windows_xp_linux_installed_first.htm?page=1
The guide is at the case where you have Ubuntu 8.04 os installed and you want to also install Windows Xp..
.. and some reminders:
- be sure the cd is clean :)
- do not forget to enable boot from cd & set sata mode to ide (from bios)