Entirex Orchestrator/xml

Hi Collins

i am using j2sdk1.4.0&tomcat3.2…my problem with Log4j got solved,there was some problem with xml file…from java file i am sending one xml file and sequence file…to OrchestratorGateway, it is giving output

<error_message>
Your request could not be satisfied. The incoming request did not contain enough
information for Orchestrator/XML to determine the processing required.
</error_message>



My java File Mediator utility
=============================
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Vector;
import java.util.Enumeration;
import java.net.HttpURLConnection;
import java.net.ProtocolException;

/
* The MediatorUtility class is used to
* post requests to mediator and recieve response
*


* *
*@ author Sandhya Dacha
*
*/
public class MediatorUtility
{
//need to remove hardcoded values

final static String HTTP_PROTOCOL = “http:”;
final static String ORCHESTRATOR_NAME = “orchestrator”;
final static String XBRIDGE_WEB = “xbridge.web”;
final static String PORTAL_SERVLET = “portal.servlet”;
final static String TYPE_TEXT_XML = “text/xml”;
final static String S_CONTENT_TYPE = “Content-Type”;
final static String S_SLASH = “/”;
final static String TYPE_APPLICATION_XML = “application/xml”;
final static String SEQUENCER_PROPERTY = “xbd.sequence.uri”;
static final String DEFAULT_XBRIDGE_WEB = “default_xbridge.web”;
static final String DEFAULT_PORTAL_SERVLET = “default_portal.servlet”;

static String _destinationURL = null;
static byte[] _dataArray = null;
static String _url = null;
static String _sequenceFile = null;

/

* getResultsFromMediator will send the input XML and sequence file to the specified servlet passed through the
* system property, portal.servlet. The default servlet is
* OrchestratorGateway. If the servlet is OrchestratorGateway,
* an additional argument, the URL format of sequence file will
* be required.
* Note that the MediatorUtility only support the “POST” method.

/
public static byte[] getResultsFromMediator(String argSequenceFile, String argInputXML)throws Exception{

HttpURLConnection _httpConnection = null;
// use System.getProperty to figure out where the xbridge web is
// and what the portal servlet is

String xbridgeWeb = System.getProperty (XBRIDGE_WEB, “//localhost:8080/orchestrator”);
String portalServlet = System.getProperty (PORTAL_SERVLET, “OrchestratorGateway”);

_sequenceFile=argSequenceFile;
// get the destination URL

_destinationURL = HTTP_PROTOCOL + xbridgeWeb + S_SLASH + portalServlet;
//_destinationURL =“http://localhost:8080/orchestrator/OrchestratorGateway”;
//OrchestratorGateway";
//OrchestratorGateway";

_dataArray=argInputXML.getBytes();

// get the URL for HTTP protocol
_url = (_sequenceFile == null) ?
_destinationURL:
_destinationURL;
//+ “?” + SEQUENCER_PROPERTY + “=” + _sequenceFile;
System.out.println("URL: " + _url);

// get the HTTP URL
URL httpURL = null;
try {
httpURL = new URL(_url);
} catch(MalformedURLException e) {
System.out.println("new URL: " + _url + e.toString());
//throw new MediatorConnectionException(e);
}

// open the HTTP URL connection
try {
_httpConnection =(HttpURLConnection) httpURL.openConnection();
} catch(IOException e) {
System.out.println("Cannot open URL connection: " + e.toString());
//throw new MediatorConnectionException(e);
}

// mo caching of documents
_httpConnection.setUseCaches(false);

// only support the “POST” method
try {
_httpConnection.setRequestMethod(“POST”);
} catch(ProtocolException e) {
System.out.println(“setRquestMethod: " + e.toString());
}

// use the URL connection for output
_httpConnection.setDoOutput(true);

// set the default value of a general request property
_httpConnection.setRequestProperty(S_CONTENT_TYPE, TYPE_TEXT_XML);

// use the URL connection for input
_httpConnection.setDoInput(true);

// send the document and receive the reply through the HTTP connection
int responseCode = 0;
byte[] rDataArray = null;
try{
httpSend(_httpConnection);
System.out.println(“send was sucessfull”);
rDataArray = httpReceive(_httpConnection);

// get and check the three digit HTTP status code where
// 1xx: Informational
// 2xx: Success
// 3xx: Redirection
// 4xx: Client Error
// 5xx: Server Error
responseCode = _httpConnection.getResponseCode();
System.out.println(”-----> Response Code: " + responseCode);

// print the error message if the status code is not 200 (HTTP_OK)
if (responseCode != HttpURLConnection.HTTP_OK) {
System.out.println(“HttpURLConnection response error\n”+responseCode);
//throw new LicenseChkrException(“some error occured while connecting to mediator”);
return null;
}
return rDataArray;
} catch(Exception e) {
System.out.println("Error! " + _url + “: " + e.toString());
return null;
}finally{

// disconnet the HTTP connection
_httpConnection.disconnect();
System.out.println(”
******** done **********\n");
}
}

/
* httpSend will send the document out through the opened
* HTTP connection.
*/
private static void httpSend(HttpURLConnection _httpConnection) throws Exception
{
System.out.println(“httpSend: … start …”);

int responseCode = 0;
String msg = null;

try {
System.out.println(“>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n” + new String(_dataArray));

// write the document to the output stream of the HTTP connection
_httpConnection.getOutputStream().write(_dataArray);

System.out.println(“>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n”);
} catch(IOException e) {
msg = "httpSend: " + e.toString();
System.out.println(msg);
throw new Exception(msg);
} finally {
// close the output stream of the HTTP connection if error
_httpConnection.getOutputStream().close();
}

System.out.println("httpSend: … done … bytes sent: " + _dataArray.length);
}

/

* httpReceive will receive the reply document through the opened
* HTTP connection.
*/
private static byte httpReceive(HttpURLConnection _httpConnection) throws Exception
{
System.out.println(“httpReceive: … start …”);

int rContentLength = 0;
byte rDataArray = null;

// get the content type
String rContentType = _httpConnection.getContentType();

// use application/xml if no content type is specified
if (rContentType == null)
rContentType = TYPE_APPLICATION_XML;

// read the document from the output stream of the HTTP connection
byte buf = new byte[4096];
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
InputStream is = _httpConnection.getInputStream ();
for (int i=0; (i=is.read (buf, 0, 4096)) != -1; ) baos.write (buf, 0, i);
rDataArray = new byte[rContentLength=baos.size ()];
rDataArray = baos.toByteArray ();
} catch(IOException e) {
// cannot receive for some reason
String eMsg = “httpReceive: " + e.toString();
e.printStackTrace();
System.out.println(eMsg);
throw new Exception(e.getMessage());
} finally {
// close the output stream of the HTTP connection if error
_httpConnection.getInputStream().close();
}

// print the content type, content length, and the document
System.out.println(“httpReceive: Content-Type: " + rContentType +
“, Content-Length: " + rContentLength + “\n” +
“<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n” + new String[rDataArray) + “\n” +
“<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n” +
“httpReceive: … done … bytes received: " + rContentLength);

return rDataArray;
}
public static void main(String args)throws Exception{

System.out.println(“Checking for valid license”);
String inputXML=”<?xml version='1.0'?>ramakrishna cellexchangeKKK KKKKKKKK chess cricket KKKKKKKK shoban business KKKKKKKKvollyballtennis KKKKKKKK ”;
MediatorUtility.getResultsFromMediator(“http://localhost:8080/orchestrator/samples/data/transformsequece.xml”, inputXML);

}

} // MediatorUtility


Input xml file
==============
i am passing xml file in Mediator.java as string inputXML


Sequence File
=============
=

< !–{Name: step};{Notes: }–>






the item1.xsl file
====================

<?xml version="1.0"?>
<xsl:stylesheet version=“1.0”
xmlns:xsl=“XSLT Namespace” >

< !–

<xsl:template name=“item”>
<xsl:value-of select=“item” />

xsl:copy
<xsl:apply-templates select=“office/tellme” />
</xsl:copy>
</xsl:template>

<xsl:template name=“office”>
<xsl:value-of select=“office” />

</xsl:template>




<xsl:template match=”/”>
<xsl:call-template name=“first” />
<xsl:call-template name=“second” />
<xsl:apply-templates select=“root/person” />
</xsl:template>

<xsl:template name=“first”>
Person1 details

<xsl:value-of select=“root/person[1]/name” />

<xsl:value-of select=“root/person[1]/office” />

<xsl:value-of select=“root/hobbies[1]/first” />

<xsl:value-of select=“root/hobbies[1]/second” />

</xsl:template>

<xsl:template name=“second”>
Person2 details

<xsl:value-of select=“root/person[2]/name” />

<xsl:value-of select=“root/person[2]/office” />

<xsl:value-of select=“root/hobbies[2]/first” />

<xsl:value-of select=“root/hobbies[2]/second” />

</xsl:template>


<xsl:template match=“root/person” >
<xsl:number value=“position[)” format="1. "/>

Person details

<xsl:value-of select=“name” />

<xsl:value-of select=“office” />

<xsl:value-of select=“hobbies/first” />

<xsl:value-of select=“hobbies/second” />


</xsl:template>

</xsl:stylesheet>


please kindly look into this

Regards
Dacha

Hi,
First, for some reason it seems that the code in your
getResultsFromMediator method to build the URL has been partially commented out, so your http request doesn’t contain any information about the location of the sequence file. If you uncomment this code you should send an extra argument:
?xbd.sequence.uri=
with the URI and this should help.

// get the URL for HTTP protocol
_url = (_sequenceFile == null) ?
_destinationURL:
_destinationURL + "?" + SEQUENCER_PROPERTY + "=" + _sequenceFile;

Next, the location of the sequence file seems to contain a typo:
MediatorUtility.getResultsFromMediator(“http://localhost:8080/orchestrator/samples/data/transformsequece.xml

Shouldn’t there be an extra “n” in transformsequence.xml?

Third, the location of the stylesheet in the SagTransformer step of the sequence should be (I think) a URL like this:

where (in my case) item1.xsl lives in the same location as the transformsequence.xml file.

Finally, the stylesheet tries to create several output elements like this:
Person1 details
Person1 details
and it is illegal to create a DOM document like this with several root nodes. So I changed your stylesheet to wrap the output in a html tag like this:
<xsl:template match=“/”>

<xsl:call-template name=“first” />
<xsl:call-template name=“second” />
<xsl:apply-templates select=“root/person” />

</xsl:template>
and now it works - I get this output:
Person1 details
ramakrishna
cellexchangeKKK

<br/
>Person2 details
shoban
business


1. Person de
tails

ramakrishna
cellexchangeKKK
chess
cricket
2.
Person details

shoban
business
vollyball
tennis


If none of this helps please let us know…

[This message was edited by Bill Leeney on 30 Dec 2002 at 10:41.]