Posting an xml request via JSTL XML

How would I post an xml request, such as the login one below, via JSTL XML?

<?xml version="1.0" ?>
<RequestMessage>
<TransactionName>SecurityLogin</TransactionName>
<Payload>
<Username>MyLogin</Username>
<Password>MyPassword</Password>
</Payload>
</RequestMessage>
arichexeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boonlengCommented:
You mean you want to post the XML content from one server to another server?
bugadaCommented:
bloodredsunCommented:
Can you explain what you mean by "post an xml request". Do you mean like using HttpUrlConnection and a HTTP POST request?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

arichexeAuthor Commented:
Yes, bloodredsun, using HttpUrlConnection and a HTTP POST request, which would result in a reply message that I'll parse.
bloodredsunCommented:
and you want to post this xml as the content of the Connection.

So maybe somehting like this then

         URL url = new URL("http://www.blah.com");
         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
         connection.setRequestMethod("POST") ;
         PrintStream outStream = null;
         String xmlFile= "<blah/>";//read your xml file as a String from the file
         connection.setDoOutput(true);
         outStream.println(xmlFile);
         outStream.close();

This is just cobbled together to give you an idea, it won't compile due to Exceptions that need to be caught.
arichexeAuthor Commented:
Say I want to post the below request to http://www.blah.com, and then parse through the reply.  Given the above example, how would I code such?  Can I use JSTL XML?

POST /ObjectsLib/servlet/SecurityServlet HTTP/1.0
Accept: *.*
Content-Type: text/xml
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Length: 200

<?xml version="1.0" ?>
<RequestMessage>
<TransactionName>SecurityLogin</TransactionName>
<Payload>
<Username>MyLogin</Username>
<Password>MyPassword</Password>
<Domain>prod</Domain>
</Payload>
</RequestMessage>
bloodredsunCommented:
You can't code an HttpUrlConnection in JSTL, you'd have to do that in a scriptlet, but you would be able to access the parameter string by using the param object in JSTL and then manipulate it via the xml library tags.

Can you please explain in a step-by-step manner what you are trying to do as I can't get my head around what you are trying to do.
arichexeAuthor Commented:
I want to send/post a request to an http server, and then read the status from the reply.  See sample request and reply below:

Content-Type: text/xml
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Length: 200
<?xml version="1.0" ?>
<RequestMessage>
<TransactionName>SecurityLogin</TransactionName>
<Payload>
<Username>MyLogin</Username>
<Password>MyPassword</Password>
<Domain>prod</Domain>
</Payload>
</RequestMessage>

<?xml version="1.0" ?>
<ReplyMessage>
<TransactionId>20009</TransactionId>
<Status>Success</Status>
<StatusDescription>Login completed successfully.</StatusDescription>
</ReplyMessage>
arichexeAuthor Commented:
Below is the solution:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/io-1.0" prefix="io" %>

<c:set var='txtReply'>
<io:http url="someURL" action="POST">
  <io:header name="Content-Type" value="text/xml"/>
  <io:body>
    <RequestMessage>
    <TransactionName>SecurityLogin</TransactionName>
    <Payload>
    <Username>MyLogin</Username>
    <Password>MyPassword</Password>
    <Domain>prod</Domain>
    </Payload>
    </RequestMessage>
  </io:body>
</io:http>
</c:set>

<x:parse xml="${txtReply}" var="xmlReply"/>
<x:if select='$xmlReply//Status = "Success"'>
  <p>Login Successful</p>
</x:if>
<x:if select='$xmlReply//Status != "Success"'>
  <p>Login Unsuccessful</p>
</x:if>
CetusMODCommented:
PAQ'd, 125 points refunded.
CetusMOD
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.