

1. Create a very simple Java Project with just three classes (This project is just to test this solution)
Book.java
package com.blogspot.oraclesoasuite11g;
import java.io.Serializable;
import java.util.Date;
public class Book implements Serializable {
private static final long serialVersionUID = -5802550970297576366L;
public String ISBN;
public String title;
public String author;
public Date publicationDate;
public String getISBN() {
return ISBN;
}
public void setISBN(String ISBN) {
this.ISBN = ISBN;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getPublicationDate() {
return publicationDate;
}
public void setPublicationDate(Date publicationDate) {
this.publicationDate = publicationDate;
}
}
Author.java
package com.blogspot.oraclesoasuite11g;
import java.io.Serializable;
public class Author implements Serializable {
private static final long serialVersionUID = -5802550970297576366L;
public String name;
public Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
Library.java
package com.blogspot.oraclesoasuite11g;
import java.util.Date;
public class Library {
public static Book getBook(){
Book bk = new Book();
bk.setAuthor(“Paul”);
bk.setTitle(“Great book”);
bk.setISBN(“99999999″);
bk.setPublicationDate(new Date());
return bk;
}
public static Author getAuthor(){
Author au = new Author();
au.setName(“Paul”);
au.setAge(90);
return au;
}
}
Note: It’s important that the two methods, getBook() and getAuthor(), are static so they can be used in OSB.
Export it as Library.jar (Java JAR) and put it in a new OSB Project – OSB Common Resources
2. This is the important part!! Create a new Java Project – JavaToXML
It’s a very simple and generic project that makes the marshelling of any java Object to XMLObject (or just to String if you wish).
This project uses Xtream library to serialize objects (http://xstream.codehaus.org/) and XMLBeans for accessing XML by binding it to Java types (http://xmlbeans.apache.org/) so the dependencies are xstream-1.4.2.jar, kxml2-2.3.0.jar and xmlbeans-2.4.0.jar.
ObjectMarshaller.java
package com.blogspot.oraclesoasuite11g;
import org.apache.xmlbeans.XmlObject;
import com.thoughtworks.xstream.XStream;
public class ObjectMarshaller {
public static XmlObject getXmlObject(Object obj) {
String strXml = null;
XmlObject xmlObj = null;
try {
XStream xstream = new XStream();
xstream.alias(obj.getClass().getSimpleName(), obj.getClass());
strXml = xstream.toXML(obj);
xmlObj = XmlObject.Factory.parse(strXml);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace(System.err);
}
return xmlObj;
}
}
Export it as JavaToXML.jar (Java JAR) and put it also in project OSB Common Resources
3. Create a OSB project – OSB Library (it doesn’t do anything special but to see the JavaToXML in action)
4. Stop the server, put the dependencies jars in ORACLE_DOMAIN\lib and start it again
5. Deploy the OSB Library project in OSB Console and test it!
