axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hickman, Craig" <Craig_Hick...@ADP.com>
Subject RE: Returning arrayList
Date Mon, 07 May 2007 15:19:28 GMT
I know you can do it with AxisC project:

Look at WSO2

http://wso2.org/library/271

Article by: Kaushalye Kapuruge 

One decision is to use an environment structure. This environment
encapsulates memory management, error handling, logging and threading
mechanisms. This allows others to use their own implementations for above
mechanisms in integrating Axis2/C. To elaborate this a bit more, think about
memory allocation in Axis2/C's PHP extension which is implemented using the
interface with emalloc and efree. If you have already gone through the
Axis2/C source you might have seen that the environment object is passed
around every function to make sure the above objective is achieved.
 

-----Original Message-----
From: Kencana [mailto:bluesky_dyx@hotmail.com] 
Sent: Sunday, May 06, 2007 10:00 PM
To: axis-user@ws.apache.org
Subject: RE: Returning arrayList


Hi Craig,

Thanks for the explanation. anyway, I try to return the result using AXIOM
and it works fine.
the following are the codes:
OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace ns =
fac.createOMNamespace("http://kencana.samples/xsd","ns");
OMElement activity = fac.createOMElement("activity", ns);

String query="SELECT * FROM ACTIVITY WHERE ACTIVITYNAME LIKE '%"+name+"%'";

result=stmt.executeQuery(query);
int i=1;
String elementName = "";
	
while(result!=null && result.next())
{
	elementName = "activityName"+i++;
	OMElement activityResult = fac.createOMElement("activityResult",
ns);
				
	OMElement activityName = fac.createOMElement("activityName", ns);
	
activityName.addChild(fac.createOMText(result.getString("ACTIVITYNAME")));
	activityResult.addChild(activityName);
	activity.addChild(activityResult);

}

however, I got one question about this. I have attached the service in wsdl
format.
my question is, is that possible to create a client of this service in PHP
or maybe other programming language. I have try it out in php language, how
ever it doesnt return me any result.
but it returns error message. any idea of this?

Thank you

Regards,
Kencana


Hickman, Craig wrote:
> 
> 
> 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:bluesky_dyx@hotmail.com]
> Sent: Friday, May 04, 2007 4:20 AM
> To: axis-user@ws.apache.org
> 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: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 

--
View this message in context:
http://www.nabble.com/Returning-arrayList-tf3691291.html#a10351858
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Mime
View raw message