You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Mike Oliver <ol...@appsaspeers.com> on 2003/01/28 16:17:35 UTC

RE: [AXIS4STRUTS]Generating XML from Struts JSP

Object Oriented Programmer Syndrome, aka OOPS.

I forgot to say this is up on the web and you can play (not abuse
please, it is my pipe/bandwidth) at:

http://soap2k.appsaspeers.com:8080/struts-example/

Logon and enter your registration info and then go back to Edit
Registration and change the URL from 

http://soap2k.appsaspeers.com:8080/struts-example/editRegistration.do?ac
tion=Edit 

to

http://soap2k.appsaspeers.com:8080/struts-example/AxisEditRegistration.d
o?action=Edit

And see what you get.  

In the example below the strutsURL would be
"http://soap2k.appsaspeers.com:8080/struts-example/editRegistration.do"
There would be one name value pair for "action=Edit" and the SOAP
response payload would be the same xml you get from the above URL.

So I am sure you are all asking, if it is that easy, why Axis, why WSDL?

The answer is that when we are done, the Axis4Struts components
shouldn't need to be changed to access almost any struts unmodified
action/bean and post and get data back, you will be able to use the
tools out there to access an Axis4STruts Web Service from Perl, Java,
C++, VB, C#, etc.  

Again that doesn't mean we are advocating the extreme use of Axis4Struts
for anything but an occasional or trivial alternate access method via
SOAP/Axis.  If you do need more, then you can see what we did and extend
it to meet your needs.

Michael Oliver
AppsAsPeers LLC
7391 S. Bullrider Ave.
Tucson, AZ 85747
Phone:(520)574-1150
Fax:(520)844-1036


-----Original Message-----
From: Mike Oliver [mailto:ollie@appsaspeers.com] 
Sent: Tuesday, January 28, 2003 7:30 AM
To: 'Struts Users Mailing List'
Subject: RE: [AXIS4STRUTS]Generating XML from Struts JSP

Craig, Excellent!  

That leads to the not so trivial, for Axis4Struts to work as envisioned,
the Axis stubs and WSDL will be generated from a class with at least one
method similar to: (other overloaded methods probable)

Public String StrutsExecute(String strutsURL, 
                            NameValuePair[] strutsFormData,
                            NameValuePair[] strutsServerHeaders){
	//Construct HttpClient
	//get connection to struts server
	//create and populate a post from strutsURL, strutsFormData 
	//  and strutsServer headers
	//execute the post method 
	//return responseXml
}

A trivial example of a struts-config.xml element to register an action
to be called from Axis4Struts to get the current registration record
from the struts example and reuse of a Struts action class without any
modifications:

<action path="/AxisEditRegistration" 
   type="org.apache.struts.webapp.example.EditRegistrationAction" 
   attribute="registrationForm" scope="request" validate="false">
   <forward name="success" path="/AxisRegistration.jsp" /> 
</action>

The AxisRegistration.jsp would be very similar to the original
registration.jsp, something like the following without the html
formatting tags:

  <%@ page contentType="text/xml" %>
  <%@ taglib prefix="bean" uri="http://jakarta.apache.org/struts/bean"
%>
  <%@ taglib prefix="logic" uri="http://jakarta.apache.org/struts/logic"
%>
  <registrationForm>
    <username>
       <bean:write name="registrationForm" property="username"/>
    </username>
    <password>
       <bean:write name="registrationForm" property="password"/>
    </password>
    <fullName>
       <bean:write name="registrationForm" property="fullName"/>
    </fullName>
    <fromAddress>
       <bean:write name="registrationForm" property="fromAddress"/>
    </fromAddress>
    <replyToAddress>
       <bean:write name="registrationForm" property="replyToAddress"/>
    </replyToAddress>
  </registrationForm>

This should be easy enough to understand and use, but I would like to go
one step further.

The Axis4Struts.jsp would be a reusable jsp (and hopefully included in
the distribution) that any action could be configured to use to output
xml for Axis from any bean ala DynaBean reflection, you would simply
pass in the bean name as an argument, then dynamically build the xml for
all the bean's named values.  The struts-config.xml action element would
look something like:

<action path="/AxisEditRegistration" 
   type="org.apache.struts.webapp.example.EditRegistrationAction" 
   attribute="registrationForm" scope="request" validate="false">
   <forward name="success"
path="/Axis4Struts.jsp?beanName=registrationForm" /> 
</action>


Michael Oliver
AppsAsPeers LLC
7391 S. Bullrider Ave.
Tucson, AZ 85747
Phone:(520)574-1150
Fax:(520)844-1036

-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org] 
Sent: Monday, January 27, 2003 10:41 PM
To: Struts Users Mailing List
Subject: Re: [AXIS4STRUTS]Generating XML from Struts JSP



On Mon, 27 Jan 2003, Michael Oliver wrote:

> Date: Mon, 27 Jan 2003 22:04:48 -0700
> From: Michael Oliver <ol...@appsaspeers.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: [AXIS4STRUTS]Generating XML from Struts JSP
>
> Has anyone used JSP with Struts to generate XML?
> http://java.sun.com/products/jsp/html/JSPXML.html
>
> Would anyone be interested in a struts-xml.tld and the associated
custom
> tag classes?
>
> If so what kinds of tags would you want? bean name and value?
>
> Can we just add a few XML oriented tags to the struts-html.tld and
> html/custom tag classes?
>
> DynaBean Tags?
>
> Build an xml document from the contents of a DynaBean?
>
> Just some of the things we might want for Axis4Struts and others may
> want too.
>

I use JSP to render XML with the standard Struts tag libraries and it
works quite well.  The <bean:write> tag already supports DynaBeans,
<logic:iterate> works great for looping through data structures, and so
on.

A trivial example similar to the XML document listed in the page you
referenced (assuming a collection of "books" that is either JavaBeans or
DynaBeans):

  <%@ page contentType="text/xml" %>
  <%@ taglib prefix="bean" uri="http://jakarta.apache.org/struts/bean"
%>
  <%@ taglib prefix="logic" uri="http://jakarta.apache.org/struts/logic"
%>
  <books>
    <logic:iterate id="book" name="books">
      <book isbn='<bean:write name="book" property="isbn"/>'>
        <title><bean:write name="book" property="title"/></title>
        <quantity><bean:write name="book"
property="quantity"/></quantity>
        <price><bean:write name="book" property="price"/></price>
      </book>
    </logic:iterate>
  </books>

Of course, you can do the same thing with JSTL tags if you've got
standard
JavaBeans as the backing data.

> Ollie

Craig


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>