OuputFormat and XMLSerializer's alternative?



I am making a sample web service program using WSDL and SOAP under JDK
1.4. To make that, I used a source below included in XML and JAVA;
developing web application 2nd Edition. As you know, Since the two
classes, OutputFomat and XMLSerializer, had been deprecated, I can't
use that source. To use that source, How I can modify it?? plz let me
know the ....

----------------------------------------------------
import java.io.FileReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.HttpURLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;

import com.wm.ws.mime.XmlMimeEntityHandler;
import com.wm.ws.soap.util.EnvelopeUtil;

public class SOAPHttpRequestor0 {

public static String SOAP_ENV = "SOAP-ENV:Envelope";
public static String CONTENT_TYPE_VALUE =
"text/xml; charset=UTF-8";

public static void main(java.lang.String[] args)
throws Exception {
Document doc;

// Parses the request XML with the specified charset (utf-8)
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
InputSource input =
new InputSource(new FileReader(args[0]));
doc = factory.newDocumentBuilder().parse(input);
OutputFormat formatter = new OutputFormat(doc, "utf-8",
false);
formatter.setPreserveSpace(true);

// SOAP-ENV:Envelope is added if needed
if (!doc.getDocumentElement().
getTagName().equals(SOAP_ENV)) {
Document env = EnvelopeUtil.createEmptyEnvelope();
doc = EnvelopeUtil.addBodyEntry(env, doc);
}

// Print out the request message
System.out.println("******** Request Message *******");
XMLSerializer serializer =
new XMLSerializer(System.out, formatter);
serializer.serialize(doc);

// Set up HTTP transport
URL url = new URL(args[1]);
HttpURLConnection con =
(HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type",
"text/xml; charset=UTF-8");
con.setRequestProperty("SOAPAction", "\"\"");
con.setDoOutput(true);

// Serialize and send the request message
OutputStream out = con.getOutputStream();
serializer = new XMLSerializer(out, formatter);
serializer.serialize(doc);

// You may get error
if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new Exception("Error in HttpURLConnection: " +
con.getResponseMessage());
}

// Receive response message
InputStream in = con.getInputStream();
input =

XmlMimeEntityHandler.getInputSource(con.getContentType(), in);

Document resp = factory.newDocumentBuilder().parse(input);

System.out.println("\n\n******** Response Message *******");
formatter = new OutputFormat();
formatter.setPreserveSpace(true);
serializer = new XMLSerializer(System.out, formatter);
serializer.serialize(resp);
System.out.println("\n\n******** Succeeded *******");
}
}
.



Relevant Pages

  • Re: Unable to cast MSMQ body to an object
    ... why wouldn't it use the one on the queue? ... converting it to XML anyway. ... I think this should work for an XML formatter ... You can find a decent xml serialization demo here: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: overriding webservice serializer?
    ... > webservice uses with a custom serializer. ... > compliant serializer and override the .net "default" webservice xml ... very carefully in the sample which stream is used for what in the request, ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: optional nillable values
    ... empty element into something the Xml Serializer would accept. ... > Nullable Type in XML webservice... ... > public bool ElementNameSpecified; ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: .NET objects (C#)
    ... Are there any examples of .Net classes using the BizTalk formatter or custom ... Nothing is serialized into XML. ... > message received by the orchestration, BizTalk will at this stage attempt ...
    (microsoft.public.biztalk.general)
  • Re: Binary Serialization!
    ... accomplish binary serialization under an ASP.NET Web Service? ... Did you know that Web Services communicate using XML? ... types and the like whilst the XML Formatter and/or Soap Formatter ...
    (microsoft.public.dotnet.framework.aspnet.webservices)