Professional Documents
Culture Documents
1. Create new SOA Composite Application in JDeveloper 11g with SOA extension; pick the Composite
with Mediator component template; call the Mediator Translator and choose the Synchronous service
interface. Add the Oracle XML Parser v2 library to the project.
2. Edit the XSD created for the mediator: singleString.xsd. Add a new element:
<element name="translationSource">
<complexType>
<sequence>
<element name="input" type="string"/>
<element name="sourceLanguage" type="string"/>
<element name="targetLanguage" type="string"/>
</sequence>
</complexType>
</element>
3. Edit the WSDL created for the mediator – change the element defining the requestMessage, replace it
with the translationSource element that was defined in the XSD:
<wsdl:message name="requestMessage">
<wsdl:part name="request" element="inp1:translationSource"/>
</wsdl:message>
I also prefer to have more meaningful names for portType and operation – instead of execute_ptt and
execute – so I have changed them too. However, these changes need to be propagated into the
composite.xml, .componentType and .mplan files.
4. From the composite editor, double click the mediator component in order to start editing. Click the
green plus sign, to create a new static routing rule. Click on the Echo button (instead of Service and
Event) to create a roundtrip mediator that takes on the request and returns it back to the requestor, after
performing transformations and java callouts.
<xsl:template match="/">
<inp1:singleString>
<inp1:input>
<xsl:value-of
select="concat(/inp1:translationSource/inp1:input,',',/inp1:translationSource/inp1:sourceLanguage,',',/inp1
:translationSource/inp1:targetLanguage)"/>
</inp1:input>
</inp1:singleString>
</xsl:template>
this mapping is used to have the translation request available in the response message for the Java Callout
to act on.
6. Specify the Java Callout for the Mediator. Set it to
nl.amis.soasuite11g.mediator.MediatorCalloutToHttpRestProcessor – the name of a class we are about to
create.
package nl.amis.soasuite11g.mediator;
}
} //for
return returnValue;
}
private XMLDocument prepareReturnMessage(String input, String sourceLanguage, String
targetLanguage) throws ParserConfigurationException {
JXDocumentBuilderFactory factory =
(JXDocumentBuilderFactory)JXDocumentBuilderFactory.newInstance();
JXDocumentBuilder documentBuilder =
(JXDocumentBuilder)factory.newDocumentBuilder();
XMLDocument doc = (XMLDocument)documentBuilder.newDocument();
doc.setVersion("1.0");
doc.setEncoding("UTF-8");
//http://xmlns.oracle.com/singleString
// singleString/input
XMLElement rootElement = (XMLElement)
(doc.createElementNS("http://xmlns.oracle.com/singleString","singleString"));
doc.appendChild(rootElement);
XMLElement inputElement =
(XMLElement)(doc.createElement("input"));
rootElement.appendChild(inputElement);
String translation = NoJerseyTranslationService.translate(input, sourceLanguage, targetLanguage);
XMLText translationElement =
(XMLText)doc.createTextNode(translation);
inputElement.appendChild(translationElement);
return doc;
}
(see the previous blog article on SOA Suite 11g Mediator Java Callout for details on this class)
8. This class uses the NoJerseyTranslationService, another class that needs to be created. However, before
we can do so, we need to download the json-simple library from http://code.google.com/p/json-simple/
and add the jar file json_simple-1.1.jar to the SCA-INF/lib directory in our project.
9. Create class NoJerseyTranslationService – see for details about its implementation the blog article
Leveraging RESTful Services from Java application using Jersey (Introduction).
package nl.amis.soasuite11g.mediator;
try {
serverAddress = new URL(googleTranslationService +"?v=1.0&&q="+sourceString.replace(' ', '+')
+"&&langpair="+sourceLanguage+"%7C"+targetLanguage);
//set up out communications stuff
connection = null;
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();
//get the output stream writer and write the output to the server
//not needed in this example
//wr = new OutputStreamWriter(connection.getOutputStream());
//wr.write("");
//wr.flush();
return(sb.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
//close the connection, set all objects to null
connection.disconnect();
rd = null;
sb = null;
wr = null;
connection = null;
}
return null;
}
}
10. Deploy the composite application to the SOA Suite. Test the Web Service exposed by the Mediator –
to have for example the string "Hello World" translated from english to french.
In an earlier post, I showed for the Oracle SOA Suite 11g how we can use the Mediator's Java Callout
functionality to integrate RESTful services into our SOA Composite applications, even though we currently
have no Http Binding Service nor WSIF support (SOAP Java Binding) at our disposal in the SOA Suite – link
to article. In SOA Suite 11g PS1 – released in November 2009 – is the preview (not yet officially supported
and only available for PoC and early trials – of Spring components. This feature provides another way of
integrating Java classes into our SOA Composite applications.
This article demonstrates how we can use the Spring component to bind our SOA Composite Application
to the RESTful Translation service provided by Google.
Note:
In order to use this preview feature in SOA Suite 11g PS1, you must first enable preview mode. Go to
$JDeveloper_HOME/integration/seed/soa/configuration and open soa-config.xml. Search for $
{SPRING_COMPONENT_NAME_L} and remove the xml comments (<!– –>) around it. After you've saved
the file, restart JDeveloper.
Steps for creating the SOA Composite with integrated RESTful
Translation Service
1. Create SOA application – with Mediator (Translator)
2. Create Java Interface ITranslator
package nl.amis.soasuite11g.spring;
public interface ITranslator {
package nl.amis.soasuite11g.spring;
try {
serverAddress = new URL(googleTranslationService +"?
v=1.0&&q="+sourceString.replace(' ', '+')
+"&&langpair="+sourceLanguage+"%7C"+targetLanguage);
//set up out communications stuff
connection = null;
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();
return(sb.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
//close the connection, set all objects to null
connection.disconnect();
rd = null;
sb = null;
wr = null;
connection = null;
}
return null;
}
}
4. Create Spring Context using the Spring 2.5.6 node under Business Tier in the New Gallery:
Call the Spring Content restful-beans.xml. For example. Or something else.
5. Configure bean translator in the restful-beans.xml Spring context, based on the TranslatorImpl class
<bean name="translator"
class="nl.amis.soasuite11g.spring.TranslatorImpl" />
The Spring Context is immediately added to the composite.xml
8. Create an XSD for the elements used for the request into and response from the Translation Service:
<schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://nl.amis/translation"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="translationResult">
<complexType>
<sequence>
<element name="result" type="string"/>
</sequence>
</complexType>
</element>
<element name="translationSource">
<complexType>
<sequence>
<element name="input" type="string"/>
<element name="sourceLanguage" type="string"/>
<element name="targetLanguage" type="string"/>
</sequence>
</complexType>
</element>
</schema>