[Yanel-commits] rev 29511 - in public/yanel/contributions/resources/soap: . src/build src/java/ch/naz/yanel src/java/org/wyona/yanel/impl/resources/soap

michi at wyona.com michi at wyona.com
Tue Dec 4 08:51:52 CET 2007


Author: michi
Date: 2007-12-04 08:51:51 +0100 (Tue, 04 Dec 2007)
New Revision: 29511

Added:
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubrikBean.java
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/NAZRubrikService.java
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubrikService.wsdl
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/AbstractWebService.java
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/IWebService.java
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/MessageContext.java
Removed:
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl
Modified:
   public/yanel/contributions/resources/soap/resource.xml
   public/yanel/contributions/resources/soap/src/build/dependencies.xml
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java
Log:
service refactored

Modified: public/yanel/contributions/resources/soap/resource.xml
===================================================================
--- public/yanel/contributions/resources/soap/resource.xml	2007-12-04 07:51:18 UTC (rev 29510)
+++ public/yanel/contributions/resources/soap/resource.xml	2007-12-04 07:51:51 UTC (rev 29511)
@@ -9,12 +9,7 @@
 </description>
 
 <rtd>
-  <!-- Communication via SOAP -->
-  <property name="mime-type" default-value="application/soap+xml"/>
-  <!-- Is this actually being used? -->
-  <property name="encoding" default-value="UTF-8"/>
-
-  <!-- Allows to specify a custom adapter, e.g. org.wyona.neutron.SOAP -->
-  <property name="interceptor-class"/>
+  <!-- Allows to specify a Web service implementation -->
+  <property name="ws-impl"/>
 </rtd>
 </resource>

Modified: public/yanel/contributions/resources/soap/src/build/dependencies.xml
===================================================================
--- public/yanel/contributions/resources/soap/src/build/dependencies.xml	2007-12-04 07:51:18 UTC (rev 29510)
+++ public/yanel/contributions/resources/soap/src/build/dependencies.xml	2007-12-04 07:51:51 UTC (rev 29511)
@@ -10,6 +10,7 @@
       <dependency groupId="wyona-org-yanel" artifactId="yanel-core" version="${yanel.source.version}"/>
       <dependency groupId="xml-apis" artifactId="xml-apis" version="1.3.02"/>
       <dependency groupId="javax.servlet" artifactId="servlet-api" version="2.3" scope="provided"/>
+      <dependency groupId="naz-eld" artifactId="yanel-resource-naz-shared" version="0.0.1-dev-rXXX"/>
     </artifact:dependencies>
 
     <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">

Modified: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java	2007-12-04 07:51:18 UTC (rev 29510)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -15,8 +15,9 @@
 	public static final String PARENT_NODE_PATH_TAG = "parent-node-path";
 	public static final String AXIS_TAG = "axis";
 	
-	public static final String CREATE_RUBRIC_RESPONSE_TAG = "CreateRubricResponse";
-	public static final String CREATE_RUBRIC_TAG = "CreateRubric";
+	public static final String CREATE_RUBRIC_RESPONSE_TAG = "CreateRubrikResponse";
+	public static final String CREATE_RUBRIC_TAG = "CreateRubrik";
+	public static final String RUBRIC_FAULT_TAG = "RubrikFault";
 	
 	public static final String EXCEPTION_MESSAGE_TAG = "exception-message";
 	public static final String NODE_PATH_TAG = "node-path";

Added: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubrikBean.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubrikBean.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubrikBean.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,61 @@
+package ch.naz.yanel;
+
+public class CreateRubrikBean {
+	private String titleEn = "Unknown";
+	private String titleDe = "Unknown";
+	private String titleIt = "Unknown";
+	private String titleFr = "Unknown";
+	private String name = "NONAME";
+	private String parentNodePath = null;
+	private String axis = "child";
+	
+	
+	public String getTitleEn() {
+		return titleEn;
+	}
+	public void setTitleEn(String titleEn) {
+		this.titleEn = titleEn;
+	}
+	public String getTitleDe() {
+		return titleDe;
+	}
+	public void setTitleDe(String titleDe) {
+		this.titleDe = titleDe;
+	}
+	public String getTitleIt() {
+		return titleIt;
+	}
+	public void setTitleIt(String titleIt) {
+		this.titleIt = titleIt;
+	}
+	public String getTitleFr() {
+		return titleFr;
+	}
+	public void setTitleFr(String titleFr) {
+		this.titleFr = titleFr;
+	}
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getParentNodePath() {
+		return parentNodePath;
+	}
+	public void setParentNodePath(String parentNodePath) {
+		this.parentNodePath = parentNodePath;
+	}
+	public String getAxis() {
+		return axis;
+	}
+	public void setAxis(String axis) {
+		if("sibling".equals(axis) || "child".equals(axis) ){
+			this.axis = axis;
+		}
+	}
+	
+	public String toString() {
+		return "rubric name: "+getName();
+	}
+}

Added: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/NAZRubrikService.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/NAZRubrikService.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/NAZRubrikService.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,211 @@
+package ch.naz.yanel;
+
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.ResourceConfiguration;
+import org.wyona.yanel.core.util.PathUtil;
+import org.wyona.yanel.core.util.YarepUtil;
+import org.wyona.yanel.impl.resources.soap.AbstractWebService;
+import org.wyona.yanel.impl.resources.soap.MessageContext;
+import org.wyona.yarep.core.Node;
+import org.wyona.yarep.core.NodeType;
+import org.wyona.yarep.core.Repository;
+import org.xml.sax.InputSource;
+
+import ch.naz.eld.yanel.content.I18nString;
+import ch.naz.eld.yanel.content.NAZContentManager;
+import ch.naz.eld.yanel.content.impl.NAZContentManagerImpl;
+import ch.naz.eld.yanel.sitetree.SiteTree;
+import ch.naz.eld.yanel.sitetree.SiteTreeNode;
+import ch.naz.eld.yanel.sitetree.yarep.YarepSiteTreeFactory;
+
+public class NAZRubrikService extends AbstractWebService{
+    private static Logger log = Logger.getLogger(NAZRubrikService.class);
+    
+    private static final String NAZ_PREFIX = "naz";
+    private MessageContext recentMessageContext = null;
+    private static final String RESOURCE_EXTENSION = "";
+    
+    public NAZRubrikService() {
+        NAMESPACE_CONTEXT.registerNamespace(NAZ_PREFIX, Constants.NS_URI);
+    }
+    
+    public Element handle(MessageContext ctx){
+        recentMessageContext = ctx;
+        
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        
+        Element response = null;
+        try {
+            // TODO: Apply security constraints
+            String s = handleRequest(extractPayload(ctx.getSoapMessage()));
+            response = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(s))).getDocumentElement();
+        } catch (Exception e) {
+            recentMessageContext = null;
+            String s = createFault(e);
+            try {
+                response = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(s))).getDocumentElement();
+            } catch (Exception e1) {
+                throw new IllegalStateException("Cannot perform the requested action: "+e1.getMessage());
+            }
+        }
+       
+        return response;
+    }
+    
+    private String createFault(Throwable e){
+        String response = 
+            "<soapenv:Envelope " +
+                " xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " +
+                " xmlns:naz='"+NAMESPACE_CONTEXT.getNamespaceURI(NAZ_PREFIX)+"'>" + 
+                "<soapenv:Header/>"+
+                "<soapenv:Body>" +"\n"+
+                    "<naz:"+Constants.RUBRIC_FAULT_TAG+">" +
+                        "<naz:"+Constants.EXCEPTION_MESSAGE_TAG+">"+
+                            e.getMessage().replaceAll("<", "&lt;")+
+                        "</naz:"+Constants.EXCEPTION_MESSAGE_TAG+">"+
+                    "</naz:"+Constants.RUBRIC_FAULT_TAG+">" +
+                "</soapenv:Body>" +
+            "</soapenv:Envelope>";
+        System.out.println(response);
+        return response;
+    }
+    
+    
+	private String handleRequest(Element payload) throws Exception{
+		CreateRubrikBean rubrik = new CreateRubrikBean();
+		
+		XPath xpath = XPathFactory.newInstance().newXPath();
+		
+		NodeList nl = (NodeList)xpath.evaluate("*", payload, XPathConstants.NODESET);
+		
+		for (int i = 0; i < nl.getLength(); i++) {
+			Element e = (Element)nl.item(i);
+			if(e.getLocalName().equals(Constants.TITLE_DE_TAG)){
+				rubrik.setTitleDe(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_EN_TAG)){
+				rubrik.setTitleEn(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_IT_TAG)){
+				rubrik.setTitleIt(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_FR_TAG)){
+				rubrik.setTitleFr(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.AXIS_TAG)){
+				rubrik.setAxis(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.NAME_TAG)){
+				rubrik.setName(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.PARENT_NODE_PATH_TAG)){
+				rubrik.setParentNodePath(e.getFirstChild().getNodeValue());
+			}
+		}
+		
+		String response = null;
+		
+		// Create rubrik
+		if(isValid(rubrik)){
+		    Resource resource = recentMessageContext.getResource();
+		    
+		    String siteTreePath = null;
+            if ("child".equals(rubrik.getAxis())) {
+                siteTreePath = rubrik.getParentNodePath() + rubrik.getName();
+            } else {
+                siteTreePath = PathUtil.getParent(rubrik.getParentNodePath()) + rubrik.getName();
+            }
+            
+		    String newResourceRealmPath = siteTreePath + RESOURCE_EXTENSION;
+		    
+		    //TODO: remove hardcode
+		    ResourceConfiguration rc = new ResourceConfiguration("rubrik", "http://naz.ch/yanel/resource/1.0", null);
+		    Resource newResource = resource.getYanel().getResourceManager().getResource(resource.getEnvironment(), resource.getRealm(), "/de" + newResourceRealmPath, rc);
+		    
+		    createYanelRCFile(newResource, "de");
+		    createYanelRCFile(newResource, "en");
+		    createYanelRCFile(newResource, "fr");
+		    createYanelRCFile(newResource, "it");
+		    
+		    I18nString title = new I18nString();
+            title.setValue("de", rubrik.getTitleDe());
+            title.setValue("en", rubrik.getTitleEn());
+            title.setValue("fr", rubrik.getTitleFr());
+            title.setValue("it", rubrik.getTitleIt());
+		    
+		    
+            SiteTree siteTree = getSiteTree();
+            SiteTreeNode originNode = siteTree.getNode(rubrik.getParentNodePath());
+            int pos = 0;
+            if (originNode != null) {
+                pos = originNode.getParentNode().indexOf(originNode) + 1;
+            }
+            NAZContentManager manager = NAZContentManagerImpl.getInstance(resource.getRealm().getRepository(), siteTree);
+            manager.createRubric(newResourceRealmPath, title, pos);
+            
+		    response = 
+	            "<soapenv:Envelope " +
+	                " xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " +
+	                " xmlns:naz='"+NAMESPACE_CONTEXT.getNamespaceURI(NAZ_PREFIX)+"'>" +
+	                "<soapenv:Header/>"+
+	                "<soapenv:Body>" +"\n"+
+	                    "<naz:"+Constants.CREATE_RUBRIC_RESPONSE_TAG+">" +
+	                    "<naz:"+Constants.NODE_PATH_TAG+">"+
+	                            siteTreePath+
+	                        "</naz:"+Constants.NODE_PATH_TAG+">"+
+	                    "</naz:"+Constants.CREATE_RUBRIC_RESPONSE_TAG+">" +
+	                "</soapenv:Body>" +
+	            "</soapenv:Envelope>";
+		}else{
+		    response = createFault(new Exception("The parameters are invalid"));
+		}
+		
+		return response;
+	}
+	
+	private boolean isValid(CreateRubrikBean rubrik){
+	    boolean valid = true;
+	    
+	    //TODO[et] it actually should be validated according to the schema in the WSDL
+        
+        // TODO: check if id exists already
+        // TODO: check if parent is valid
+
+        return valid;
+	}
+	
+    private void createYanelRCFile(Resource resource, String language) throws Exception {
+        StringBuffer rcContent = new StringBuffer("<?xml version=\"1.0\"?>\n\n");
+        rcContent.append("<yanel:resource-config xmlns:yanel=\"http://www.wyona.org/yanel/rti/1.0\">\n");
+        rcContent.append("<yanel:rti name=\"" + resource.getRTD().getResourceTypeLocalName() + "\" namespace=\"" + resource.getRTD().getResourceTypeNamespace() + "\"/>\n\n");
+        rcContent.append("<yanel:property name=\"xslt\" value=\"/xslt/rubrik-body.xsl\"/>\n");
+        rcContent.append("<yanel:property name=\"xslt\" value=\"/xslt/global.xsl\"/>\n");
+        rcContent.append("<yanel:property name=\"mime-type\" value=\"text/html\"/>\n");
+        rcContent.append("</yanel:resource-config>");
+        
+        Repository rcRepo = resource.getRealm().getRTIRepository();
+        String newRCPath = PathUtil.getRCPath("/" + language + resource.getPath().substring("/de".length()));
+        if (log.isDebugEnabled()) 
+            log.debug(newRCPath);
+        YarepUtil.addNodes(rcRepo, newRCPath, NodeType.RESOURCE);
+
+        java.io.Writer writer = new OutputStreamWriter(rcRepo.getNode(newRCPath).getOutputStream());
+        writer.write(rcContent.toString());
+        writer.close();
+    }
+    
+    private SiteTree getSiteTree() throws Exception {
+        Node siteTreeNode = recentMessageContext.getResource().getRealm().getRepository().getNode("/sitetree.xml");
+        return YarepSiteTreeFactory.getSiteTree(siteTreeNode);
+    }
+
+}

Deleted: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl	2007-12-04 07:51:18 UTC (rev 29510)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl	2007-12-04 07:51:51 UTC (rev 29511)
@@ -1,119 +0,0 @@
-<wsdl:definitions
-	targetNamespace="http//www.naz.ch/eld/wyona/1.0"
-	xmlns:tns="http//www.naz.ch/eld/wyona/1.0"
-	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
-	xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
-	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
-	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
-
-	<wsdl:types>
-			<xsd:schema 
-			attributeFormDefault="unqualified"
-			elementFormDefault="qualified"
-			targetNamespace="http//www.naz.ch/eld/wyona/1.0">
-			
-			<xsd:element name="CreateRubric">
-				<xsd:complexType>
-					<xsd:sequence>
-						<xsd:element name="title_de" type="xsd:string"/>
-						<xsd:element name="title_fr" type="xsd:string"/>
-						<xsd:element name="title_it" type="xsd:string"/>
-						<xsd:element name="title_en" type="xsd:string"/>
-						<xsd:element name="name" type="xsd:string"/>
-						<xsd:element name="parent-node-path" type="xsd:anyURI"/>
-						<xsd:element name="axis" default="child">
-							<xsd:simpleType>
-								<xsd:restriction base="xsd:string">
-									<xsd:enumeration value="child"/>
-									<xsd:enumeration value="sibling"/>
-								</xsd:restriction>
-							</xsd:simpleType>
-						</xsd:element>
-					</xsd:sequence>
-				</xsd:complexType>
-			</xsd:element>
-			
-			<xsd:element name="CreateRubricResponse">
-				<xsd:complexType>
-					<xsd:sequence>
-						<xsd:element name="node-path" type="xsd:anyURI"/>
-					</xsd:sequence>
-				</xsd:complexType>
-			</xsd:element>
-			
-			<xsd:element name="ListAllRubrics">
-			<!-- TODO -->
-			</xsd:element>
-			<xsd:element name="ListAllRubricsResponse">
-			<!-- TODO -->
-			</xsd:element>
-			
-			<xsd:element name="RubricFault">
-				<xsd:complexType>
-					<xsd:sequence>
-						<xsd:element name="exception-message" type="xsd:string"/>
-					</xsd:sequence>
-				</xsd:complexType>
-			</xsd:element>	
-		</xsd:schema>
-	</wsdl:types>
-	
-	<wsdl:message name="CreateRubricMessage">
-		<wsdl:part name="part1" element="tns:CreateRubric"/>
-	</wsdl:message>
-	<wsdl:message name="CreateRubricResponseMessage">
-		<wsdl:part name="part1" element="tns:CreateRubricResponse" />
-	</wsdl:message>
-	
-	<wsdl:message name="ListAllRubricsMessage">
-		<wsdl:part name="part1" element="tns:ListAllRubrics"/>
-	</wsdl:message>
-	<wsdl:message name="ListAllRubricsResponseMessage">
-		<wsdl:part name="part1" element="tns:ListAllRubricsResponse" />
-	</wsdl:message>
-	
-	<wsdl:message name="RubricFaultMessage">
-		<wsdl:part name="part1" element="tns:RubricFault" />
-	</wsdl:message>
-	
-	<wsdl:portType name="RubricServicePortType">
-		<wsdl:operation name="createRubric">
-			<wsdl:input message="tns:CreateRubricMessage" />
-			<wsdl:output message="tns:CreateRubricResponseMessage" />
-			<wsdl:fault message="tns:RubricFaultMessage"
-				name="createFault" />
-		</wsdl:operation>
-		<wsdl:operation name="listAllRubrics">
-			<wsdl:input message="tns:ListAllRubricsMessage" />
-			<wsdl:output message="tns:ListAllRubricsResponseMessage" />
-			<wsdl:fault message="tns:RubricFaultMessage" name="listFault" />
-		</wsdl:operation>
-	</wsdl:portType>
-	
-	<wsdl:binding name="RubricServiceSOAPBinding"
-		type="tns:RubricServicePortType">
-		<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
-		<wsdl:operation name="createRubric">
-			<soap:operation soapAction="" style="document" />
-			<wsdl:input>
-				<soap:body use="literal" />
-			</wsdl:input>
-			
-			<wsdl:output>
-				<soap:body use="literal" />
-			</wsdl:output>
-			<wsdl:fault name="createFault">
-				<soap:fault use="literal" name="createFault" />
-			</wsdl:fault>
-		</wsdl:operation>		
-	</wsdl:binding>
-
-	<wsdl:service name="RubricService">
-		<wsdl:port name="RubricServiceSOAPport_http"
-			binding="tns:RubricServiceSOAPBinding">
-			<soap:address location="http://replace/on/initialization"/>
-		</wsdl:port>
-	</wsdl:service>
-	
-</wsdl:definitions>

Added: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubrikService.wsdl
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubrikService.wsdl	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubrikService.wsdl	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,125 @@
+<wsdl:definitions
+	targetNamespace="http//www.naz.ch/eld/wyona/1.0"
+	xmlns:tns="http//www.naz.ch/eld/wyona/1.0"
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+	xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
+	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
+
+	<wsdl:types>
+			<xsd:schema 
+			attributeFormDefault="unqualified"
+			elementFormDefault="qualified"
+			targetNamespace="http//www.naz.ch/eld/wyona/1.0">
+			
+			<xsd:element name="CreateRubrik">
+				<xsd:complexType>
+					<xsd:sequence>
+						<xsd:element name="title_de" type="xsd:string"/>
+						<xsd:element name="title_fr" type="xsd:string"/>
+						<xsd:element name="title_it" type="xsd:string"/>
+						<xsd:element name="title_en" type="xsd:string"/>
+						<xsd:element name="name">
+							<xsd:simpleType>
+								<xsd:restriction base="xsd:string">
+									<xsd:pattern value="[a-zA-Z_0-9]+"></xsd:pattern>
+								</xsd:restriction>
+							</xsd:simpleType>
+						</xsd:element>
+						<xsd:element name="parent-node-path" type="xsd:anyURI"/>
+						<xsd:element name="axis" default="child">
+							<xsd:simpleType>
+								<xsd:restriction base="xsd:string">
+									<xsd:enumeration value="child"/>
+									<xsd:enumeration value="sibling"/>
+								</xsd:restriction>
+							</xsd:simpleType>
+						</xsd:element>
+					</xsd:sequence>
+				</xsd:complexType>
+			</xsd:element>
+			
+			<xsd:element name="CreateRubrikResponse">
+				<xsd:complexType>
+					<xsd:sequence>
+						<xsd:element name="node-path" type="xsd:anyURI"/>
+					</xsd:sequence>
+				</xsd:complexType>
+			</xsd:element>
+			
+			<xsd:element name="ListAllRubriks">
+			<!-- TODO -->
+			</xsd:element>
+			<xsd:element name="ListAllRubriksResponse">
+			<!-- TODO -->
+			</xsd:element>
+			
+			<xsd:element name="RubrikFault">
+				<xsd:complexType>
+					<xsd:sequence>
+						<xsd:element name="exception-message" type="xsd:string"/>
+					</xsd:sequence>
+				</xsd:complexType>
+			</xsd:element>	
+		</xsd:schema>
+	</wsdl:types>
+	
+	<wsdl:message name="CreateRubrikMessage">
+		<wsdl:part name="part1" element="tns:CreateRubrik"/>
+	</wsdl:message>
+	<wsdl:message name="CreateRubrikResponseMessage">
+		<wsdl:part name="part1" element="tns:CreateRubrikResponse" />
+	</wsdl:message>
+	
+	<wsdl:message name="ListAllRubriksMessage">
+		<wsdl:part name="part1" element="tns:ListAllRubriks"/>
+	</wsdl:message>
+	<wsdl:message name="ListAllRubriksResponseMessage">
+		<wsdl:part name="part1" element="tns:ListAllRubriksResponse" />
+	</wsdl:message>
+	
+	<wsdl:message name="RubrikFaultMessage">
+		<wsdl:part name="part1" element="tns:RubrikFault" />
+	</wsdl:message>
+	
+	<wsdl:portType name="RubrikServicePortType">
+		<wsdl:operation name="createRubrik">
+			<wsdl:input message="tns:CreateRubrikMessage" />
+			<wsdl:output message="tns:CreateRubrikResponseMessage" />
+			<wsdl:fault message="tns:RubrikFaultMessage"
+				name="createFault" />
+		</wsdl:operation>
+		<wsdl:operation name="listAllRubriks">
+			<wsdl:input message="tns:ListAllRubriksMessage" />
+			<wsdl:output message="tns:ListAllRubriksResponseMessage" />
+			<wsdl:fault message="tns:RubrikFaultMessage" name="listFault" />
+		</wsdl:operation>
+	</wsdl:portType>
+	
+	<wsdl:binding name="RubrikServiceSOAPBinding"
+		type="tns:RubrikServicePortType">
+		<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+		<wsdl:operation name="createRubrik">
+			<soap:operation soapAction="" style="document" />
+			<wsdl:input>
+				<soap:body use="literal" />
+			</wsdl:input>
+			
+			<wsdl:output>
+				<soap:body use="literal" />
+			</wsdl:output>
+			<wsdl:fault name="createFault">
+				<soap:fault use="literal" name="createFault" />
+			</wsdl:fault>
+		</wsdl:operation>		
+	</wsdl:binding>
+
+	<wsdl:service name="RubrikService">
+		<wsdl:port name="RubrikServiceSOAPport_http"
+			binding="tns:RubrikServiceSOAPBinding">
+			<soap:address location="http://replace/with/real/endpoint"/>
+		</wsdl:port>
+	</wsdl:service>
+	
+</wsdl:definitions>

Added: public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/AbstractWebService.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/AbstractWebService.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/AbstractWebService.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,62 @@
+package org.wyona.yanel.impl.resources.soap;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Element;
+
+public abstract class AbstractWebService implements IWebService{
+    protected final class NamespaceContextSupport implements NamespaceContext{
+        public static final String SOAP_ENV_PREFIX = "soapenv";
+        
+        private final Map namespaces = new HashMap();
+
+        public NamespaceContextSupport() {
+            namespaces.put(SOAP_ENV_PREFIX, "http://schemas.xmlsoap.org/soap/envelope/");
+        }
+        
+        public String getPrefix(String namespaceURI) {
+            Set s = namespaces.entrySet();
+            for (Iterator i = s.iterator(); i.hasNext();) {
+                Map.Entry e = (Map.Entry)i.next();
+                if(namespaceURI.equals(e.getValue())){
+                    return (String)e.getKey();
+                }
+            }
+            return null;
+        }
+        
+        public Iterator getPrefixes(String namespaceURI) {
+            return new HashSet(namespaces.keySet()).iterator();
+        }
+        
+        public String getNamespaceURI(String prefix) {
+            return (String)namespaces.get(prefix);
+        }
+        
+        public void registerNamespace(String prefix, String nsURI){
+            namespaces.put(prefix, nsURI);
+        }
+    }
+    
+	protected final NamespaceContextSupport NAMESPACE_CONTEXT = new NamespaceContextSupport();
+	
+	protected final Element extractPayload(Element soapEnvelope) throws Exception{
+	    
+	    XPath xpath = XPathFactory.newInstance().newXPath();
+        xpath.setNamespaceContext(NAMESPACE_CONTEXT);
+        Element payload = (Element)xpath.evaluate(
+                        "/"+NamespaceContextSupport.SOAP_ENV_PREFIX+":Envelope/"+
+                          NamespaceContextSupport.SOAP_ENV_PREFIX+":Body/*", soapEnvelope, XPathConstants.NODE);
+        
+        return payload;
+	}
+}

Added: public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/IWebService.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/IWebService.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/IWebService.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,11 @@
+package org.wyona.yanel.impl.resources.soap;
+
+import org.w3c.dom.Element;
+
+public interface IWebService {
+    /**
+     * Handles an incoming call to a Web service, i.e. parses the message
+     * @return a response of the service call. On some exceptions should return message with a fault
+     * */    
+    public Element handle(MessageContext ctx);
+}

Added: public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/MessageContext.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/MessageContext.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/MessageContext.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -0,0 +1,24 @@
+package org.wyona.yanel.impl.resources.soap;
+
+import org.w3c.dom.Element;
+import org.wyona.yanel.core.Resource;
+
+public class MessageContext {
+    private Element soapMessage = null;
+    private Resource resource = null;
+    
+    public Element getSoapMessage() {
+        return soapMessage;
+    }
+    public void setSoapMessage(Element soapMessage) {
+        this.soapMessage = soapMessage;
+    }
+    public Resource getResource() {
+        return resource;
+    }
+    public void setResource(Resource resource) {
+        this.resource = resource;
+    }
+    
+    
+}

Modified: public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java	2007-12-04 07:51:18 UTC (rev 29510)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java	2007-12-04 07:51:51 UTC (rev 29511)
@@ -1,66 +1,22 @@
 package org.wyona.yanel.impl.resources.soap;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.io.StringWriter;
 
-import javax.xml.namespace.NamespaceContext;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 import org.wyona.yanel.core.Resource;
 import org.wyona.yanel.core.api.attributes.ViewableV2;
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 
-import ch.naz.yanel.Constants;
-import ch.naz.yanel.CreateRubricBean;
-
-/**
- *
- */
 public class SOAPResource extends Resource implements ViewableV2 {
-	private static final NamespaceContext NAMESPACE_CONTEXT;
-	static{
-		final Map namespaces = new HashMap();
-		namespaces.put("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
-		namespaces.put("naz", "http//www.naz.ch/eld/wyona/1.0");
-		
-		NAMESPACE_CONTEXT = new NamespaceContext(){
-			public String getNamespaceURI(String prefix) {
-				return (String)namespaces.get(prefix);
-			}
-			
-			public String getPrefix(String namespaceURI) {
-				Set s = namespaces.entrySet();
-				for (Iterator i = s.iterator(); i.hasNext();) {
-					Map.Entry e = (Map.Entry)i.next();
-					if(namespaceURI.equals(e.getValue())){
-						return (String)e.getKey();
-					}
-				}
-				return null;
-			}
-			
-			public Iterator getPrefixes(String namespaceURI) {
-				return new HashSet(namespaces.keySet()).iterator();
-			}
-			
-		};
-	}
-	
-	
 	private static final String SOAP_MIME_TYPE = "application/soap+xml";
 	
 	public boolean exists() throws Exception {
@@ -82,12 +38,18 @@
         dbf.setNamespaceAware(true);
         Document soapMessage = dbf.newDocumentBuilder().parse(getEnvironment().getRequest().getInputStream());
 		
-        XPath xpath = XPathFactory.newInstance().newXPath();
-        xpath.setNamespaceContext(NAMESPACE_CONTEXT);
-        Element payload = (Element)xpath.evaluate("/soapenv:Envelope/soapenv:Body/*", soapMessage, XPathConstants.NODE);
-		
-        ByteArrayInputStream bais = new ByteArrayInputStream(new ServiceInterceptor().handleRequest(payload).getBytes());
-        //ByteArrayInputStream bais = new ByteArrayInputStream(new classForName.getResourceConfigProerty("interceptor-class").handleRequest(payload).getBytes());
+        MessageContext ctx = new MessageContext();
+        ctx.setSoapMessage(soapMessage.getDocumentElement());
+        ctx.setResource(this);
+        
+        Element response = ((IWebService)Class.forName(getResourceConfigProperty("ws-impl")).newInstance()).handle(ctx);
+        
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer();
+        StringWriter sw = new StringWriter();
+        t.transform(new DOMSource(response), new StreamResult(sw));
+        
+        ByteArrayInputStream bais = new ByteArrayInputStream(sw.toString().getBytes());
         v.setInputStream(bais);
 		
         return v;



More information about the Yanel-commits mailing list