Wednesday, December 19, 2007

Sun Java System Web Server 6.1 - Proxying

We are currently inquiring about the use of directives as a way to proxy requests from one url to another server. Proxies can be used for different use cases. For one, if you would like to simply redirect requests from a legacy web service to a new web service, you could want to use proxies.

There are three options available to proxy requests. Each provide a partial solution for proxying but none provide a full one. They are listed below in order of complexity.

A) Using the NameTrans 'redirect' directive.

The documentation indicates that this directive can redirect URLs coming into the web server to another web server at a particular path. It is configured in the following way:

Steps:
1) Make a copy of the obj.conf in the same folder and rename the file as desired. This file will contain the NameTrans directive to redirect the requests.
2) Add the following directive to the new copy of the obj.conf before the NameTrans ntrans-j2ee directive, like below:

<Object name="default">
AuthTrans fn="match-browser" browser="*MSIE*" ssl-unclean-shutdown="true"
NameTrans fn=redirect from=/ws/services/ url=http://dev-a.services.bamnetworks.com:52070/ws/services/
NameTrans fn="ntrans-j2ee" name="j2ee"
...

3) Configure a new virtual server class (VSCLASS) in server.xml.
4) Configure the new virutal server class to use the new obj.conf like below:

<VSCLASS id="vsclass2" objectfile="obj2.conf" >

5) Add the web application instance on which requests will be proxied under this virtual server class.

Disadvantages:
1) Redirect Response code: This directive actually will return a response code of 301 Permanently Moved back to the client requesting the server. The client is responsible for automatically redirecting to the new URL. This is however not default behavior of web service clients, but is for web browsers.

Note: We tried to use this solution for redirecting our web service clients but the generated client does not automatically redirect to the new URL given this HTTP response code.

2) Cross-browser issues: This directive does not solve cross-browser issues either. Although the browser will redirect automatically to a web service, it will not be able to accept incoming data from a domain different from the domain of the current page making the HTTP requests.

B) Using the Reverse Proxy Plug-in.

Monday, December 10, 2007

Actionscript Arrays displayed as objects using typeof operator

The typeof operator applied to an Array object does not display as "array". It still displays as "object".

Monday, December 3, 2007

How to Retrieve FlashVars Data in ActionScript 3.0

You would like to retrieve variables from the embed Flash object as in the following example:

root.loaderInfo.parameters

References: How to Retrieve FlashVars Data in ActionScript 3.0

Thursday, November 15, 2007

Struts Error Message - ???en.ProfileProperty.error.message???

error
???en.ProfileProperty.error.message???

environment
You have a Struts web application. The error messages are configured through the applicationResoources.properties file. Whenever these properties file is changed, the error messages may now be configured differently and will result in the above unrecognizable error message. This seems to be happening in only this particular error message. Other messages are working correctly.

possible causes:
The following Struts configuration files may be related to the misconfiguration:

struts-config.xml
applicationResources.xml

solution
You may either include dom.jar or xml-apis.jar in your classpath.

Friday, October 26, 2007

Flash verus Java: Differences

As a Java developer, moving to Flash should not be too difficult of a task. Actionscript 3.0 contains many features of the Java language, but also has tremendous amount of other features related to animations that Java does not have. It is these latter features that will require a slower learning curve for a Java developer. Here are couple of important similarities and differences that I have encountered related to the design, structure and syntax of the Actionscript language as I was reading a book. These differences are more oriented toward a Java developer moving to Actionscript as opposed to a Flash developer moving to Java.


Conceptual Differences

1. Variable declaration

Variables in Actionscript do not have a type, as opposed to Java where all variables must be assigned a type. Although one could stipulate that assigning a Java variable as a java.lang.Object could simulate an untyped Actionscript variable, the same can be done to an Actionscript variable. Although, the variable of a type Object is still a typed variable. The difference lies in the fact that an untyped Actionscript variable can be assigned a primitive data type value or an Object type, where in Java it would not be possible for a single variable to be assigned both a primitive data type and an Object at the same time.

2. Function declaration

Despite the syntactical differences, there are also two conceptual differences in function/method declarations between Actionscript and Java.

(1) The first difference is that functions do not need to declare a return type. This is to support older versions of Actionscript.

(2) The second is that functions can declare initial values for its parameters in Actionscript. Initialized parameters of a function are not required to be passed to the function, while uninitialized parameters of a function are required to be passed. Whether they will cause compile errors is something i do not yet know.

3. Function passed as value


One of the more powerful features in Actionscript is the ability to assign a variable to a reference to a function. This is quite a powerful feature in Actionscript and perhaps provides a short cut for coding.

This feature is actually used for event handling and animation, the forte of Actionscript.

4. Nested Functions

Functions can be declared within another function.

5. Package-level, Source-File-Level, And Global Functions

One can create functions within a package (package-level). Package-level functions are accessible only within the package.

Source-file-level functions are rarely used because they can be replaced with private static functions within a package.

Global functions are defined in the unnamed package and are accessible by any class or package without an import.

All these are not concepts within Java. In Java, all functions are always associated with a class.

6. Protected and default access-control modifiers.

The protected and default access modifiers of Actionscript and Java have different definitions. The protected modifier in Java allows classes within the same package and any subclasses to access the class or variable on which the protected modifier has been declared, while in Actionscript, the protected modifier allows only subclasses to access the class or variable. Therefore, the Actionscript modifier is more restrictive, but in my opinion, makes more sense.

The default modifier in Java, which is designated with no keyword but aka package-private, only allows classes within the same package to access the class or variable, while, in Actionscript, the default or internal modifier allows classes within the same package and subclasses to access the class or variable. Essentially, the internal modifier has the same access control as in Java's protected modifier.

8. Overloading Methods in Subclasses

9. No Abstract Classes

10. Reflection replaced with built-in operators.

11. Arrays are different in Actionscript.

Arrays in Actionscript are not associated with a particular class or type as in Java. So, there is only one array type in Actionscript as opposed to Java where there can be an infinite number of array types according to the type the array has been declared with. This single array type in Actionscript is used to hold all types within the same array.

The array in Actionscript is also dynamically sized and therefore will never throw an error if the initial capacity of the array has been exceeded when attempting to add new elements beyond the size of the array. In Java, an array is always initialized with an initial capacity and cannot be changed after instantiation. Instead, the ArrayList can be used in place of the fixed-sized array.

Unlike the Java array, the Actionscript array has methods used for modifying its contents. Both array types allow you to directly modify its contents using the bracket notation. However, the Actionscript array defines modification methods, listed in the following: push, unshift, splice, shift, pop, concat, delete. This allows the array to be used as a stack.

One other trivial but nice feature of the Actionscript array is that it prints out as a comma-delimited list of element values. No more weird string representations of arrays! (Athough in Java 1.5, there is a new method that prints out Arrays nicely, Arrays.toString()).

12. Dynamic Actionscript

An entirely different concept in Actionscript is the ability to dynamically create or add new instance variables and methods to classes or dynamically create new classes. There is no analogous concept in Java.

Only Actionscript classes that have been defined as

13. Actionscript Lookup Tables versus Java Collections Map

The Java Collections framework has revolutionalized the way Java developers use data structures in their programs. The lead designer of the Collections Framework, Joshua Bloch, who also wrote a highly acclaimed and one of the most useful Java programming books, called Effective Java, is a prominent Java architect among the Java community. His framework has won an award for Best Java Class Library.

One of the collection classes in the framework is a Map. There is not equivalent class in Actionscript. Instead, the ability to dynamically add instance variables to a dynamic object replaces the Map concept.

Feature Differences

1. Setter / Getter functions



2. Constants and the final modifier for instance variables.

3. The switch statement is more powerful in Actionscript.

The Java switch statement only allows the primitive data types to used as values in the switch statement. One of the complaints in Java is that you cannot use Strings or perhaps Objects within the switch statement. Fortunately, in Actionscript, you can! However, there is fine print related with this feature. In a switch statement, it uses a strict equality operator on determining equality of the switch values.

4. Actionscript has additional operators that Java does not have. Some are quite powerful.

Some of these additional operators include those that backwards-compatible for older versions of Actionscript. These will not be included here as they should not be used in new code.

5. Actionscript has built-in XML operators.


Syntactical Differences

1. Constructors

2. Overriding methods

3. void vs. null

Conceptual Similarities

1. Object-oriented programming

Actionscript 3.0 contains interfaces, classes, instance methods, static methods, instance variables, static variables.

Tuesday, October 23, 2007

Flash Questions

1. Can two flash players embedded on the same page talk to each other?

2. Is it typical for flash players to be configured through a separate config file located on the machine?

3. NetStream is responsible for playing

Monday, October 22, 2007

Java To XML Technologies

I am trying to find the most suitable Java to XML utility that will provide easy to read XML that defines a Java object. Here are some sample ones below:

1. XML Encoder

sample:

JFrame class

XML:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.0" class="java.beans.XMLDecoder">
<object class="javax.swing.JFrame">
<void property="name">
<string>frame1</string>
</void>
<void property="bounds">
<object class="java.awt.Rectangle">
<int>0</int>
<int>0</int>
<int>200</int>
<int>200</int>
</object>
</void>
<void property="contentPane">
<void method="add">
<object class="javax.swing.JButton">
<void property="label">
<string>Hello</string>
</void>
</object>
</void>
</void>
<void property="visible">
<boolean>true</boolean>
</void>
</object>
</java>
advantages:
  • completely comprehensive
  • part of the Java API
disadvantages:
  • verbose
2. JSX - Java Serialization to XML

sample XML:
N/A

advantages:

disadvantages:
  • not mature product
  • not free
  • no sample provided
3. XStream

sample:

Java:
public class Person {
private String firstname;
private String lastname;
private PhoneNumber phone;
private PhoneNumber fax;
// ... constructors and methods
}

public class PhoneNumber {
private int code;
private String number;
// ... constructors and methods
}
XML:
<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
<code>123</code>
<number>1234-456</number>
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person>

advantages:
  • no mappings required

disadvantages:

4. Castor

References: Java Boutique Tutorial: Java To XML and Back Again with Castor XML

sample:

Java:
private List myList = new ArrayList();

public void setMyList(List myList) {
this.myList = myList;
}

public List getMyList() {
return this.myList;
}

public Person(String name, String email, String phone, List myList) {
this.name = name;
this.email = email;
this.phone = phone;
this.myList = myList;
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<person>
<myList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="java:java.util.String">
List#1
</myList>
<myList xsi:type="java:java.util.String">
List#2
</myList>
<email>prokhorenko@gmail.com</email>
<name>Olexandr Prokhorenko</name>
<phone>123-555-1234</phone>
</person>
advantages:
  • comprehensive
  • mature product

disadvantages:
  • requires a mapping file

5. Java2XML

References: Java Boutique Tutorial: Java To XML and Back Again with Castor XML

sample:

Java:
public class HelloWorld
extends Thread
{
private int N;

private long sleep;

public HelloWorld(int N, long sleep)
{
this.N = N;
this.sleep = sleep;
}

public void run()
{
for (int i = 0; i < hw =" new"> XML:
<!-- Generated by Java2XML http://java2xml.dev.java.net/ -->
<java-source-program>
<java-class-file name="helloworld.java">
<import module="java.util.*"/>
<class name="HelloWorld" visibility="public">
<superclass name="Thread"/>
<field name="N" visibility="private">
<type primitive="true" name="int"/>
</field>
<field name="sleep" visibility="private">

<type primitive="true" name="long"/>
</field>
<constructor visibility="public" name="HelloWorld">
<formal-arguments>
<formal-argument name="N">
<type primitive="true" name="int"/>
</formal-argument>
<formal-argument name="sleep">
<type primitive="true" name="long"/>

</formal-argument>
</formal-arguments>
<assignment-expr op="=">
<lvalue>
<field-access field="N">
<this/>
</field-access>
</lvalue>
<var-ref name="N"/>

</assignment-expr>
<assignment-expr op="=">
<lvalue>
<field-access field="sleep">
<this/>
</field-access>
</lvalue>
<var-ref name="sleep"/>
</assignment-expr>

</constructor>
<method name="run" visibility="public">
<type name="void" primitive="true"/>
<formal-arguments/>
<block>
<loop kind="for">
<init>
<local-variable name="i">
<type primitive="true" name="int"/>

<literal-number kind="interger" value="0"/>
</local-variable>
</init>
<test>
<binary-expr op="<">
<var-ref name="i"/>
<field-access field="N">
<this/>
</field-access>

</binary-expr>
</test>
<update>
<unary-expr op="++" post="true">
<var-ref name="i"/>
</unary-expr>
</update>
<block>
<send message="println">

<target>
<field-access field="out">
<var-ref name="System"/>
</field-access>
</target>
<arguments>
<literal-string value=""Hello World""/>
</arguments>
</send>

<try>
<block>
<send message="sleep">
<target>
<var-ref name="Thread"/>
</target>
<arguments>
<var-ref name="sleep"/>
</arguments>

</send>
</block>
<catch>
<formal-argument name="e">
<type name="InterruptedException"/>
</formal-argument>
<block>
<send message="printStackTrace">
<target>

<var-ref name="e"/>
</target>
<arguments/>
</send>
</block>
</catch>
</try>
</block>
</loop>

</block>
</method>
<method name="main" visibility="public" static="true">
<type name="void" primitive="true"/>
<formal-arguments>
<formal-argument name="args">
<type name="String" dimensions="1"/>
</formal-argument>
</formal-arguments>

<block>
<local-variable name="hw">
<type name="HelloWorld"/>
<new>
<type name="HelloWorld"/>
<arguments>
<literal-number kind="interger" value="10"/>
<literal-number kind="interger" value="1000"/>
</arguments>

</new>
</local-variable>
<send message="start">
<target>
<var-ref name="hw"/>
</target>
<arguments/>
</send>
</block>

</method>
</class>
</java-class-file>
</java-source-program>
advantages:
  • comprehensive
  • mature product
  • free

disadvantages:
  • complicated XML
6. Jato

References: Javaworld Article: Jato: The new kid on the open source block

disadvatages:

  • fairly new product
7.  JiBX

advantages

disadvantages:
  • requires binding file to define the XML 

Tuesday, October 16, 2007

JAXRPC Error - java.lang.ClassCastException

error
java.lang.ClassCastException
at com.sun.xml.rpc.client.StubBase._postSendingHook(StubBase.java:231)
at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:324)
at com.bamnetworks.services.boc.csp.client.impl.jaxrpc.generated.CspWsInterface_Stub.getPlanSummary(CspWsInterface_Stub.java:86)
at com.bamnetworks.services.boc.csp.client.CspClient.getMnCollegescholarshipInterface(CspClient.java:63)


environment
JAXRPC client resides inside Axis2 container.
The following jars are included in the Axis2 service lib: saaj-api.jar and saaj-impl.jar.

However, the Axis2 container also contains the following jar: axis2_saaj-1.1.jar


possible causes:
The above two jars are conflicting with each other. What is happening is that the axis2 saaj implementation of the message factory is being used instead of the sun saaj implementation of the message factory.

Therefore, the axis2 saaj implementation is creating messages that the JAX-RPC client is not expecting. It is expecting Message objects of a different type.

Axis2 saaj Message class: org.apache.axis2.saaj.SOAPMessageImpl
Sun saaj Message class: com.sun.xml.messaging.saaj.soap.MessagingImpl

It is this discrepancy in the classes that is causing the above ClassCastException. Within the StubBase it is expecting the type to be of the Sun implementation, but instead is getting the Axis 2 implementation.

solution

solution 1) Setting a system property and moving jars to the Axis 2 container lib

Move the saaj-impl.jar and FastInfoSet.jar to the Axis2 container lib from the Axis2 service's lib.

Then, within the code, set a system property that indicates which message factory should be used to construct SOAP messages for web services before the JAX-RPC client operation is called, as in the following code:

System.setProperty("javax.xml.soap.MessageFactory", "com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Imp");

solution 2) Keep the JAXRPC jars in the service lib directory and modify the JAXRPC stub to use the correct MessageFactory.

This is particularly a hacky way of embedding a JAXRPC client within a Axis2 service, but this seems to be the only way to do without including the JAXRPC client jars in the Axis2 container lib.

In this solution, you need to modify the JAXRPC stub to

a) Create a custom MessageContext that extends from com.sun.xml.rpc.soap.message.SOAPMessageContext

In this custom class, override the methods called createMessage(useFastInfoset, acceptFastInfoset) and
createMessage(useFastInfoset, acceptFastInfoset) to use the com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl() as the MessageFactory.

b) Create a custom ClientTransport that extends from HttpClientTransport.

In this custom class, override the readResponse() method.




Friday, October 12, 2007

Detecting Broken Images with Javascript

An awesome link to determine whether the image is broken within the page. The following is exact copy from the link in the References below. Please refer to the link below.


<script language="javascript">
<!--
window.onload = function() {
for (var i = 0; i < document.images.length; i++) {
if (!IsImageOk(document.images[i])) {
document.images[i].style.visibility = "hidden";
}
}
};

function IsImageOk(img) {
// During the onload event, IE correctly identifies any images that
// weren't downloaded as not complete. Others should too. Gecko-based
// browsers act like NS4 in that they report this incorrectly.
if (!img.complete) {
return false;
}
// However, they do have two very useful properties: naturalWidth and
// naturalHeight. These give the true size of the image. If it failed
// to load, either of these should be zero.
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
return false;
}
// No other way of checking: assume it's ok.
return true;
}


//-->
</script>

(If you feel that an exact copy of the code in this blog violates your rights, please tell me and I will take this code down. The link below will still remain. Thanks!)

References:
http://talideon.com/weblog/2005/02/detecting-broken-images-js.cfm

Monday, September 24, 2007

Axis2 Client Error - NullPointerException at ClientUtils.inferIntTransport

error
java.lang.NullPointerException
at org.apache.axis2.description.ClientUtils.inferInTransport(ClientUtils.java:85)
at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:253)


environment
Attempting to connect to a web service using an Axis2 client.

possible causes:
You are missing a jar in your classpath.

solution
The missing jar is the commons-httpclient.jar. Add this jar to your classpath.

Friday, September 21, 2007

Classpath Problem - javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found

error
com.bea.xml.stream.MXParserFactory not found

environment
The following xml jars are in my classpath:
xerces.jar - org.apache.*, org.w3c.dom.html.*, org.w3c.dom.ls.*
xercesImpl.jar - com.sun.org.apache.*


possible causes:
You do not have a StAX implementation in your classpath.

solution
You must provide an implementation of StAX in your classpath.

references
http://forums.java.net/jive/thread.jspa?messageID=117971

Thursday, September 20, 2007

Secure Copy

Copy local file to remote location:

scp <local-file-path>/<file-name> <username>@<server-name>:<location-from-home-dir>

Copy remote file to local location:

scp <username>@<server-name>:~/<path-to-file>/<file-name> <local-directory-location>

Mule Logging - How to specify a different location for the mule logs

bin/mule script

Create and export an environment variable pointing to your desired log location.

export LOG_DIR=/data/logs/your-desired-log-location

conf/wrapper.conf file

Refer to the environment variable exported in the mule script in the wrapper.logfile property in the wrapper.conf configuration file.

#********************************************************************
# Wrapper Logging Properties
#********************************************************************
......
# Log file to use for wrapper output logging.
wrapper.logfile=%LOG_DIR%/%MULE_APP%.log
......

Thursday, September 13, 2007

Running an SSH Tunnel in the background

nohup ssh -v -L <local.port>:<destination.ip>:<destination.port> username@<remote.ip>

Note: You cannot use an alias for the ssh command or else it will not work. You must use the ssh command directly in the nohup command.

Friday, September 7, 2007

Mule Error: Remote Debugging a Mule Server

The article given in Remote Debugging a Mule Server does not work on some operating systems. You must include each JVM option on a separate line as in the following example.

# uncomment this line to debug remotely, the application will wait for the external debugger to connect
# IMPORTANT: change the wrapper.java.additional. parameter to be the actual consecutive number,
# depending on the number of additional parameters above
wrapper.java.additional.4=-Xdebug
wrapper.java.additional.5=-Xnoagent
wrapper.java.additional.6=-Djava.compiler=NONE
wrapper.java.additional.7=-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005


References:
http://mule.codehaus.org/display/MULE/Remote+Debugging+a+Mule+Server
http://www.mail-archive.com/user@mule.codehaus.org/msg04986.html

Migrating from Mule 1.3.3 to Mule 1.4.1

1. Change the MULE_HOME to point to the Mule 1.4.1 home directory.

2. Update the 'mule' script in the bin folder with the Mule 1.4.1 version.

Thursday, August 30, 2007

XML Error: NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange

error
java.lang.NoClassDefFoundError: org/w3c/dom/ranges/DocumentRange

environment
The following xml jars are in my classpath:
xerces.jar - org.apache.*, org.w3c.dom.html.*, org.w3c.dom.ls.*
xercesImpl.jar - com.sun.org.apache.*


possible causes:
You are missing the DocumentRange class in your classpath.

solution
You may either include dom.jar or xml-apis.jar in your classpath.

Wednesday, August 29, 2007

Pivot Tables

Example:

SELECT *
FROM (SELECT job,
sum(decode(deptno,10,sal)) DEPT10,
sum(decode(deptno,20,sal)) DEPT20,
sum(decode(deptno,30,sal)) DEPT30,
sum(decode(deptno,40,sal)) DEPT40
FROM scott.emp
GROUP BY job)
ORDER BY 1;
If you are pivoting over varchar fields, you can use the max or min aggregate function because these can operate on varchar fields.

Example:

SELECT language_id,
max(decode(greeting,'hello', sal)) english,
max(decode(greeting,'konichiwa',sal)) japanese,
max(decode(greeting,'ni hao',sal)) chinese,
max(decode(greeting,'ola',sal)) spanish
FROM language.phrases
GROUP BY language_id


References:
How does one code a matrix/crosstab/pivot report in SQL?
Pivot Table Techniques

Tuesday, August 28, 2007

Java XML Binding Frameworks

Apache Axiom ~ AXis Object Model
Castor XML
JAXB ~ Java Architecture for XML Binding
JBind
JiBX
XMLBeans

Dom4j Schema Validation

XML:

<?xml version="1.0"?>
<reportingConfig xmlns="http://services.bamnetworks.com/reporting/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://services.bamnetworks.com/reporting/ reporting-config.xsd"
>
...
</reportingConfig>


XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://services.bamnetworks.com/reporting/"
xmlns:tns="http://services.bamnetworks.com/reporting/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
>
...
</xsd:schema>


Java code:


import org.dom4j.io.SAXReader;
import org.dom4j.Document;
....

SAXReader reader = new SAXReader(true);

reader.setFeature("http://apache.org/xml/features/validation/schema", true);

// set the validation feature to true to report validation errors
reader.setFeature("http://xml.org/sax/features/validation", true);

// set the validation/schema feature to true to report validation errors against a schema
reader.setFeature("http://apache.org/xml/features/validation/schema", true);

// set the validation/schema-full-checking feature to true to enable full schema, grammar-constraint checking
reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

Document document = reader.read(reportingConfigURL);