[jboss-cvs] jboss-seam/src/main/org/jboss/seam/remoting ...
Shane Bryzak
Shane_Bryzak at symantec.com
Tue Feb 13 19:36:48 EST 2007
User: sbryzak2
Date: 07/02/13 19:36:48
Modified: src/main/org/jboss/seam/remoting remote.js
Added: src/main/org/jboss/seam/remoting
RemotingResourceProvider.java
Removed: src/main/org/jboss/seam/remoting SeamRemotingServlet.java
Log:
replaced SeamRemotingServlet with RemotingResourceProvider
Revision Changes Path
1.22 +1 -1 jboss-seam/src/main/org/jboss/seam/remoting/remote.js
(In the diff below, changes in quantity of whitespace are not shown.)
Index: remote.js
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/remoting/remote.js,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- remote.js 17 Oct 2006 21:54:19 -0000 1.21
+++ remote.js 14 Feb 2007 00:36:48 -0000 1.22
@@ -589,7 +589,7 @@
asyncReq = new ActiveXObject("Microsoft.XMLHTTP");
asyncReq.onreadystatechange = function() {Seam.Remoting.requestCallback(asyncReq, callback); }
- asyncReq.open("POST", Seam.Remoting.contextPath + "/seam/remoting" + path, true);
+ asyncReq.open("POST", Seam.Remoting.resourcePath + path, true);
asyncReq.send(envelope);
return asyncReq;
}
1.1 date: 2007/02/14 00:36:48; author: sbryzak2; state: Exp;jboss-seam/src/main/org/jboss/seam/remoting/RemotingResourceProvider.java
Index: RemotingResourceProvider.java
===================================================================
package org.jboss.seam.remoting;
import static org.jboss.seam.InterceptionType.NEVER;
import static org.jboss.seam.ScopeType.APPLICATION;
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Intercept;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.ResourceProvider;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.contexts.Lifecycle;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.servlet.AbstractResourceProvider;
@Startup
@Scope(APPLICATION)
@Name("org.jboss.seam.remoting.remotingResourceProvider")
@Install(precedence = BUILT_IN)
@Intercept(NEVER)
@ResourceProvider("/remoting")
public class RemotingResourceProvider extends AbstractResourceProvider
{
/**
* We use a Map for this because a Servlet can serve requests for more than
* one context path.
*/
private Map<String, byte[]> cachedConfig = new HashMap<String, byte[]>();
private static final LogProvider log = Logging.getLogProvider(RemotingResourceProvider.class);
private static final Pattern pathPattern = Pattern.compile("/(.*?)/([^/]+)");
private static final String RESOURCE_PATH = "resource";
private String resourcePath;
public RemotingResourceProvider()
{
ResourceProvider p = getClass().getAnnotation(ResourceProvider.class);
resourcePath = p.value();
}
private synchronized void initConfig(String contextPath,
HttpSession session, HttpServletRequest request)
{
if (!cachedConfig.containsKey(contextPath))
{
try
{
Lifecycle.beginRequest(getServletContext(), session, request);
StringBuilder sb = new StringBuilder();
sb.append("\nSeam.Remoting.resourcePath = \"");
sb.append(contextPath);
sb.append(request.getServletPath());
sb.append(resourcePath);
sb.append("\";");
sb.append("\nSeam.Remoting.debug = ");
sb.append(RemotingConfig.instance().getDebug() ? "true" : "false");
sb.append(";");
sb.append("\nSeam.Remoting.pollInterval = ");
sb.append(RemotingConfig.instance().getPollInterval());
sb.append(";");
sb.append("\nSeam.Remoting.pollTimeout = ");
sb.append(RemotingConfig.instance().getPollTimeout());
sb.append(";");
cachedConfig.put(contextPath, sb.toString().getBytes());
}
finally
{
Lifecycle.endRequest(session);
}
}
}
@Override
public void getResource(HttpServletRequest request, HttpServletResponse response)
throws IOException
{
try
{
String pathInfo = request.getPathInfo().substring(resourcePath.length());
RequestHandler handler = RequestHandlerFactory.getInstance()
.getRequestHandler(pathInfo);
if (handler != null)
{
handler.setServletContext(getServletContext());
handler.handle(request, response);
}
else
{
Matcher m = pathPattern.matcher(pathInfo);
if (m.matches())
{
String path = m.group(1);
String resource = m.group(2);
HttpSession session = request.getSession();
if (RESOURCE_PATH.equals(path))
{
writeResource(resource, response.getOutputStream());
if ("remote.js".equals(resource))
{
appendConfig(response.getOutputStream(), request
.getContextPath(), session, request);
}
}
response.getOutputStream().flush();
}
}
}
catch (Exception ex)
{
log.error("Error", ex);
}
}
/**
* Appends various configuration options to the remoting javascript client
* api.
*
* @param out OutputStream
*/
private void appendConfig(OutputStream out, String contextPath,
HttpSession session, HttpServletRequest request) throws IOException
{
if (!cachedConfig.containsKey(contextPath))
initConfig(contextPath, session, request);
out.write(cachedConfig.get(contextPath));
}
/**
*
* @param resourceName String
* @param out OutputStream
*/
private void writeResource(String resourceName, OutputStream out)
throws IOException
{
// Only allow resource requests for .js files
if (resourceName.endsWith(".js"))
{
InputStream in = this.getClass().getClassLoader().getResourceAsStream(
"org/jboss/seam/remoting/" + resourceName);
if (in != null)
{
byte[] buffer = new byte[1024];
int read = in.read(buffer);
while (read != -1)
{
out.write(buffer, 0, read);
read = in.read(buffer);
}
}
else
log.error(String.format("Resource [%s] not found.", resourceName));
}
}
}
More information about the jboss-cvs-commits
mailing list