I'm not familair with RPCElement and my memory on axis 1.x is a bit
hazy ... but it looks like you are invoking a client and are trying to
parse a soap body into elements.
Here's some code that does precisely that. Look at OMElement resultOM
.., one example just prints out the results while the commented out
one gets the child.
package client;
import java.io.StringWriter;
import javax.xml.stream.XMLOutputFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
// jira imports
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.client.OperationClient;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.namespace.QName;
import org.apache.axis2.wsdl.WSDLConstants;
public class TestCW {
/** Access point inside the servlet container. **/
private static EndpointReference targetEPR =
new EndpointReference(
"http://localhost:8080/axis2/services/SpringAwareService");
/**
* Simple axis2 client.
*
* @param args Main
*/
public static void main(String[] args) {
try {
ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTo(targetEPR);
/* code to test close_wait jira axis2-935 */
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(HTTPConstants.SO_TIMEOUT,1);
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.FALSE);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 5);
MessageContext requetMessageContext = new MessageContext();
requetMessageContext.setEnvelope(getRequestEnvelope());
OperationClient opClient =
serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
opClient.addMessageContext(requetMessageContext);
opClient.setOptions(options);
/* end extra jira code */
opClient.execute(true);
SOAPEnvelope result = opClient.getMessageContext(
WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope();
printResult(result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static SOAPEnvelope getRequestEnvelope() {
SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
OMNamespace omNs = fac.createOMNamespace(
"http://springExample.org/example1", "example1");
OMElement method = fac.createOMElement("getValue", omNs);
OMElement value = fac.createOMElement("Text", omNs);
value.addChild(fac.createOMText(value, "Some String "));
method.addChild(value);
envelope.getBody().setFirstChild(method);
return envelope;
}
public static void printResult(SOAPEnvelope result) {
try {
if (result != null) {
//OMElement resultOM =
result.getBody().getFirstChildWithName(new QName("example1"));
OMElement resultOM = result.getBody();
StringWriter writer = new StringWriter();
resultOM.serialize(XMLOutputFactory.newInstance()
.createXMLStreamWriter(writer));
writer.flush();
System.out.println("Response: " + writer.toString());
} else
System.out.println("Result is null");
} catch (Exception e) {
e.printStackTrace();
- Hide quoted text -
}
}
}
On 9/22/06, Liping Guo <[EMAIL PROTECTED]> wrote:
Hi,
I am trying to convert our web service application from axis to axis2.
The sample axis code is the following:
----------------------------------------------------------------
void doService(MessageContext ctxt){
// retrieve the soap envelope
// retrieve the soap envelope
SOAPEnvelope requestEnv = null;
Vector bodyElements = null;
Enumeration e0 = null;
requestEnv = ctxt.getRequestMessage().getSOAPEnvelope();
bodyElements = requestEnv.getBodyElements();
e0 = bodyElements.elements();
while (e0.hasMoreElements()) {
// recurse through the soap body and retrieve the
// rpc elements, the rpc elements contain the
// embeded objects which were returned from the service
RPCElement rpcElement = (RPCElement) e0.nextElement();
Vector params = rpcElement.getParams();
Enumeration e1 = params.elements();
while (e1.hasMoreElements()) {
RPCParam rpcParam = (RPCParam) e1.nextElement();
Object param = null;
param = rpcParam.getObjectValue();
// perform some service
// ......
}
}
}
--------------------------------------------------------
In axis, there is an RPCElement class can be used to pull out SOAP input
object's information, but in axis2, it seems that RPCElement can not be used
anymore. Question is which class in axis2 can be used as substitute for
RPCElement. I found "RPCRequestElement" and "RPCRespondElement" classes in
axis2 web site, but not sure they are the right answer, if yes, which axis2
jar they belong to?
How to replace above highlighted code by using axis2? Is there any examples
I can look at?
Any help is highly appreciated!
Liping
________________________________
The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]