Returning XML String From Servlet
Is there a simple way to disable the HTML character escaping when returning
a string from a servlet. The returned string contains well formed XML, and
I don't want the tags converted to > and < meta characters in the
HTTP reply.
The code is basically "hello world", version 7.0 SP2.
Thanks
> package xxx.servlet;
>
> import weblogic.jws.control.JwsContext;
>
>
> /**
> * @jws:protocol http-xml="true" form-get="false" form-post="false"
> */
> public class HelloWorld
> {
> /** @jws:context */
> JwsContext context;
>
> /**
> * @jws:operation
> * @jws:protocol http-xml="false" form-post="true" form-get="false" soap-s
tyle="document"
> * @jws:return-xml xml-map::
> * <HelloWorldResponse xmlns="http://www.xxx.com/">
> * {return}
> * </HelloWorldResponse>
>
> * ::
> * @jws:parameter-xml xml-map::
> * <HelloWorld xmlns="http://www.xxx.com/">
> * <ix>{ix}</ix>
> * <contents>{contents}</contents>
> * </HelloWorld>
>
> * ::
> */
> public String HelloWorld(String s)
> {
> return "<a> xyz </a>";
> }
> }
Radha,
We have a client/server package which speaks SOAP over a
streaming HTTP channel for which we are writing a WebLogic
servlet. For reasons of efficiency, we want to deserialize
only the very top-level tags of the messages as they pass
through the servlet. Yes, in theory, we should probably
deserialize and validate the entire message contents...
When we add support for other clients, we will fully
deserialize inside those servlets.
I have not looked any further into how to stop the inner
tags from being escaped yet -- it is an annoyance more than
a disaster, since the client handle meta escapes.
My current guess is to use ECMAScript mapping...
-Tony
"S.Radha" <[email protected]> wrote:
>
>"Tony Hawkins" <[email protected]> wrote:
>>
>>Is there a simple way to disable the HTML character escaping when returning
>>a string from a servlet. The returned string contains well formed XML,
>>and
>>I don't want the tags converted to > and < meta characters in the
>>HTTP reply.
>>
>>The code is basically "hello world", version 7.0 SP2.
>
>>
>>Thanks
>>
>>> package xxx.servlet;
>>>
>>> import weblogic.jws.control.JwsContext;
>>>
>>>
>>> /**
>>> * @jws:protocol http-xml="true" form-get="false" form-post="false"
>>> */
>>> public class HelloWorld
>>> {
>>> /** @jws:context */
>>> JwsContext context;
>>>
>>> /**
>>> * @jws:operation
>>> * @jws:protocol http-xml="false" form-post="true" form-get="false"
>>soap-s
>>tyle="document"
>>> * @jws:return-xml xml-map::
>>> * <HelloWorldResponse xmlns="http://www.xxx.com/">
>>> * {return}
>>> * </HelloWorldResponse>
>>>
>>> * ::
>>> * @jws:parameter-xml xml-map::
>>> * <HelloWorld xmlns="http://www.xxx.com/">
>>> * <ix>{ix}</ix>
>>> * <contents>{contents}</contents>
>>> * </HelloWorld>
>>>
>>> * ::
>>> */
>>> public String HelloWorld(String s)
>>> {
>>> return "<a> xyz </a>";
>>> }
>>> }
>>
>>
>Hi Tony,
>
> Can you let me know for what purpose you want to disable the
>HTML character
>escaping.In case if you
>
>have tried this using someway,pl. let me know.
>
>rgds
>Radha
>
>
Similar Messages
-
Sending long XML strings from a servlet
Hi,
I'm trying to send a long (16K) XML string from a Java servlet to a
MSXML2.XMLHTTP40 client. The client doesn't receive any data when the
string is longer than about 2K .
I am using the POST method.
I have tried increasing the buffer size on the sending side with
HttpServletResponse.setBufferSize() - this had no effect.
Any ideas ?
Thanks very much for your help,
RodLooks like the problem is on the client side (MSXML) because I can flawlessly send half-megs XML files from a Servlet to a browser or a java.net.URL
-
How to create XML string from BPM Business Object?
Hello,
I have a business object in my BPM project and I need to transform it in a XML string:
From:
Business Object: Customer
Properties: Name, Age
To:
"<Customer><Name>Robert</Name><Age>17</Age></Customer>"
How can I do this?
Thanks.Hello,
I have a business object in my BPM project and I need to transform it in a XML string:
From:
Business Object: Customer
Properties: Name, Age
To:
"<Customer><Name>Robert</Name><Age>17</Age></Customer>"
How can I do this?
Thanks. -
Passing XML payload from Servlet to JMS
Hi All,
My requirement is that servlet will receive the HTTP request , convert it into XML format and publish it to JMS queue.
Now, I am stuck at the part where I need to publish the XML payload to JMS queue.
Is it possible to send the XML payload from servlet to JMS queue? Is yes, please let me know how can we achieve this.
ThanksI suggest you go to the following page: [http://edocs.bea.com/wls/docs103/pdf.html] .
In the "Programming" section, download and read at least "Programming WebLogic JMS" and perhaps "Developing Web Applications, Servlets, and JSPs for WebLogic Server" and "Developing Applications with WebLogic Server". -
Returning the string from the SimpleDateFormat
Hi guys,
Can someone tell me how to return the string from the SimpleDateFormat?
I've created the method to do this, but i don't know the exact code to use. Here's my code so far...
public String convert (Calendar gc)
String s = convert(gc);
return // I need to return the s here, but don't know how to code it.
}BTW, i've already wrote the code for the SimpleDateFormat (so if you want me post that, i will).DrLaszloJamf wrote:
LevelSix wrote:
DrLaszloJamf wrote:
No.Can you tell me what it is, because i've went through the API and i don't know.
Have you looked for a tutorial: [http://java.sun.com/docs/books/tutorial/i18n/format/dateintro.html]
Thanks a lot DrLaszloJamf, this is useful.
DrClap wrote:
Nope. Suppose you were on a construction site and the foreman told you to move a pile of concrete blocks from a truck into the building. What do you suppose would happen if you asked the foreman what a concrete block was, and where the building was, and whether you should drive the truck into the street, and then you tried to pick up the whole pile all at once, and then you asked if you could kick the blocks like footballs? This is what you're doing here. You'd be fired from the construction site within half an hour.Sir... -
Return a string from a method: a problem in C++ but is it a problem in java
I have a method which return a String from it as:
String pattern(short i)
String s="":
if (i==1)
s = "test1";
else
s = "test2";
return s;
Since s is a local vaariable to pattern(), does the code above
create problems? I know it is a problem for C++ since the local
variable memory address will be reused by others and thus the
returned value may take other values sometime later or not
readable.Actually, this is not a problem in C++ either if you
just use the string class instead of the old-style
char* from C.True, I was assuming he/she meant (in C++):
char mylocalbuf[80];
// put stuff in mylocalbuf here
return mylocalbuf;
which would be very very bad to do indeed. -
How to get an XML string from a Java Bean without wrting to a file first ?
I know we can save a Java Bean to an XML file with XMLEncoder and then read it back with XMLDecoder.
But how can I get an XML string of a Java Bean without writing to a file first ?
For instance :
My_Class A_Class = new My_Class("a",1,2,"Z", ...);
String XML_String_Of_The_Class = an XML representation of A_Class ?
Of course I can save it to a file with XMLEncoder, and read it in using XMLDecoder, then delete the file, I wonder if it is possible to skip all that and get the XML string directly ?
FrankI think so too, but I am trying to send the object to a servlet as shown below, since I don't know how to send an object to a servlet, I can only turn it into a string and reconstruct it back to an object on the server side after receiving it :
import java.io.*;
import java.net.*;
import java.util.*;
class Servlet_Message // Send a message to an HTTP servlet. The protocol is a GET or POST request with a URLEncoded string holding the arguments sent as name=value pairs.
public static int GET=0;
public static int POST=1;
private URL servlet;
// the URL of the servlet to send messages to
public Servlet_Message(URL servlet) { this.servlet=servlet; }
public String sendMessage(Properties args) throws IOException { return sendMessage(args,POST); }
// Send the request. Return the input stream with the response if the request succeeds.
// @param args the arguments to send to the servlet
// @param method GET or POST
// @exception IOException if error sending request
// @return the response from the servlet to this message
public String sendMessage(Properties args,int method) throws IOException
String Input_Line;
StringBuffer Result_Buf=new StringBuffer();
// Set this up any way you want -- POST can be used for all calls, but request headers
// cannot be set in JDK 1.0.2 so the query string still must be used to pass arguments.
if (method==GET)
URL url=new URL(servlet.toExternalForm()+"?"+toEncodedString(args));
BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream()));
while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
else
URLConnection conn=servlet.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
// Work around a Netscape bug
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
// POST the request data (html form encoded)
DataOutputStream out=new DataOutputStream(conn.getOutputStream());
if (args!=null && args.size()>0)
out.writeBytes(toEncodedString(args));
// System.out.println("ServletMessage args: "+args);
// System.out.println("ServletMessage toEncString args: "+toEncodedString(args));
BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
out.flush();
out.close(); // ESSENTIAL for this to work!
return Result_Buf.toString(); // Read the POST response data
// Encode the arguments in the property set as a URL-encoded string. Multiple name=value pairs are separated by ampersands.
// @return the URLEncoded string with name=value pairs
public String toEncodedString(Properties args)
StringBuffer sb=new StringBuffer();
if (args!=null)
String sep="";
Enumeration names=args.propertyNames();
while (names.hasMoreElements())
String name=(String)names.nextElement();
try { sb.append(sep+URLEncoder.encode(name,"UTF-8")+"="+URLEncoder.encode(args.getProperty(name),"UTF-8")); }
// try { sb.append(sep+URLEncoder.encode(name,"UTF-16")+"="+URLEncoder.encode(args.getProperty(name),"UTF-16")); }
catch (UnsupportedEncodingException e) { System.out.println(e); }
sep="&";
return sb.toString();
}As shown above the servlet need to encode a string.
Now my question becomes :
<1> Is it possible to send an object to a servlet, if so how ? And at the receiving end how to get it back to an object ?
<2> If it can't be done, how can I be sure to encode the string in the right format to send it over to the servlet ?
Frank -
Returning xml string in web service call
hi all
i'm writing a server-side web service
one method i am writing returns a recordset from a db query. i then use jdom to trasnform the recorset to xml and i retrun the xml as a string
however, my client who is using this web service is having difficulty with the xml string i return - instead of angle brackets it is retruned as &alt &agt
the client is now able to get rid of the &alt signs but now he cannot traverse through the xml to get the elemnts
i'm using this code to retrun the xml
how do others retrun xml within their web sevices?
try
RecordsetToXML rsXML = new RecordsetToXML(rs, "ROOT", "UCWSTATS");
Document jDOMDoc = rsXML.build();
rs = null;
XMLOutputter outputter = new XMLOutputter();
outputter.output(jDOMDoc, writer);
result = writer.toString();
writer.close();
return result;Does result end up with a String containing the offending encoded characters, or does it occur when you transfer the xml over the pipe?
-
Hi
I have requirement in which i have a jsp that i use to get information from users. I need to convert the info to XML data into a String , whihc i later use to pass as messages using AQ.
I also have to, at a later point retreive the data from the XML String, update some information and recreate the XML string object with the new data.
I do not want to use the XML SQL Utility as this could provide too costly in terms of database hits .
Is there some XML Parser methods i can use to do the generation and retrieval of XML data into Strings.
Thanks
nullSort of hack but the way I did it was
Convert to String:
Construct a ByteArrayOutputStream
print your documenet to this,
and then call the toString() on the
ByteArrayOutputStream.
Convert from String to an XMLDocument:
Construct a StringReader(String s)
Construct a DOMParser and parse the
StringReader.
Hope this helps.
null -
Convert XML-String from Codepage utf-16 to ISO-8859-1
Hi to all experts,
our system is now unicode with codepage 4102 (UTF-16) and we do an Simple Transformation for creating an XML-String.
before UniCode : xml_data = <?xml version="1.0" encoding="iso-8859-1"?>#<transactionRequest userID=" .......
now with UniCode : xml_data = <?xml version="1.0" encoding="utf-16"?>#<transactionRequest userID=".......
The xml_data transfered to an external Sytem via HTTPS- Communication direct from ABAP.
The external Sytem send an Error Request:
<?xml version="1.0" encoding="ISO-8859-1"?>#<transactionResponse># <transactionErrorResponse># <errorResponse># <errorCode>SYS-0001</errorCode># <errorDescription>java.lang.Exception: null[ #<?xml version="1.................
Have you any idea
Thanks for your help!
Peter
Edited by: Peter Pforr on Sep 25, 2008 9:59 AM
Edited by: Peter Pforr on Sep 25, 2008 10:14 AMDarshan,
Did you get an answer for this question? We have same requirement to create XML file in ISO-8859-1 format with Attributes is set to "Y" and CDATA is being used for data.
Can you please let me know if you still remember how did you achieve it?
Satyen... -
Returning XML Data from a database
Ok, just got the new DW CS3 and really want to begin using
the built in Spry capabilitites. All of the examples I've seen for
populating the datasets with XML data are based on referencing a
static XML file. I want to query my database and return XML data to
a Spry Table. How do I accomplish this? I know how to perform the
query and retrun the data in an XML format (ColdFusion) but I can't
tell the spry dataset to use this. HELP!!Well, that's the trick... I can't point to a testing server
(i.e. Application interface) because we aren't permitted to have
the RDS login where I work. (They haven't bothered to configure the
CF server for restricting access) I have to manually create all
connections and queries. I'm currenlty using the exact format in
the example page you provided to return the data in an XML format
but when I point to that file as my datasource I get nothing
displayed on the page. The file that performs the query and returns
the data is in a separate file from the one I'm trying to use the
Spry table in. When I use this same query file for an Ajax call to,
say, populate a listbox or pulldown menu it works fine, but I can't
get it to work with the Spry dataset. -
Queue returns blank strings from template VI
I have created a master VI which creates a named queue, this VI then spawns multiple copies of a template VI. These sub VIs all gain access to the queue and try writing data to it. I understood that the queue VI was protected so this should not cause a problem. Infact this does not work at all, when i extract element within the master VI it only finds a few of the elements and returns blank strings between. Help what is going on. I am not destroying the queue or such, it seems to be a problem with the protection of the queue when using template VIs.
Cheers Tom.I have not been able to reproduce the problem on LV 6.0.2 Win98. Do you check the error cluster when an empty element is returned? Posting your code might help to find the problem.
LabVIEW, C'est LabVIEW -
Return XML/HTTP from a servlet
Hi,
I want to design a servlet which will will be invoked from an application residing in a different web server and the second application will get back an XML blob as a return.
The whole connection will be based on HTTP ofcourse(no SOAP etc).
Any suggestions on how to achieve this?
Thanks in advance,
SunetraWrite a servlet that sends back xml?
Not really sure what your problem is. -
Hi How to get XML file from servlet that XI sent to my J2EE appl?
Hi All!
I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
Please help me its urgent, Any code help is highly appreciated.
My xml file will be like this:
<ns0:Http_Message_Type_Demo
xmlns:ns0="http://abcdemo.com">
<Name>ABC</Name>
<RollNo>123</RollNo>
<Address>a-4</Address>
</ns0:Http_Message_Type_Demo>
somebody should help me!please
ThanksHi,
You can use HTTPServletRequest object to get the XML payload.
BufferedReader reader = request.getReader(); //gets XML payload
String line = reader.readLine(); // to read the XML payload line by line
(request is the HTTPServletRequest object)
Regards,
Uma -
Returning a string from one class to another
I have a file from where i creating an object of another class and calling the fuctionsl
This is how i am doing
public login()
String input =new String (passwordField.getPassword());
input= input.trim();
tempuser= userField.getText();
db2sqln patientsqln =new db2sqln(); //creating an object
patientsqln.connectdb2();// calling a connect to database function
patientsqln.dbselect(tempuser);// passing the login informaiont
in patientsqln i am getting the password from the database and want to pass it back to login class so that i can compare the entered password and the database password
here is i am using my patientsqln.dbselect()
//public void dbselect(String userinput)
try
Statement stmt = con.createStatement();
String select = "Select patientpass from patient where PATIENTUSER="+"'"+userinput+"'";
ResultSet rs = stmt.executeQuery(select);
while (rs.next())
name=rs.getString("PATIENTPASS");
name = name.trim();
System.out.println(name+"from db2sqln");
rs.close();
My question is that everything else works fine, but i donot get any password back in login() class it returns null value. looks like i am not returing the string back. how should i do that
I am comparing like this
if(input.equals("name"))
System.out.println("Correct password");
else{
System.out.println("Incorrect password");
//I have a file from where i creating an object of another class and calling the fuctionsl
This is how i am doing
public login()
String input =new String (passwordField.getPassword());
input= input.trim();
tempuser= userField.getText();
db2sqln patientsqln =new db2sqln(); //creating an object
patientsqln.connectdb2();// calling a connect to database function
patientsqln.dbselect(tempuser);// passing the login informaiont
in patientsqln i am getting the password from the database and want to pass it back to login class so that i can compare the entered password and the database password
here is i am using my patientsqln.dbselect()
//public void dbselect(String userinput)
try
Statement stmt = con.createStatement();
String select = "Select patientpass from patient where PATIENTUSER="+"'"+userinput+"'";
ResultSet rs = stmt.executeQuery(select);
while (rs.next())
name=rs.getString("PATIENTPASS");
name = name.trim();
System.out.println(name+"from db2sqln");
rs.close();
My question is that everything else works fine, but i donot get any password back in login() class it returns null value. looks like i am not returing the string back. how should i do that
I am comparing like this
if(input.equals("name"))
System.out.println("Correct password");
else{
System.out.println("Incorrect password");
//
Maybe you are looking for
-
Hi All, We arein a process of migrating 3.x Transfer rules and update rules to NW2004s. We are following the standard procedure of migrating the objects such that transfer rules are migrated to a transformations and so do update rules. In on of the o
-
Adobe CS3 Bridge - Metadata Problem
Hello, Alot of my images (JPGs) seem to be losing their metadata, for example, if I keyword a bunch of pictures in bridge and save them. I go back the next day, and they are missing? Also when uploading to a website, if I put in copyright like this:
-
Error in FM tables parameters type.
Hi, I am creating a BAPI FM with the tables parameters with a parameter as i_ydrseg type MMCR_DRSEG. This is similar to the type as defined in the FM MRM_INVOICE_READ as T_DRSEG TYPE MMCR_TDRSEG. I have declared the MMCR as types pool
-
Workitem not seen in inbox but event is triggered in transaction SWEL.
Hi, I have created a workflow to create and display a material master using transaction MM01. My event (created) is getting triggerd when I am creating a material but the same is not seen in my business Workplace. In display event trace i am able to
-
I just installed Adobe CS3 and all the programs installed but Photoshop. I have even tried just installing Photoshop by itself and still says it failed to download. Anyone have any suggestions? I am running on OS X 10.8.2