wip made remote ejb working over http
This commit is contained in:
parent
d4e537a2bf
commit
2a0d992642
393 changed files with 8916 additions and 3872 deletions
23
vasc-core-ejb3-server/.project
Normal file
23
vasc-core-ejb3-server/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-core-ejb3-server</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
41
vasc-core-ejb3-server/pom.xml
Normal file
41
vasc-core-ejb3-server/pom.xml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc</artifactId>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>vasc-core-ejb3-server</artifactId>
|
||||
<name>vasc-core-ejb3-server</name>
|
||||
<description>vasc-core-ejb3-server</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core-ejb3-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-backend-jpa</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ejb</groupId>
|
||||
<artifactId>ejb-api</artifactId>
|
||||
<version>${ejb-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
<version>${persistence-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-xpql-ejb3-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,324 @@
|
|||
/*
|
||||
* Copyright 2007-2012 forwardfire.net All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.vasc.ejb3;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import net.forwardfire.vasc.backend.VascBackend;
|
||||
import net.forwardfire.vasc.backends.jpa.EntityManagerProvider;
|
||||
import net.forwardfire.vasc.core.VascController;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryControllerLocal;
|
||||
import net.forwardfire.vasc.core.VascEntryLocal;
|
||||
import net.forwardfire.vasc.impl.DefaultVascFactory;
|
||||
import net.forwardfire.vasc.impl.x4o.VascParser;
|
||||
import net.forwardfire.vasc.xpql.ejb3.XpqlQueryManager;
|
||||
import net.forwardfire.vasc.xpql.query.Query;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 13 Aug 2007
|
||||
*/
|
||||
@Stateless(name="vascServiceManager")
|
||||
public class VascServiceManagerImpl implements VascServiceManagerRemote,VascServiceManagerLocal {
|
||||
|
||||
private Logger logger = Logger.getLogger(VascServiceManagerImpl.class.getName());
|
||||
|
||||
protected EntityManager entityManager;
|
||||
|
||||
protected XpqlQueryManager xpqlController = null;
|
||||
|
||||
protected VascController vascController = null;
|
||||
|
||||
//protected ResourceBundle resourceBundle = null;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void loadAll() {
|
||||
logger.fine("VascServiceManager created now loading resources...");
|
||||
try {
|
||||
InitialContext context = new InitialContext();
|
||||
Map<String,String> keys = loadKeys();
|
||||
for (String key:keys.keySet()) {
|
||||
String value = keys.get(key);
|
||||
if ("persistenceUnit".equals(key)) {
|
||||
logger.fine("getting EntityManager: "+value);
|
||||
entityManager = (EntityManager)context.lookup(value);
|
||||
}
|
||||
if ("xpqlController".equals(key)) {
|
||||
logger.fine("getting XpqlQueryManagerLocal: "+value);
|
||||
xpqlController = (XpqlQueryManager)context.lookup(value);
|
||||
}
|
||||
if ("vascController".equals(key)) {
|
||||
logger.fine("getting jndiVascController: "+value);
|
||||
vascController = (VascController)context.lookup(value);
|
||||
}
|
||||
//if ("i18nBundle".equals(key)) {
|
||||
// resourceBundle = ResourceBundle.getBundle(value);
|
||||
//}
|
||||
}
|
||||
/*
|
||||
if (entityManager==null) {
|
||||
new NullPointerException("Have no entityManager");
|
||||
}
|
||||
if (xpqlController==null) {
|
||||
new NullPointerException("Have no xpqlController");
|
||||
}*/
|
||||
//if (resourceBundle==null) {
|
||||
// new NullPointerException("Have no resourceBundle");
|
||||
//}
|
||||
long s = System.currentTimeMillis();
|
||||
|
||||
// get local jvm plugging controller
|
||||
if (vascController==null) {
|
||||
vascController = DefaultVascFactory.getDefaultVascController();
|
||||
}
|
||||
|
||||
for (String key:keys.keySet()) {
|
||||
String value = keys.get(key);
|
||||
if (key.startsWith("load")) {
|
||||
// TODO made reuse working.
|
||||
VascParser vp = new VascParser(vascController);
|
||||
if (xpqlController!=null) {
|
||||
vp.addELBean("xpqlController", new XpqlController());
|
||||
}
|
||||
if (entityManager!=null) {
|
||||
vp.addELBean("entityManagerProvider", new LocalEntityManagerProvider());
|
||||
}
|
||||
vp.parseResource(value);
|
||||
}
|
||||
}
|
||||
DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vascController.getVascEntryController(), vascController);
|
||||
|
||||
|
||||
long t = System.currentTimeMillis()-s;
|
||||
logger.info("Total loaded vasc entries: "+vascController.getVascEntryController().getVascEntryIds().size()+" in "+t+" ms.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Error while init resources error: "+e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads xtes-xpql-ejb3.xml from meta-inf and gives the keys
|
||||
*/
|
||||
protected Map<String,String> loadKeys() throws IOException {
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
logger.fine("Getting urls");
|
||||
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/vasc-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading reletive namespaces of: "+u+" for: META-INF/vasc-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/META-INF/vasc-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading root namespaces of: "+u+" for: /META-INF/vasc-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.fine("done loading");
|
||||
|
||||
Map<String,String> result = new HashMap<String,String>(20);
|
||||
for (Object key:properties.keySet()) {
|
||||
if (key instanceof String) {
|
||||
String key2 = (String) key;
|
||||
String value = properties.getProperty(key2);
|
||||
result.put(key2, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
public Map<String,String> getResourceBundle(String locale) {
|
||||
Map<String,String> result = new HashMap<String,String>(resourceBundle.keySet().size());
|
||||
for (String key:resourceBundle.keySet()) {
|
||||
String value = resourceBundle.getString(key);
|
||||
result.put(key,value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
public List<String> getVascEntryIds() {
|
||||
VascController v = getVascController();
|
||||
if (v==null) {
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
return v.getVascEntryController().getVascEntryIds();
|
||||
}
|
||||
|
||||
public VascEntry getVascEntry(String entryId) {
|
||||
VascController v = getVascController();
|
||||
VascEntryLocal ve = (VascEntryLocal)v.getVascEntryController().getVascEntryById(entryId);
|
||||
|
||||
try {
|
||||
VascEntry result = ve.clone();
|
||||
logger.info("Returning cloned ve.");
|
||||
|
||||
ByteArrayOutputStream dataArray = new ByteArrayOutputStream(256); // it grows when needed
|
||||
ObjectOutputStream objOutstream = new ObjectOutputStream(dataArray);
|
||||
objOutstream.writeObject(ve);
|
||||
objOutstream.close();
|
||||
|
||||
int objectSize = dataArray.size();
|
||||
|
||||
logger.info("Writing obj to data: "+objectSize);
|
||||
|
||||
return result;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new RuntimeException("VascEntry should alway be clonable",e);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("VascEntry error:",e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object invokeBackendMethod(String backendId,String method,Object[] args) {
|
||||
VascController v = getVascController();
|
||||
VascBackend vb = v.getVascBackendController().getVascBackendById(backendId);
|
||||
Method vbm = null;
|
||||
for (Method m:vb.getClass().getMethods()) {
|
||||
if (m.getName().equals(method)) {
|
||||
vbm = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (vbm==null) {
|
||||
throw new IllegalArgumentException("Could not find: "+method);
|
||||
}
|
||||
try {
|
||||
Object result = vbm.invoke(vb, args);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public VascController getVascController() {
|
||||
return vascController;
|
||||
}
|
||||
|
||||
class XpqlController implements Map<String,Query> {
|
||||
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, Query>> entrySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Query get(Object key) {
|
||||
return xpqlController.getQuery((String)key);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Query put(String key, Query value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map m) {
|
||||
}
|
||||
|
||||
public Query remove(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Collection<Query> values() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LocalEntityManagerProvider implements EntityManagerProvider {
|
||||
/**
|
||||
* @see net.forwardfire.vasc.backends.jpa.EntityManagerProvider#getEntityManager()
|
||||
*/
|
||||
public EntityManager getEntityManager() {
|
||||
return entityManager;
|
||||
}
|
||||
|
||||
public boolean hasEntityManagerTransaction() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<ejb-jar/>
|
||||
Loading…
Add table
Add a link
Reference in a new issue