Sunday, July 19, 2009

Remove Write Protection Micro Sdhc

GWT 1.6 Hosted Mode: internal Jetty server with JDNI Data Sources and Environment Information for PostgreSQL provide

DSCF0005c
Update: In GWT Version 2.0.3 seems method will still work!
As one of the most tedious things you find when entering the GWT programming must admit I felt the solution to the following question: How does
internal Jetty server that is in the hosted mode used development under Eclipse with the plugin Google to provide the server-side programming JBDC connections or connection pools and other JNDI resources?
will probably be almost any reasonably ambitious GWT project sometime before this task. If it does not resolve you would have the enormous advantages of the hosted mode development waive his translation GWT project for each test run (Java -> Javascript) and do without the helpful development functions.

information on the web

In the actual GWT pages you find any particularly useful information. In the thread Setting DataSource (JNDI) in GWT 1.6 (hosted mode - Jetty) in Google Groups can be found, however, help that take us finally to the solution.
On my first attempt to solve the problem but I am following the link followed from the comments, because the solution seemed simple:
http://humblecode.blogspot.com/2009/05/gwt-16-using-jndi-datasource.html
also find other helpful links, such as Jetty to appropriate pages. Unfortunately, I am with this solution failed due to the question of how the Jetty server the missing by default JNDI context java: is comp / env available. Therefore, I have finally ended the solution of the Google Groups implemented. This, and the adjustment for our PostgreSQL database will be described below:

bit by bit

first Jetty and JDBC JARs
First you should get the necessary JARs. These are the extensions for a Jetty, on the other hand, the JDBC driver for PostgreSQL. Click the links for the download:
Jetty: http://dist.codehaus.org/jetty/
Here you can find to Jetty version 6 Version 7 of the download the Eclipse project can be found. When you download a version 6 in one of the subdirectories to go and the larger (non- src) Get ZIP archive, it to find the two jars.
PostgreSQL JDBC: http://jdbc.postgresql.org/download.html
JDBC3 the version I have used.
Altogether you the Jetty server then make available the following JARs:
  • jetty-naming-*. jar
  • jetty-plus-*. jar
  • postgresql-*. jdbc3.jar
Man the JARs, the simplicity in / was placed / WEB-INF / lib / , even if not needed for the actual application. The JARs must be placed in the launch configuration properties in the classpath (under User Entries ).
second jetty-env.xml
In was / / Create WEB-INF / directory the file jetty-env.xml . Here are the resources for the JNDI context can be created. Unfortunately you can only learn from a little any existing configuration for Tomcat, Jetty as many different makes. In our case, in addition to the DataSource configuration information is stored. Both definitions see my jetty-env.xml this:
 \u0026lt;xml version = "1.0"?> \u0026lt;

- Is used only for the use of the GWT hosted mode development - ->

\u0026lt;configure class="org.mortbay.jetty.webapp.WebAppContext">

\u0026lt;new class="org.mortbay.jetty.plus.naming.EnvEntry">
\u0026lt;arg> \u0026lt;/ arg>
\u0026lt;arg> meinEnvParameter \u0026lt;/ arg>
\u0026lt;arg type = "java . lang.String> some string \u0026lt;/ arg>
\u0026lt;arg type="boolean"> true \u0026lt;/ arg>
\u0026lt;/ new>

\u0026lt;new id = "jdbc / meinDBPool" class = " org.mortbay.jetty.plus.naming.Resource>
\u0026lt;arg> \u0026lt;/ arg>
\u0026lt;arg> jdbc / meinDBPool \u0026lt;/> arg
<arg>
<new class="org.postgresql.ds.PGSimpleDataSource">
<set name="User">meinPostgresBenutzer</set>
<set name="Password">meinPostgresPasswort</set>
<set name="DatabaseName">meinePostgresDatenbank</set>
<set name="ServerName">localhost</set>
<set name="PortNumber">5432</set>
</new>
</arg>
</new>

\u0026lt;/ configure>


The appropriate resources must of course be, as always, defined in the web.xml :


 \u0026lt;resource-ref> 
\u0026lt;res-ref-name> jdbc / meinDBPool \u0026lt; ; / res-ref-name>
\u0026lt;res-type> javax.sql.DataSource \u0026lt;/ res-type>
\u0026lt;res-auth> Container \u0026lt;/ res-auth>
\u0026lt;/ resource-ref>


But that should already be the case in most cases.


third env context configure


One problem is overcome now: Jetty known in the standard configuration or not Environment Context, which is what you queries typically:


 Context initCtx = new InitialContext (); 
Context myenv = (Context) initCtx. lookup ("java: comp / env");


Jetty might want to be kept lean this way for certain scenarios, but here it is another stumbling block is that is overcome. There seems to be possible to supply the Jetty XML configuration of context, but unfortunately I have not figured out how. It is therefore in the way described Google Groups taken, which is to implement your own starter class for the internal server.


The GWT uses by default the class



com.google.gwt.dev.shell.jetty.JettyLauncher



to the server for the hosted mode launch. This class is located, including source code in gwt-dev- windows.jar . This class must be extended. The easiest way is probably where you copied the source code is in a class (when you upgrade to the next GWT needs to see it, perhaps, if anything has changed). Let's call the new class



org.unibi.sm.edit. MyCustomJettyLauncher



and put them in the source directory of the GWT project. Now it's just a matter of the WebappClassLoader foist the corresponding configuration with which he presents the required context is available. Here's the code snippet, in the end finds himself once again the complete MyCustomJettyLaucher.java :


 / / Additional code Start: 
private static string [] = {__dftConfigurationClasses
"org.mortbay.jetty.webapp.WebInfConfiguration" / /
"org.mortbay.jetty.plus.webapp.EnvConfiguration", / / jetty-env
"org.mortbay.jetty.plus.webapp.Configuration", // web.xml
"org.mortbay.jetty.webapp.JettyWebXmlConfiguration",// jettyWeb
};
// Zusaetzlicher Quellcode Ende.

/**
* A {@link WebAppContext} tailored to GWT hosted mode. Features....
*/
protected final class WebAppContextWithReload extends WebAppContext {

/**
* Specialized {@link WebAppClassLoader} that allows outside…
*/
private class WebAppClassLoaderExtension extends WebAppClassLoader {

private static final String META_INF_SERVICES = "META-INF/services/";

public WebAppClassLoaderExtension() throws IOException {super
(bootStrapOnlyClassLoader, WebAppContextWithReload.this);

/ / Additional code Start:
setConfigurationClasses (__dftConfigurationClasses);
/ / Additional code end.
}


are therefore added in the constructor of the inner class that extends the WebappClassLoader , a list of previously defined configuration classes. Last you need now run the Configuration of the project made to launch our new explanation aces are used. This is simply the argument tab under Program arguments adds the following option:



-server org.unibi.sm.edit.MyCustomJettyLauncher



So it looks like:


EclipseJetty


4th should start


If everything was done correctly, the internal Jetty now start without error messages and the GWT server-side programming can be as described above to access databases and other environment objects.


Important: If To test the effect of changes to stop a possibly running hosted mode environment completely and start again.




The third way



addition to the hint a possible third way between waiving the hosted mode, and the arduous Jetty configuration: Oliver describes a way to get the hosted mode without the built-in server to use. Here then the server-side code and the static content of the project by an external AppServer be performed or delivered. This is especially interesting when you have finished anyway has a configured AppServer for its development. However, Oliver's text refers to a somewhat older version of GWT, the Tomcat was still used as an internal server.




Source 'org.unibi.sm.edit.MyCustomJettyLauncher'



 package  org.unibi.sm.edit; 

import com.google.gwt.core.ext.ServletContainer;
import com.google.gwt.core.ext.ServletContainerLauncher;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.shell.jetty.JettyNullLogger;
import com.google.gwt.dev.util.InstalledHelpInfo;

import org.mortbay.component.AbstractLifeCycle;
import org.mortbay.jetty.AbstractConnector;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.RequestLog;
import org.mortbay.jetty.Response;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.RequestLogHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppClassLoader;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.log.Log;
import org.mortbay.log.Logger;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

/**
* A {@link ServletContainerLauncher} for an embedded Jetty server.
*/
public class MyCustomJettyLauncher extends ServletContainerLauncher {

/**
* Log jetty requests/responses to TreeLogger.
*/
public static class JettyRequestLogger extends AbstractLifeCycle implements
RequestLog {

private final TreeLogger logger;

public JettyRequestLogger(TreeLogger logger) {
this.logger = logger;
}

/**
* Log an HTTP request/response to TreeLogger.
*/
@SuppressWarnings("unchecked")
public void log(Request request, Response response) {
int status = response.getStatus();
if (status < 0) {
// Copied from NCSARequestLog
status = 404;
}
TreeLogger.Type logStatus, logHeaders;
if (status >= 500) {
logStatus = TreeLogger.ERROR;
logHeaders = TreeLogger.INFO;
} else if (status >= 400) {
logStatus = TreeLogger.WARN;
logHeaders = TreeLogger.INFO;
} else {
logStatus = TreeLogger.INFO;
logHeaders = TreeLogger.DEBUG;
}
String userString = request.getRemoteUser();
if (userString == null) {
userString = "";
} else {
userString += "@";
}
String bytesString = "";
if (response.getContentCount() > 0) {
bytesString = " " + response.getContentCount() + " bytes";
}
TreeLogger branch = logger.branch(logStatus, String.valueOf(status)
+ " - " + request.getMethod() + ' ' + request.getUri()
+ " (" + userString + request.getRemoteHost() + ')'
+ bytesString);
TreeLogger headers = branch.branch(logHeaders, "Request headers");
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String hdr = headerNames.nextElement();
String hdrVal = request.getHeader(hdr);
headers.log(logHeaders, hdr + ": " + hdrVal);
}
// TODO(jat): add response headers
}
}

/**
* An adapter for the Jetty logging system to GWT's TreeLogger. This
* implementation class is only public to allow {@link Log} to instantiate
* it.
*
* The weird static data / default construction setup is a game we play with
* {@link Log}'s static initializer to prevent the initial log message from
* going to stderr.
*/
public static class JettyTreeLogger implements Logger {
private final TreeLogger logger;

public JettyTreeLogger(TreeLogger logger) {
if (logger == null) {
throw new NullPointerException();
}
this.logger = logger;
}

public void debug(String msg, Object arg0, Object arg1) {
logger.log(TreeLogger.SPAM, format(msg, arg0, arg1));
}

public void debug(String msg, Throwable th) {
logger.log(TreeLogger.SPAM, msg, th);
}

public Logger getLogger(String name) {
return this;
}

public void info(String msg, Object arg0, Object arg1) {
logger.log(TreeLogger.INFO, format(msg, arg0, arg1));
}

public boolean isDebugEnabled() {
return logger.isLoggable(TreeLogger.SPAM);
}

public void setDebugEnabled(boolean enabled) {
// ignored
}

public void warn(String msg, Object arg0, Object arg1) {
logger.log(TreeLogger.WARN, format(msg, arg0, arg1));
}

public void warn(String msg, Throwable th) {
logger.log(TreeLogger.WARN, msg, th);


} / ** * copied from org.mortbay.log.StdErrLog
.
* /
private String format (String msg, Object arg0, Object arg1) {int
0 = msg.indexOf ("{}");
int i1 = I0 \u0026lt;0? -1: Msg.indexOf ("{}", I0 + 2);

if (arg1! = Null & & i1> = 0) {msg = msg.substring
(0, i1) + arg1 + msg.substring (i1 + 2);

} if (arg0! = null & & I0> = 0) {msg = msg.substring
(0, I0) + arg0 + msg.substring (I0 + 2 );}

return msg;}
}


/**
* The resulting {@link ServletContainer} this is launched.
*/
protected static class JettyServletContainer extends ServletContainer {
private final int actualPort;
private final File appRootDir;
private final TreeLogger logger;
private final Server server;
private final WebAppContext wac;

public JettyServletContainer(TreeLogger logger, Server server,
WebAppContext wac, int actualPort, File appRootDir) {
this.logger = logger;
this.server = server;
this.wac = wac;
this.actualPort = actualPort;
this.appRootDir = appRootDir;
}

public int getPort() {
return actualPort;
}

public void refresh() throws UnableToCompleteException {
String msg = "Reloading web app to reflect changes in "
+ appRootDir.getAbsolutePath();
TreeLogger branch = logger.branch(TreeLogger.INFO, msg);
// Temporarily log Jetty on the branch.
Log.setLog(new JettyTreeLogger(branch));
try {
wac.stop();
wac.start();
branch.log(TreeLogger.INFO, "Reload completed successfully");
} catch (Exception e) {
branch.log(TreeLogger.ERROR,
"Unable to restart embedded Jetty server", e);
throw new UnableToCompleteException();
} finally {
// Reset the top-level logger.
Log.setLog(new JettyTreeLogger(logger));
}
}

public void stop() throws UnableToCompleteException {
TreeLogger branch = logger.branch(TreeLogger.INFO,
"Stopping Jetty server");
// Temporarily log Jetty on the branch.
Log.setLog(new JettyTreeLogger(branch));
try {
server.stop();
server.setStopAtShutdown(false);
branch.log(TreeLogger.INFO, "Stopped successfully");
} catch (Exception e) {
branch.log(TreeLogger.ERROR,
"Unable to stop embedded Jetty server", e);
throw new UnableToCompleteException();
} finally {
// Reset the top-level logger.
Log.setLog(new JettyTreeLogger(logger));
}
}
}

private static String[] __dftConfigurationClasses = {
"org.mortbay.jetty.webapp.WebInfConfiguration", //
"org.mortbay.jetty.plus.webapp.EnvConfiguration",// jetty-env
"org.mortbay.jetty.plus.webapp.Configuration", // web.xml
"org.mortbay.jetty.webapp.JettyWebXmlConfiguration",// jettyWeb
};

/**
* A {@link WebAppContext} tailored to GWT hosted mode. Features hot-reload
* with a new {@link WebAppClassLoader} to pick up disk changes. The default
* Jetty {@code WebAppContext} will create new instances of servlets, but it
* will not create a brand new {@link ClassLoader}. By creating a new
* {@code ClassLoader} each time, we re-read updated classes from disk.
*
* Also provides special class filtering to isolate the web app from the GWT
* hosting environment.
*/
protected final class WebAppContextWithReload extends WebAppContext {

/**
* Specialized {@link WebAppClassLoader} that allows outside resources
* to be brought in dynamically from the system path. A warning is
* issued when this occurs.
*/
private class WebAppClassLoaderExtension extends WebAppClassLoader {

private static final String META_INF_SERVICES = "META-INF/services/";

public WebAppClassLoaderExtension() throws IOException {
super(bootStrapOnlyClassLoader, WebAppContextWithReload.this);

setConfigurationClasses(__dftConfigurationClasses);
}

@Override
public URL findResource(String name) {
// Specifically for
// META-INF/services/javax.xml.parsers.SAXParserFactory
String checkName = name;
if (checkName.startsWith(META_INF_SERVICES)) {
checkName = checkName.substring(META_INF_SERVICES.length());
}

// For a system path, load from the outside world.
URL found;
if (isSystemPath(checkName)) {
found = systemClassLoader.getResource(name);
if (found != null) {
return found;
}
}

// Always check this ClassLoader first.
found = super.findResource(name);
if (found != null) {
return found;
}

// See if the outside world has it.
found = systemClassLoader.getResource(name);
if (found == null) {
return null;
}

// Warn, add containing URL to our own ClassLoader, and retry
// the call.
String warnMessage = "Server resource '"
+ name
+ "' could not be found in the web app, but was found on the system classpath";
if (!addContainingClassPathEntry(warnMessage, found, name)) {
return null;
}
return super.findResource(name);
}

/**
* Override to additionally consider the most commonly available JSP
* and XML implementation as system resources. (In fact, Jasper is
* in gwt-dev via embedded Tomcat, so we always hit this case.)
*/
@Override
public boolean isSystemPath(String name) {
name = name.replace('/', '.');
return super.isSystemPath(name)
name)
throws ClassNotFoundException {
// For system path, always prefer the outside world.
if (isSystemPath(name)) {
try {
return systemClassLoader.loadClass(name);
} catch (ClassNotFoundException e) {
}
}

try {
return super.findClass(name);
} catch (ClassNotFoundException e) {
// Don't allow server classes to be loaded from the outside.
if (isServerPath(name)) {
throw e;
}
}

// See if the outside world has a URL for it.
String resourceName = name.replace('.', '/') + ".class";
URL found = systemClassLoader.getResource(resourceName);
if (found == null) {
return null;
}

// Warn, add containing URL to our own ClassLoader, and retry
// the call.
String warnMessage = "Server class '"
+ name
+ "' could not be found in the web app, but was found on the system classpath";
if (!addContainingClassPathEntry(warnMessage, found,
resourceName)) {
throw new ClassNotFoundException(name);
}
return super.findClass(name);
}

private boolean addContainingClassPathEntry(String warnMessage,
URL resource, String resourceName) {
TreeLogger.Type logLevel = (System
.getProperty(PROPERTY_NOWARN_WEBAPP_CLASSPATH) == null) ? TreeLogger.WARN
: TreeLogger.DEBUG;
TreeLogger branch = logger.branch(logLevel, warnMessage);
String classPathURL;
String foundStr = resource.toExternalForm();
if (resource.getProtocol().equals("file")) {
assert foundStr.endsWith(resourceName);
classPathURL = foundStr.substring(0, foundStr.length()
- resourceName.length());
} else if (resource.getProtocol().equals("jar")) {
assert foundStr.startsWith("jar:");
assert foundStr.endsWith("!/" + resourceName);
classPathURL = foundStr.substring(4, foundStr.length()
- (2 + resourceName.length()));
} else {
branch.log(TreeLogger.ERROR,
"Found resouce but unrecognized URL format: '"
+ foundStr + '\'');
return false;
}
branch = branch.branch(logLevel, "Adding classpath entry '"
+ classPathURL
+ "' to the web app classpath for this session", null,
new InstalledHelpInfo("webAppClassPath.html"));
try {
addClassPath(classPathURL);
return true;
} catch (IOException e) {
branch.log(TreeLogger.ERROR, "Failed add container URL: '"
+ classPathURL + '\'', e);
return false;
}
}
}

/**
* Parent ClassLoader for the Jetty web app, which can only load JVM
* classes. We would just use
null
for the parent
* ClassLoader except this makes Jetty unhappy.
*/
private final ClassLoader bootStrapOnlyClassLoader = new ClassLoader( null) { };

private final TreeLogger logger;

/**
* In the usual case of launching {@link com.google.gwt.dev.HostedMode},
* this will always by the system app ClassLoader.
*/
private final ClassLoader systemClassLoader = Thread.currentThread()
.getContextClassLoader();

@SuppressWarnings("unchecked")
private WebAppContextWithReload(TreeLogger logger, String webApp,
String contextPath) {
super(webApp, contextPath);
this.logger = logger;

// Prevent file locking on Windows; pick up file changes.
getInitParams().put(
"org.mortbay.jetty.servlet.Default.useFileMappedBuffer",
"false");

// Since the parent class loader is bootstrap-only, prefer it first.
setParentLoaderPriority(true);
}

@Override
protected void doStart() throws Exception {
setClassLoader(new WebAppClassLoaderExtension());
super.doStart();
}

@Override
protected void doStop() throws Exception {
super.doStop();
setClassLoader(null);
}
}

/**
* System property to suppress warnings about loading web app classes from
* the system classpath.
*/
private static final String PROPERTY_NOWARN_WEBAPP_CLASSPATH = "gwt.nowarn.webapp.classpath";

static {
// Suppress spammy Jetty log initialization.
System.setProperty("org.mortbay.log.class", JettyNullLogger.class
.getName());
Log.getLog();

/*
* Make JDT the default Ant compiler so that JSP compilation just works
* out-of-the-box. If we don't set this, it's very, very difficult to
* make JSP compilation work.
*/
String antJavaC = System.getProperty("build.compiler",
"org.eclipse.jdt.core.JDTCompilerAdapter");
System.setProperty("build.compiler", antJavaC);
}

public ServletContainer start(TreeLogger logger, int port, File appRootDir)
throws Exception {
TreeLogger branch = logger.branch(TreeLogger.INFO,
"Starting Jetty on port " + port, null);

checkStartParams(branch, port, appRootDir);

// Setup our branch logger during startup.
Log.setLog(new JettyTreeLogger(branch));

// Turn off XML validation.
System.setProperty("org.mortbay.xml.XmlParser.Validating", "false");

AbstractConnector connector = getConnector();
connector.setPort(port);

// Don't share ports with an existing process.
connector.setReuseAddress(false);

// Linux keeps the port blocked after shutdown if we don't disable this.
connector.setSoLingerTime(0);

Server server = new Server();
server.addConnector(connector);

// Create a new web app in the war directory.
WebAppContext wac = new WebAppContextWithReload(logger, appRootDir
.getAbsolutePath(), "/");

RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new JettyRequestLogger(logger));
logHandler.setHandler(wac);
server.setHandler(logHandler);
server.start();
server.setStopAtShutdown(true);

// Now that we're started, log to the top level logger.
Log.setLog(new JettyTreeLogger(logger));

return new JettyServletContainer(logger, server, wac, connector
.getLocalPort(), appRootDir);
}

protected AbstractConnector getConnector() {
return new SelectChannelConnector();
}

private void checkStartParams(TreeLogger logger, int port, File appRootDir) {
if (logger == null) {
throw new NullPointerException("logger cannot be null");


} if (port \u0026lt;0 probably a distinction between the free (aka ad-supported) Standard Edition and the paid Professional Edition to take. An overview of the different editions provide the rest of the English Wikipedia article

.

Google Apps Premier / Premier

In
Google Apps Help
is made available to the following statement:


We guarantee that Google is at least 99.9 percent of the time is available to help make employees more productive and less to have to worry about a breakdown .**


After Google's calculation gives the 15 minutes of downtime month. In the footnotes, however, the
Terms
directed with the restriction that the SLA is valid only if the apps in accordance with these conditions are used. The Professional Edition is available today (08/07/2009) at a price of 40 € / user account / year.
Education Edition

is loud Wikipedia QP1050077 a variant of the Premier / Professional Edition. However, apparently without the availability guarantee. Standard Edition

Here I have found no information from Google. However, according to the experience almost as high as the reliability of the Professional Edition. Or knows somebody sources?

convince yourself ... .. can to some extent on the status

Apps Dashboard
:

http://www.google.com/appsstatus # hl = en

Here you can for the various services the corresponding status information, it can also go far in the past and look at the (relatively few) problem cases, such as Google has dealt with it (and see, for example, the solution time). The objectives pursued with the Dashboard and Google, Google itself

as described

:

In February, we brought the Apps Status Dashboard

on the way to keep you better informed about the condition and efficiency of our services such as Google Mail to keep Google Calendar or Google Docs to date. This dashboard you can use to check at any time, whether our service will work as smoothly or whether you experience an error. We have received many positive feedback and helpful hints from users and customers to make the dashboard more useful.

Due the high visibility, it is probably not Google simply be possible in the dashboard to conceal losses.

0 comments:

Post a Comment