31 Mart 2011 Perşembe

revisited: using Java FX app in a web application

Please read for the background of this post: http://hilaltarakci.blogspot.com/2011/03/using-java-fx-app-in-web-application.html

Unfortunately, JavaFX MediaBox component did not run successfully, when i deployed the web application in production environment and test it from another client computer.
After a while, i realized that the problem is due to calling JavaFX from a .jsp file.. When JavaFX MediaBox is called from an .html file, no problem shows up..

28 Mart 2011 Pazartesi

using Java FX app in a web application

In order to pass media url as argument to Java FX MediaBox component,
  • change the Main.fxin MediaBox project as follows:
var mediaUrl = FX.getArgument("mediaUrl");

// in order to access mediaUrl, use mediaUrl.toString()
  • create a java web application project (i used Netbeans 6.5.1 for this).
  • edit index.jsp as follows:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script src="http://dl.javafx.com/dtfx.js"></script>
<script>
javafx(
{
archive: "MediaBox.jar",
width: 640,
height: 360,
code: "com.sun.javafx.mediabox.Main",
name: "MediaBox"
}, {
mediaUrl: "http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv"
/*"file:/E:/htarakci/WORKSTATION/tez/projects/lost.avi"*/
}
);
</script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
  • deploy the web app to server and run..

javafx samples here:

for deploying Javafx app:

for passing arguments to Javafx app:

a few tips on writing scripts:

display video interval (specifying startTime and stopTime) with JavaFX Media Box

JavaFX Media Box Component is a prefabricated video player.

In order to play a specified interval of the given video, slightly modify original Main.fx code as follows:
package com.sun.javafx.mediabox;

import javafx.stage.*;
import javafx.scene.*;
import com.sun.javafx.mediabox.MediaBox;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

/**
* @author baechul
*/

var mediaUrl = //"file:/C:/hilaltarakci/WORKSTATION/workspace/WebClient/lost.avi";
"http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv";

var mediaTitle = "Lost Movie Sample";
var mediaDescription = "a sample scene from loast movie...";

var startTime = 404444;
var stopTime = 424444;

var theme = getFXArgString("theme", "paranara");
var mediaViewWidth = getFXArgInt("mediaViewWidth", 640);
var mediaViewHeight = getFXArgInt("mediaViewHeight", 360);

var mediaBox:MediaBox = MediaBox {

// set the current profile

// media and play variables
mediaSource:mediaUrl
mediaTitle: mediaTitle
mediaDescription: mediaDescription
autoPlay: true // default: false
preserveRatio: true // default: true

// size and layout position
width: bind mediaBox.scene.width
//width: bind if({__PROFILE__} == "desktop") 640 else 1024;

height: bind mediaBox.scene.height
//height: bind if({__PROFILE__} == "desktop") 360 else 1024;
layoutX: 0;
layoutY: 0;

// view
themeStr: theme // default: "paranara"
mediaControlBarHeight: 25 // default: 25, possible values: 20~50
showMediaInfo: true // default: true

// function variables
onMouseClicked: function(me) {
mediaBox.setVideo(mediaUrl, mediaTitle, mediaDescription, startTime, stopTime);
/*mediaBox.mediaControlBar.mediaPlayer.startTime = Duration.valueOf(startTime);
mediaBox.mediaControlBar.mediaPlayer.stopTime = Duration.valueOf(stopTime);*/
}

onKeyPressed:function(e:KeyEvent):Void {
if ((e.code == KeyCode.VK_BACK_SPACE) or
(e.code == KeyCode.VK_Q) or
(e.code == KeyCode.VK_POWER))
{
FX.exit();
}
}
}

Stage {
title: "MediaBox Player"
resizable: true

scene:Scene {
//width: getFXArgInt("mediaViewWidth", 640)
width: getWidth()
//height: getFXArgInt("mediaViewHeight", 360)
height: getHeight()
content: mediaBox
}
}

mediaBox.requestFocus();

// helper functions

function getWidth(): Number {

if ({__PROFILE__} == "desktop")
return 640
else
return 1280
}

function getHeight(): Number {

if ({__PROFILE__} == "desktop")
return 360
else
return 720
}

function getFXArgString(arg:String, defaultValue:String): String {
var val = FX.getArgument(arg);
if (val == null) {
return defaultValue;
}
return val as String;
}

function getFXArgInt(arg:String, defaultValue:Integer): Integer {
var val = FX.getArgument(arg);
if (val == null) {
return defaultValue;
}
try {
return Integer.parseInt(val as String);
} catch (nfe: java.lang.NumberFormatException) {
return defaultValue;
}
}

and add the following method to the end of MediaBox.fx :

public function setVideo(url: String, title: String, description: String,
givenStartTime: Integer, givenStopTime: Integer) {
mediaSource = url;
mediaTitle = title;
mediaDescription = description;
mediaControlBar.mediaPlayer.startTime = Duration.valueOf(givenStartTime);
mediaControlBar.mediaPlayer.stopTime = Duration.valueOf(givenStopTime);
}

The application is going to play the video from the beginning at first. However, when you click on the video, the video will play the specified interval.


error: Failed to access IIS metabase

Yesterday, while i was trying to browse my C# web service deployed on iis, i got this error:
Failed to access IIS metabase...
The following two commands solved my problem:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis -i
Start installing ASP.NET (2.0.50727).
......................
Finished installing ASP.NET (2.0.50727).

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis -ga aspnet
Start granting aspnet access to the IIS metabase and other directories used by A
SP.NET.
Finished granting aspnet access to the IIS metabase and other directories used b
y ASP.NET.

26 Mart 2011 Cumartesi

C# - convert DataTable to ArrayList

I need to output a result list which i have as DataTable from a C# web service. So, i have to convert it to ArrayList before using..
here is a code for conversion:
private ArrayList ConvertDT(ref DataTable dt) {
ArrayList converted = new ArrayList(dt.Rows.Count);

foreach (DataRow row in dt.Rows){
converted.Add(row);
}

return converted;
}

// for access
((DataRow)list[0])["startTime"].ToString()


25 Mart 2011 Cuma

JPA tips

In this post, i tried to summarize Java Persistence API: Best Practices slides prepared by Carol McDonald and available at http://www.slideshare.net/caroljmcdonald/td09jpabestpractices2.



Two types of persistence context:

  • · Transaction scoped
  • · Extended scoped persistence context




Configure L2 caching for entities that are

  • · read often
  • · modified infrequently
  • · Not critical if stale

protect any data that can be concurrently modified with a locking strategy

  • · Must handle optimistic lock failures on flush/commit
  • · configure expiration, refresh policy to minimize lock failures

Configure Query cache

  • · Useful for queries that are run frequently with the same parameters, for not modified tables

Navigating Entity Relationships

Data fetching strategy

  • · EAGER – immediate

    · LAZY – loaded only when needed

    · LAZY is good for large objects and/or with relationships with deep hierarchies




Database Design Tips

Smaller tables use less disk, less memory, can give better performance

> Use as small data types as possible

> use as small primary key as possible

> Vertical Partition:

split large, infrequently used columns into a separate one-to-one table

Use good indexing

> Indexes Speed up Querys

> Indexes slow down Updates

> Index columns frequently used in Query Where claus


Mapping Inheritance Hierarchies





Transactions

Do not perform expensive and unnecessary operations that are not part of a transaction

> Hurt performance

> Eg. logging – disk write are expensive, resource contention on log

Do not use transaction when browsing data

> @TransactionAttribute(NOT_SUPPORTED)


There is also a blog entry of the same writer about JPA caching, possibly initiated from the slides at http://www.slideshare.net/caroljmcdonald/td09jpabestpractices2 . (http://blogs.sun.com/carolmcdonald/entry/jpa_caching)


16 Mart 2011 Çarşamba

changing tomcat port

in order to change tomcat port, edit this line in CATALINA_HOME/conf/server.xml:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

by changing 8080 to 8081 (for example..) and restart server..


tried in apache tomcat 7.0.5..

10 Mart 2011 Perşembe

error: A truncation error was encountered trying to shrink CLOB to length : org.apache.derby.iapi.services.io.DerbyIOException'.

The error
A truncation error was encountered trying to shrink CLOB to length : org.apache.derby.iapi.services.io.DerbyIOException'.
is thrown from apache ode while trying to do binary data transfer through bpel..
so, seperating the binary transfer from the process can be a workaround..

here is an explanation from ode FAQ (http://ode.apache.org/faq.html):
Q. I'm getting data truncation errors, what does that mean?
A. We try to use sensible sizes for the database columns that contain messages and variables in ODE. However if you're manipulating large quantities of data that may not e enough. The solution in that case is to alter the column that's too short to reserve enough database space for your needs.

warning C4996: 'fopen' was declared deprecated

in visual studio 2008 environment, to get rid of warnings such as
warning C4996: 'fopen' was declared deprecated
do the following:

add _CRT_SECURE_NO_DEPRECATE to Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.

error: error spawning cmd.exe

While trying to build a component in Visual Studio 2008 environment, i got the error error spawning cmd.exe

sorry, i could not remember where i discovered this solution, but it worked:

In the Options go into Projects and Solutions -> VC++ Directories page and place this rows:

$(SystemRoot)\System32

3 Mart 2011 Perşembe

javax.xml.ws.soap.SOAPFaultException: axis2ns2:selectionFailure

The error javax.xml.ws.soap.SOAPFaultException: axis2ns2:selectionFailure shows up, while the process is running in apache ode (tried with versions 1.3.4 and 1.3.5).

The following assignment is successful:

<copy>
<from>
<literal>
<ns2:operationResponse>
<ns2:return> </ns2:return>
</ns2:operationResponse>
</literal>
</from>
<to variable="OperationOut" part="parameters"/>
</copy>

the definition:

<xs:complexType name="operationResponse">
<xs:sequence>
<xs:element name="return" type="ns1:returnMessage" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

.. however, this one results in axis2ns2:selectionFailure error

<assign name="InitOperation">
<copy>
<from>$OperationWsdlOperationIn.identity/username</from>
<to>$OperationIn.parameters/username</to>
</copy>
<copy>
<from variable="OperationWsdlOperationIn" part="password"/>
<to>$OperationIn.parameters/password</to>
</copy>
</assign>


despite this initialization:

<copy>
<from>
<literal>
<ns2:operation>

<username> </username>
<password> </password>

</ns2:operation>
</literal>
</from>
<to variable="OperationIn" part="parameters"/>
</copy>

<xs:complexType name="operation">
<xs:sequence>
<xs:element name="username" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="password" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

There is an explanation for this situation in Apache ODE FAQ (http://ode.apache.org/faq.html), i copied here for convenience:

Q. My process fails with a selectionFailure; What can I do? A. BPEL expects a single element to be selected when evaluating and expressions, and a selectionFailure fault is thrown if zero or more than one element are selected.

If you get zero element, double-check your namespace prefix and bindings. Also, remember that you must initialize your variables (most often with 's) before assigning into them, unless your are reassigning the whole variable (e.g. directly into $variable, or $variable.part). To debug assignments, you can set the "org.apache.ode" logging category to DEBUG in order to see the content of variables as the process executes.

This links say that it is due to namespace error:

http://stackoverflow.com/questions/4498982/soap-exception-axis2ns2selectionfailure

http://old.nabble.com/assign-with-complex-types-td20919141.html

Solution:

The following assignment lucily solved the error:

<copy>
<from>
<literal>
<operation xmlns="">

<username> </username>
<password> </password>

</operation>
</literal>
</from>
<to variable="OperationIn" part="parameters"/>
</copy>

2 Mart 2011 Çarşamba

variable initilalization in bpel

while using openEsb, variable initilialization is not a problem, since i think openEsb has an extention for this..
however, during ode migration, i get javax.xml.ws.soap.SOAPFaultException: axis2ns1:selectionFailure errors from some of my processes..
i must say, i think variable initialization is the most annoying part of developing bpel processes..
so, i decided to note down some basics about that:


ODE doesn't support variable initialization yet. See here:
http://ode.apache.org/ws-bpel-20-specification-compliance.html
The only way to initialize a message variable is through a copy operation within an assign activity.
You can initialize all of the parts of a message at once if you are copying from another message variable of the same message type.
If you are copying from an expression, literal, or other variable type then you need to specify the message part in the to specification.


Variables need to be initialized before they are assigned from or when
assigned to using a query or an expression or if they are used as to
input to an invoke or in conditional expressions.
If you are just assigning directly to a variable's message part with no query then no
initialization is needed.