You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by jcamus <jc...@parkeon.com> on 2008/08/07 10:27:53 UTC

Hard coded XML tags into a java component...

I have a HTTPSOAP-SU and after XSLT transform and routing I arrive in a java
class to treat the SOAP demand (and to return a formatted response for the
client).

My question is : currently my java class is completely hard coded (with all
XML tags), is there a way do it more properly and easier into the ESB ? For
now, I must use the dom4j.jar and jaxen.jar to extract XML tags (and have it
into the SU.zip file).

Here is the java code :

public class LoginComponent extends TransformComponentSupport {
	 	
		private static final Log log = LogFactory.getLog("org.apache.servicemix");
		
		public LoginComponent() {
		
log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
			log.debug("$$$$$$$$$$$$$$$$$$$$$ LoginComponent created
$$$$$$$$$$$$$$$$$$$$$$$$$");
		
log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
		}		
	   
	    public boolean transform(MessageExchange exchange, NormalizedMessage
in, NormalizedMessage out) throws MessagingException {
	        
	    	log.debug("LoginComponent transform....");
	    	
	        try {
	            SourceTransformer sourceTransformer = new SourceTransformer();
	            String fluxXMLInput = sourceTransformer.contentToString(in); 
	            	            
	            Document doc = DocumentHelper.parseText(fluxXMLInput);
	            String deviceId = Utils.getXPathField(doc, "deviceId");
	            String groupId = Utils.getXPathField(doc, "groupId");
	            
	            log.debug("LoginComponent deviceId = " + deviceId);
	            log.debug("LoginComponent groupId = " + groupId);
	            
	            Source outMsg = null;
	            String result = null;	            
	            result =
"<SOAP><RESULT>"+deviceId+"/"+groupId+"</RESULT></SOAP>";
	            outMsg = new StringSource(result);
	            
	            if (outMsg != null) {
	                // There is a valid response
	                log.debug("Response: " +
sourceTransformer.toString(outMsg));
	                out.setContent(outMsg);
	                return true;
	            } else {
	                log.debug("Response: No Response");
	                return false;
	            }
	        
	        } catch (Exception e) {
	        	log.error("LoginComponent Exception: ", e);
	            throw new MessagingException(e);
	        } finally {
	        }	    
	    }
}
-- 
View this message in context: http://www.nabble.com/Hard-coded-XML-tags-into-a-java-component...-tp18866116p18866116.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Hard coded XML tags into a java component...

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

I think you can use servicemix-cxf-bc(for mesasge transform) and 
servicemix-cxf-se (for pojo host) to do soap demand issue, such things 
like marshall/unmarshall is done for you in an automatic way so that you 
needn't handle the xml tags yourself.

You may take a look at the cxf-wsdl-first  example in the kit.
Regards
Freeman

jcamus wrote:
> I have a HTTPSOAP-SU and after XSLT transform and routing I arrive in a java
> class to treat the SOAP demand (and to return a formatted response for the
> client).
>
> My question is : currently my java class is completely hard coded (with all
> XML tags), is there a way do it more properly and easier into the ESB ? For
> now, I must use the dom4j.jar and jaxen.jar to extract XML tags (and have it
> into the SU.zip file).
>
> Here is the java code :
>
> public class LoginComponent extends TransformComponentSupport {
> 	 	
> 		private static final Log log = LogFactory.getLog("org.apache.servicemix");
> 		
> 		public LoginComponent() {
> 		
> log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
> 			log.debug("$$$$$$$$$$$$$$$$$$$$$ LoginComponent created
> $$$$$$$$$$$$$$$$$$$$$$$$$");
> 		
> log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
> 		}		
> 	   
> 	    public boolean transform(MessageExchange exchange, NormalizedMessage
> in, NormalizedMessage out) throws MessagingException {
> 	        
> 	    	log.debug("LoginComponent transform....");
> 	    	
> 	        try {
> 	            SourceTransformer sourceTransformer = new SourceTransformer();
> 	            String fluxXMLInput = sourceTransformer.contentToString(in); 
> 	            	            
> 	            Document doc = DocumentHelper.parseText(fluxXMLInput);
> 	            String deviceId = Utils.getXPathField(doc, "deviceId");
> 	            String groupId = Utils.getXPathField(doc, "groupId");
> 	            
> 	            log.debug("LoginComponent deviceId = " + deviceId);
> 	            log.debug("LoginComponent groupId = " + groupId);
> 	            
> 	            Source outMsg = null;
> 	            String result = null;	            
> 	            result =
> "<SOAP><RESULT>"+deviceId+"/"+groupId+"</RESULT></SOAP>";
> 	            outMsg = new StringSource(result);
> 	            
> 	            if (outMsg != null) {
> 	                // There is a valid response
> 	                log.debug("Response: " +
> sourceTransformer.toString(outMsg));
> 	                out.setContent(outMsg);
> 	                return true;
> 	            } else {
> 	                log.debug("Response: No Response");
> 	                return false;
> 	            }
> 	        
> 	        } catch (Exception e) {
> 	        	log.error("LoginComponent Exception: ", e);
> 	            throw new MessagingException(e);
> 	        } finally {
> 	        }	    
> 	    }
> }
>