use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ComponentUtil method _getStructPropertiesClass.
private static Class _getStructPropertiesClass(PageContext pc, Struct sct, PhysicalClassLoader cl) throws PageException, IOException, ClassNotFoundException {
// create hash based on the keys of the struct
String hash = StructUtil.keyHash(sct);
char c = hash.charAt(0);
if (c >= '0' && c <= '9')
hash = "a" + hash;
// create class name (struct class name + hash)
String className = sct.getClass().getName() + "." + hash;
// create physcal location for the file
String real = className.replace('.', '/');
Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
// load existing class
if (classFile.exists()) {
try {
Class clazz = cl.loadClass(className);
if (clazz != null)
return clazz;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
// Properties
List<ASMProperty> props = new ArrayList<ASMProperty>();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
props.add(new ASMPropertyImpl(ASMUtil.toType(e.getValue() == null ? Object.class : Object.class, /*e.getValue().getClass()*/
true), e.getKey().getString()));
}
// create file
byte[] barr = ASMUtil.createPojo(real, props.toArray(new ASMProperty[props.size()]), Object.class, new Class[] { Pojo.class }, null);
// create class file from bytecode
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
return cl.loadClass(className);
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ComponentUtil method getComponentJavaAccess.
// private static final Method INVOKE_PROPERTY = new Method("invoke",Types.OBJECT,new Type[]{Types.STRING,Types.OBJECT_ARRAY});
/**
* generate a ComponentJavaAccess (CJA) class from a component
* a CJA is a dynamic genarted java class that has all method defined inside a component as java methods.
*
* This is used to generated server side Webservices.
* @param component
* @param isNew
* @return
* @throws PageException
*/
public static Class getComponentJavaAccess(PageContext pc, Component component, RefBoolean isNew, boolean create, boolean writeLog, boolean suppressWSbeforeArg, boolean output, boolean returnValue) throws PageException {
isNew.setValue(false);
String classNameOriginal = component.getPageSource().getClassName();
String className = getClassname(component, null).concat("_wrap");
String real = className.replace('.', '/');
String realOriginal = classNameOriginal.replace('.', '/');
Mapping mapping = component.getPageSource().getMapping();
PhysicalClassLoader cl = null;
try {
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
} catch (IOException e) {
throw Caster.toPageException(e);
}
Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
// check last Mod
if (classFile.lastModified() >= classFileOriginal.lastModified()) {
try {
Class clazz = cl.loadClass(className);
if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
return registerTypeMapping(clazz);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
if (!create)
return null;
isNew.setValue(true);
// print.out("new");
// CREATE CLASS
ClassWriter cw = ASMUtil.getClassWriter();
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, real, null, "java/lang/Object", null);
// GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.STATIC_CONSTRUCTOR,null,null,cw);
// StaticConstrBytecodeContext statConstr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.STATIC_CONSTRUCTOR);
// /ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.CONSTRUCTOR,null,null,cw);
// new BytecodeContext(null,null,null,cw,real,ga,Page.CONSTRUCTOR);
ConstrBytecodeContext constr = null;
// field component
// FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, "c", "Llucee/runtime/ComponentImpl;", null, null);
// fv.visitEnd();
java.util.List<LitString> _keys = new ArrayList<LitString>();
// remote methods
Collection.Key[] keys = component.keys(Component.ACCESS_REMOTE);
int max;
for (int i = 0; i < keys.length; i++) {
max = -1;
while ((max = createMethod(constr, _keys, cw, real, component.get(keys[i]), max, writeLog, suppressWSbeforeArg, output, returnValue)) != -1) {
// for overload remove this
break;
}
}
// Constructor
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw);
adapter.loadThis();
adapter.invokeConstructor(Types.OBJECT, CONSTRUCTOR_OBJECT);
lucee.transformer.bytecode.Page.registerFields(new BytecodeContext(null, constr, getPage(constr), _keys, cw, real, adapter, CONSTRUCTOR_OBJECT, writeLog, suppressWSbeforeArg, output, returnValue), _keys);
adapter.returnValue();
adapter.endMethod();
cw.visitEnd();
byte[] barr = cw.toByteArray();
try {
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
return registerTypeMapping(cl.loadClass(className, barr));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
}
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class ThreadUtil method createPageContext.
/**
* @param config
* @param os
* @param serverName
* @param requestURI
* @param queryString
* @param cookies
* @param headers
* @param parameters
* @param attributes
* @param register
* @param timeout timeout in ms, if the value is smaller than 1 it is ignored and the value comming from the context is used
* @return
*/
public static PageContextImpl createPageContext(ConfigWeb config, OutputStream os, String serverName, String requestURI, String queryString, Cookie[] cookies, Pair[] headers, byte[] body, Pair[] parameters, Struct attributes, boolean register, long timeout) {
CFMLFactory factory = config.getFactory();
HttpServletRequest req = new HttpServletRequestDummy(config.getRootDirectory(), serverName, requestURI, queryString, cookies, headers, parameters, attributes, null, body);
req = new HTTPServletRequestWrap(req);
HttpServletResponse rsp = createHttpServletResponse(os);
return (PageContextImpl) factory.getLuceePageContext(factory.getServlet(), req, rsp, null, false, -1, false, register, timeout, false, false);
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Admin method terminateRunningThread.
private static boolean terminateRunningThread(ConfigWeb configWeb, int id) {
Map<Integer, PageContextImpl> pcs = ((CFMLFactoryImpl) configWeb.getFactory()).getActivePageContexts();
Iterator<PageContextImpl> it = pcs.values().iterator();
PageContextImpl pc;
Collection.Key key;
while (it.hasNext()) {
pc = it.next();
if (pc.getId() == id) {
CFMLFactoryImpl.terminate(pc, true);
return true;
}
}
return false;
}
use of lucee.runtime.PageContextImpl in project Lucee by lucee.
the class Admin method fillGetRunningThreads.
private static void fillGetRunningThreads(lucee.runtime.type.Query qry, ConfigWeb configWeb) throws PageException {
CFMLFactoryImpl factory = ((CFMLFactoryImpl) configWeb.getFactory());
Map<Integer, PageContextImpl> pcs = factory.getActivePageContexts();
Iterator<PageContextImpl> it = pcs.values().iterator();
PageContextImpl pc;
Collection.Key key;
int row = 0;
while (it.hasNext()) {
pc = it.next();
qry.addRow();
row++;
StackTraceElement[] st = pc.getThread().getStackTrace();
configWeb.getConfigDir();
configWeb.getIdentification().getId();
configWeb.getConfigDir();
qry.setAt("Id", row, new Double(pc.getId()));
qry.setAt("Start", row, new DateTimeImpl(pc.getStartTime(), false));
qry.setAt("Timeout", row, new Double(pc.getRequestTimeout() / 1000));
qry.setAt("ThreadType", row, pc.getParentPageContext() == null ? "main" : "child");
qry.setAt("StackTrace", row, toString(st));
qry.setAt("TagContext", row, PageExceptionImpl.getTagContext(pc.getConfig(), st));
qry.setAt("label", row, factory.getLabel());
qry.setAt("RootPath", row, ReqRspUtil.getRootPath(((ConfigWebImpl) configWeb).getServletContext()));
qry.setAt("ConfigFile", row, configWeb.getConfigFile().getAbsolutePath());
if (factory.getURL() != null)
qry.setAt("url", row, factory.getURL().toExternalForm());
}
}
Aggregations