cancel
Showing results for 
Search instead for 
Did you mean: 

XI sent an XML file to my Servlet(J2EE appl), how to display?

Former Member
0 Kudos

Hi all!

I have a scenario like FIle->XI->J2EE appl.

How to test whether XI is sending XML file to my Servlet(J2EE appl). I have to display the same XML file as it is in browser using Servlet/JSP.

Code help is highly appreciated.

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is Server Java Proxy scenario. In Proxy Implementation code, the proxyRequest parameter will have the incoming XML file. Send this xml file to J2EE application and display it there.

Regards,

Uma

Message was edited by: Uma Maheswari

Former Member
0 Kudos

Hi Uma!

Thanks for your answer.

The code is not displaying any thing on browser.

I deployed the appl on Weblogic9.0 server. How to test whether XI is sending the XML file to my J2EE appl.

I have used NWDS2.0.9 for developing J2EE appl.

This is my application.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"

"http://java.sun.com/dtd/application_1_3.dtd">

<application>

<display-name>HTTPReceiver_EAR</display-name>

<description>EAR description</description>

<module>

<web>

<web-uri>HttpReceiver.war</web-uri>

<context-root>/Invoke</context-root>

</web>

</module>

</application>

This is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>WEB APP</display-name>

<description>WEB APP description</description>

<servlet>

<servlet-name>DisplayRes</servlet-name>

<servlet-class>com.abc.DisplayRes</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>DisplayRes</servlet-name>

<url-pattern>/DisplayRes/*</url-pattern>

</servlet-mapping>

</web-app>

public class DisplayRes extends HttpServlet {

public void doGet(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException

{

doWork(requset, response);

}

public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

{

doWork(req, resp);

}

private void doWork(HttpServletRequest req, HttpServletResponse resp) throws IOException

{

String path = null;

Writer out = null;

//PrintWriter out = null;

PrintWriter p2=resp.getWriter();

//ServletOutputStream outp = resp.getOutputStream();

//p2.println("This is doWork");

try

{

resp.setContentType("text/xml");

out = resp.getWriter();

// out.println("hi");

path = req.getPathInfo();

//p2.println("path is"+ path);

if(req.getContentLength() != -1){

outputURI(req.getInputStream(), out);

}

} catch (IOException ioe) {

p2.println("IOException "+ ioe);

//return;

}

}

//private void outputURI(InputStream resultStream, Writer out) {

private void outputURI(InputStream resultStream, Writer out) {

if (resultStream == null) {

// no default file

// logger.error("No File to return");

return;

}

try {

DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();

// Class clazz = loader.loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

// DocumentBuilderFactoryImpl factory = (DocumentBuilderFactoryImpl) clazz.newInstance();

// DocumentBuilder parser = factory.newDocumentBuilder();

parser.setEntityResolver(new ClassPathEntityResolver());

printXML(parser.parse(resultStream), out);

resultStream.close();

} catch (Exception e) {

// logger.error("Trying to parse the output " , e);

}

}

//private void printXML(Document document, Writer writer) throws Exception {

private void printXML(Document document, Writer writer) throws Exception {

Transformer transformer = TransformerFactory.newInstance().newTransformer();

Source source = new DOMSource(document);

Result output = new StreamResult(System.out);

transformer.transform(source, output);

// Write as XML so that entity references can be resolved.

if (writer != null) {

transformer.transform(source, new StreamResult(writer));

}

}

}

Help is highly rewarded.

Thanks

Former Member
0 Kudos

The code required to do this would be

BufferedReader brin =
new BufferedReader(new InputStreamReader(request.getInputStream()));
 
String inputLine;
StringBuffer sBuf = new StringBuffer();
while ((inputLine = brin.readLine()) != null)
     sBuf.append(inputLine);
brin.close();
PrintWriter out = response.getWriter();
out.setContentType("text/xml");
out.write(sBuf.toString);
out.flush();

<b>Reward helpful answers!!!</b>

Former Member
0 Kudos

Hi Amol!

The XML page cannot be displayed

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

-


XML document must have a top level element. Error processing resource 'http://10.7.1.36:7001/Invoke/DisplayRes'.

I am getting the following error. My question is whether XI is sending XML file to my servlet or not? How to test that?

Thanks

Former Member
0 Kudos

Hi Amol!

The XML page cannot be displayed

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

-


XML document must have a top level element. Error processing resource 'http://localhost:7001/Invoke/DisplayRes'.

I am getting the following error. My question is whether XI is sending XML file to my servlet or not? How to test that?

Thanks

Former Member
0 Kudos

Hi,

I got this error when '.ear' file is deployed on Weblogic application server9.0.

The XML page cannot be displayed

Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.

-


XML document must have a top level element. Error processing resource 'http://localhost:7001/Invoke/DisplayRes'.

I am getting the following error. My question is whether XI is sending XML file to my servlet or not? How to test that?

Thanks

Answers (0)