Hope the below will provide you an example
If I read this correctly your user is calling the service and your are
returning a collection of objects as in your example. I do this with a list
sequence using the Object Model and returning a
org.apache.axiom.soap.SOAPEnvelope envelope:
1. Build the envelope from your POJO list and/or bean objects:
private org.apache.axiom.soap.SOAPEnvelope getSoapMessage(ExampleBean pco,
List exampleList) throws ErrorException, IOException {
try {
factory = new
org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory();
envelope = factory.getDefaultEnvelope();
envelope.getHeader().detach();
org.apache.axiom.soap.SOAPBody body =
envelope.getBody();
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs =
fac.createOMNamespace("http://example.namespace.com", "");
org.apache.axiom.om.OMElement punchoutResponse =
fac.createOMElement(WSConstants.Punch_Out_Response, omNs);
org.apache.axiom.om.OMElement exampleResponse =
fac.createOMElement(WSConstants.RESPONSE_URL, omNs);
org.apache.axiom.om.OMElement exampleWarnings =
fac.createOMElement(WSConstants.RESPONSE_WARNINGS, omNs);
org.apache.axiom.om.OMElement exampleWarning =
fac.createOMElement(WSConstants.RESPONSE_WARNING, omNs);
if (pco.getExample().equalsIgnoreCase("")) {
exampleResponse.addChild(fac.createOMText(exampleResponse, ""));
} else {
exampleResponse.addChild(fac.createOMText(exampleResponse, ""
+pco.getExampleResponseUrl()));
}
if (exampleList.isEmpty()) {
exampleWarning.addChild(fac.createOMText(warnings, ""));
} else {
for (int j=0; j < candidateList.size(); j++) {
exampleWarning.addChild(fac.createOMText(warnings, ""
+exampleList.get(j).toString()));
}
}
exampleWarningWarnings.addChild(exampleWarning);
punchoutResponse.addChild(exampleResponse);
punchoutResponse.addChild(exampleWarnings);
body.addChild(punchoutResponse);
} catch (org.apache.axiom.soap.SOAPProcessingException e) {
e.getStackTrace();
ErrorException failedSOAP =
utils.getErrorMessage(WSConstants.FAILED_SOAP_MESSAGE);
throw failedSOAP;
}
return envelope;
}
2. In the main adapter I then call this method:
try {
// pass in your list or bean object
return getSoapMessage(pco,
exampleList);
} catch (IOException e1) {
e1.printStackTrace();
logger.debug("SOAP Message
Failed >>>>> " +e1.getMessage());
ErrorException authEX =
utils.getErrorMessage(WSConstants.FAILED_SOAP_MESSAGE);
throw authEX;
}
3. Which is called by the Skeleton, which is then calle bye the
MessageReceiver:
public org.apache.axiom.soap.SOAPEnvelope
create(org.apache.axis2.context.MessageContext msgContext) throws
ErrorException {
envelope = msgContext.getEnvelope();
try {
SOAPBody body = envelope.getBody();
if (body == null) {
ErrorException run =
utils.getErrorMessage(WSConstants.SOAP_MESSAGE_MISSING); // chek soap body
throw run;
}
// GET THE FIRST ELEMENT
.... Set objects for POJO ...
service = new ExampleManagerImpl();
envelope =
service.create(this.getExampleBean()); // pass in bean
} catch (OMException e) {
ErrorException ex =
utils.getErrorMessage(WSConstants.SERVICE_FAILED); // if service fails
throw ex;
}
return envelope;
}
// Message Receiver/Sender
public void invokeBusinessLogic(
org.apache.axis2.context.MessageContext msgContext,
org.apache.axis2.context.MessageContext
newMsgContext)
throws org.apache.axis2.AxisFault {
try {
// get the implementation class for the Web Service
Object obj = getTheImplementationObject(msgContext);
SkeletonInterface skel = (SkeletonInterface) obj;
org.apache.axiom.soap.SOAPEnvelope envelope = null;
// Find the axisOperation that has been set by the
Dispatch phase.
org.apache.axis2.description.AxisOperation op =
msgContext.getOperationContext().getAxisOperation();
if (op == null) {
throw new
org.apache.axis2.AxisFault("Operation is not located");
}
if (op.getName() != null) {
if
("create".equals(op.getName().toString())) {
envelope = skel.create(msgContext);
// pass in the message context
}
newMsgContext.setEnvelope(envelope); return
the new context with your envelope
}
} catch (ErrorException e) {
org.apache.axis2.AxisFault f =
utils.createAxisFault(e);
f.setDetail(utils.toOM(e.getFaultMessage(), false));
throw f;
} catch (Exception e) {
ErrorException ex =
utils.getErrorMessage(WSConstants.SERVICE_FAILED);
org.apache.axis2.AxisFault f =
utils.createAxisFault(ex);
f.setDetail(utils.toOM(ex.getFaultMessage(),
false));
throw f;
}
}
-----Original Message-----
From: Kencana [mailto:[EMAIL PROTECTED]
Sent: Friday, May 04, 2007 4:20 AM
To: [email protected]
Subject: Returning arrayList
Hi all,
Lets say, there are many fields on the database table.
so when user wants to retrieve all the data, basically what i did in normal
java application is I bind it to an arrayList.
so my question is, can axis return arrayList data type?
or is there any other solution to let user retrieve all the data from the
table fields and bind it to the xml file.
for example:
<user>
<name>Kencana</name>
<gender>female</gender>
</user>
<user>
<name>Bob</name>
<gender>Male</gender>
</user>
sorry for my poor explanation, I hope you guys can understand what I am
trying to do
Thanks
Regards,
Kencana
--
View this message in context:
http://www.nabble.com/Returning-arrayList-tf3691291.html#a10320177
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]