You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by oz...@apache.org on 2004/07/12 17:48:45 UTC
cvs commit: jakarta-slide/webdavclient/connector/example/src/java/connector TestServlet.java
ozeigermann 2004/07/12 08:48:45
Added: webdavclient/connector/example/src/conf web.xml
jboss-web.xml
webdavclient/connector/example/src/java/connector
TestServlet.java
Log:
Initial *untested* example of JCA connector implementation
bluntly stolen from commons transactrions
*** WORK IN PROGRESS ***
Revision Changes Path
1.1 jakarta-slide/webdavclient/connector/example/src/conf/web.xml
Index: web.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app id="WebApp">
<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<servlet-class>connector.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<resource-ref >
<res-ref-name>Map</res-ref-name>
<res-type>org.apache.commons.transaction.memory.jca.MapManagedConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
1.1 jakarta-slide/webdavclient/connector/example/src/conf/jboss-web.xml
Index: jboss-web.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web.dtd">
<jboss-web>
<!-- Resource references -->
<resource-ref>
<res-ref-name>Map</res-ref-name>
<jndi-name>java:Map</jndi-name>
</resource-ref>
</jboss-web>
1.1 jakarta-slide/webdavclient/connector/example/src/java/connector/TestServlet.java
Index: TestServlet.java
===================================================================
package connector;
import java.io.*;
import org.apache.webdav.connector.*;
import org.apache.webdav.lib.WebdavResource;
import javax.resource.ResourceException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
import javax.naming.InitialContext;
import javax.naming.Context;
/**
* Implementation of the test servlet.
*/
public class TestServlet extends HttpServlet {
static String HOST = "http://localhost:8888/slide";
static String USER = "root";
static String PASSWORD = "password";
static int TIMEOUT = 10;
// Reference to the factory
private WebDAVConnectionFactory _factory;
/**
* <code>init()</code> stores the factory for efficiency since JNDI
* is relatively slow.
*/
public void init() throws ServletException {
try {
Context ic = new InitialContext();
_factory = (WebDAVConnectionFactory) ic.lookup("java:comp/env/WebDAV-Connector");
} catch (Exception e) {
throw new ServletException(e);
}
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
WebDAVConnection conn1 = null;
WebDAVConnection conn2 = null;
UserTransaction tx = null;
try {
Context ic = new InitialContext();
tx = (UserTransaction) ic.lookup("java:comp/UserTransaction");
tx.begin();
System.out.println("Tx: " + tx);
out.println("Tx: " + tx + "<br>");
System.out.println("Factory: " + _factory);
out.println("Factory: " + _factory + "<br>");
WebDAVConnectionSpec spec = new WebDAVConnectionSpec(HOST, USER, PASSWORD, TIMEOUT);
conn1 = (WebDAVConnection) _factory.getConnection(spec);
conn2 = (WebDAVConnection) _factory.getConnection(spec);
out.println("Connection1: " + conn1 + "<br>");
System.out.println("Connection1: " + conn1);
out.println("Connection2: " + conn2 + "<br>");
System.out.println("Connection2: " + conn2);
WebdavResource wr1 = conn1.getWebdavResource();
WebdavResource wr2 = conn2.getWebdavResource();
out.println("WR1: " + wr1 + "<br>");
System.out.println("WR1: " + wr1);
out.println("WR2: " + wr2 + "<br>");
System.out.println("WR2: " + wr2);
wr1.putMethod(HOST+"/files/file1", "Content");
String thisIsWhatTx1Sees = wr1.getMethodDataAsString(HOST+"/files/file1");
String thisIsWhatTx2Sees = wr2.getMethodDataAsString(HOST+"/files/file1");
out.println("WR1 sees " + thisIsWhatTx1Sees + "<br>");
System.out.println("WR1 sees " + thisIsWhatTx2Sees);
out.println("WR2 sees " + thisIsWhatTx1Sees + "<br>");
System.out.println("WR2 sees " + thisIsWhatTx2Sees);
tx.commit();
} catch (Exception e) {
if (tx != null)
try {
tx.rollback();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println(e);
e.printStackTrace();
throw new ServletException(e);
} finally {
if (conn1 != null)
try {
conn1.close();
} catch (ResourceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (conn2 != null)
try {
conn2.close();
} catch (ResourceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org