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

michi at wyona.com michi at wyona.com
Mon Dec 3 12:21:22 CET 2007


Author: michi
Date: 2007-12-03 12:21:22 +0100 (Mon, 03 Dec 2007)
New Revision: 29472

Added:
   public/yanel/contributions/resources/soap/src/java/ch/
   public/yanel/contributions/resources/soap/src/java/ch/naz/
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubricBean.java
   public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/ServiceInterceptor.java
Modified:
   public/yanel/contributions/resources/soap/src/build/dependencies.xml
   public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java
Log:
first method implemented

Modified: public/yanel/contributions/resources/soap/src/build/dependencies.xml
===================================================================
--- public/yanel/contributions/resources/soap/src/build/dependencies.xml	2007-12-03 10:49:45 UTC (rev 29471)
+++ public/yanel/contributions/resources/soap/src/build/dependencies.xml	2007-12-03 11:21:22 UTC (rev 29472)
@@ -7,8 +7,9 @@
 
     <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
       <remoteRepository refid="wyona.remote.repository"/>
-      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
-                  version="${yanel.source.version}"/>
+      <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"/>
     </artifact:dependencies>
 
     <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">

Added: public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/Constants.java	2007-12-03 11:21:22 UTC (rev 29472)
@@ -0,0 +1,24 @@
+package ch.naz.yanel;
+
+public class Constants {
+	public static final String SOAP_MIME_TYPE = "application/soap+xml";
+	
+	public static final String NS_URI = "http//www.naz.ch/eld/wyona/1.0";
+	
+	// Look into RoobricService.wsdl for details
+	public static final String TITLE_EN_TAG = "title_en";
+	public static final String TITLE_DE_TAG = "title_de";
+	public static final String TITLE_IT_TAG = "title_it";
+	public static final String TITLE_FR_TAG = "title_fr";
+	
+	public static final String NAME_TAG = "name";
+	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 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/CreateRubricBean.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubricBean.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/CreateRubricBean.java	2007-12-03 11:21:22 UTC (rev 29472)
@@ -0,0 +1,61 @@
+package ch.naz.yanel;
+
+public class CreateRubricBean {
+	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/RubricService.wsdl
===================================================================
--- public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/ch/naz/yanel/RubricService.wsdl	2007-12-03 11:21:22 UTC (rev 29472)
@@ -0,0 +1,119 @@
+<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>

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-03 10:49:45 UTC (rev 29471)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/SOAPResource.java	2007-12-03 11:21:22 UTC (rev 29472)
@@ -1,58 +1,102 @@
-/*
- * Copyright 2007 Wyona
- */
-
 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 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 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;
 
-public class SOAPResource extends Resource implements ViewableV2{
-	private static String ENVELOPE =
-		"<?xml version='1.0'?>"+
-		"<soap:Envelope xmlns:soap='http://www.w3.org/2001/12/soap-envelope' soap:encodingStyle='http://www.w3.org/2001/12/soap-encoding'>"+
-			"<soap:Body xmlns:o='http://www.optaros.com'>" +
-				"<o:exampleResponse>" +
-					" Hello World!" +
-				"</o:exampleResponse>" +
-			"</soap:Body>" +
-		"</soap:Envelope>";
+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();
+			}
+			
+		};
+	}
 	
-    public SOAPResource() {
-    }
-    
-    public boolean exists() throws Exception {
-    	return true;
-    }
-    
+	
+	private static final String SOAP_MIME_TYPE = "application/soap+xml";
+	
+	public boolean exists() throws Exception {
+		return true;
+	}
+	
+	public long getSize() throws Exception {
+		return -1;
+	}
+
     /**
      *
      */
-    private String getMimeType(String viewId) throws Exception {
-        if (getResourceConfigProperty("mime-type") != null) return getResourceConfigProperty("mime-type");
-    	return "application/soap+xml";
-    }
-    
-    public long getSize() throws Exception {
-    	return ENVELOPE.getBytes().length;
-    }
-    
     public View getView(String viewId) throws Exception {
-    	
-    	System.out.println(super.getConfiguration().getProperty("encoding"));
-    	
-    	View v = new View();
-    	v.setInputStream( new ByteArrayInputStream(ENVELOPE.getBytes()));
-    	// This is important!
-    	v.setMimeType(getMimeType(viewId));
-    	return v;
+        View v = new View();
+        v.setMimeType(SOAP_MIME_TYPE);
+		
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        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());
+        v.setInputStream(bais);
+		
+        return v;
     }
-    
+
+    /**
+     *
+     */
     public ViewDescriptor[] getViewDescriptors() {
-    	return null;
+        // TODO Auto-generated method stub
+        return null;
     }
 }

Added: public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/ServiceInterceptor.java
===================================================================
--- public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/ServiceInterceptor.java	                        (rev 0)
+++ public/yanel/contributions/resources/soap/src/java/org/wyona/yanel/impl/resources/soap/ServiceInterceptor.java	2007-12-03 11:21:22 UTC (rev 29472)
@@ -0,0 +1,113 @@
+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 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 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 ServiceInterceptor {
+	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 String handleRequest(Element payload) throws Exception{
+		CreateRubricBean rubric = new CreateRubricBean();
+		
+		XPath xpath = XPathFactory.newInstance().newXPath();
+		xpath.setNamespaceContext(NAMESPACE_CONTEXT);
+		
+		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)){
+				rubric.setTitleDe(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_EN_TAG)){
+				rubric.setTitleEn(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_IT_TAG)){
+				rubric.setTitleIt(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.TITLE_FR_TAG)){
+				rubric.setTitleFr(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.AXIS_TAG)){
+				rubric.setAxis(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.NAME_TAG)){
+				rubric.setName(e.getFirstChild().getNodeValue());
+			}else if(e.getLocalName().equals(Constants.PARENT_NODE_PATH_TAG)){
+				rubric.setParentNodePath(e.getFirstChild().getNodeValue());
+			}
+		}
+		
+		// Create rubric
+		String rubricPath = "/rubric-"+rubric.getName()+".txt";
+		PrintWriter fw = new PrintWriter(new FileWriter(rubricPath));
+		fw.println(rubricPath.toString());
+		fw.flush();
+		
+		// TODO: when creation is not successful a message with a fault must be returned
+		
+		
+		String response = 
+			"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" + "\n"+
+			"\t"+"<soapenv:Header/>"+
+			"\t"+"<soapenv:Body>" +"\n"+
+				"\t\t"+"<naz:CreateRubricResponse xmlns:naz='"+NAMESPACE_CONTEXT.getNamespaceURI("naz")+"'>" +"\n"+
+				"\t\t\t"+"<naz:"+Constants.NODE_PATH_TAG+">"+
+							rubricPath+
+						"</naz:"+Constants.NODE_PATH_TAG+">"+"\n"+
+				"\t\t"+"</naz:CreateRubricResponse>" +"\n"+
+			"\t"+"</soapenv:Body>" +"\n"+
+			"</soapenv:Envelope>";
+		
+		return response;
+	}
+}



More information about the Yanel-commits mailing list