use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class HTTPClient method getMetaData.
private Struct getMetaData(PageContext pc) {
if (meta == null) {
pc = ThreadLocalPageContext.get(pc);
InputStream is = null;
HTTPResponse rsp = null;
try {
rsp = HTTPEngine.get(metaURL, username, password, -1, false, "UTF-8", createUserAgent(pc), proxyData, null);
MimeType mt = getMimeType(rsp, null);
int format = MimeType.toFormat(mt, -1);
if (format == -1)
throw new ApplicationException("cannot convert response with mime type [" + mt + "] to a CFML Object");
is = rsp.getContentAsStream();
Struct data = Caster.toStruct(ReqRspUtil.toObject(pc, IOUtil.toBytes(is, false), format, mt.getCharset(), null));
Object oUDF = data.get(KeyConstants._functions, null);
Object oAACF = data.get(ComponentPageImpl.ACCEPT_ARG_COLL_FORMATS, null);
if (oUDF != null && oAACF != null) {
meta = Caster.toStruct(oUDF);
String[] strFormats = ListUtil.listToStringArray(Caster.toString(oAACF), ',');
argumentsCollectionFormat = UDFUtil.toReturnFormat(strFormats, UDF.RETURN_FORMAT_JSON);
} else {
meta = data;
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new PageRuntimeException(Caster.toPageException(t));
} finally {
IOUtil.closeEL(is);
HTTPEngine.closeEL(rsp);
}
}
return meta;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class HTTPClient method _callWithNamedValues.
private Object _callWithNamedValues(PageContext pc, Key methodName, Struct args) throws PageException {
// prepare request
Map<String, String> formfields = new HashMap<String, String>();
formfields.put("method", methodName.getString());
formfields.put("returnformat", "cfml");
String str;
try {
if (UDF.RETURN_FORMAT_JSON == argumentsCollectionFormat) {
Charset cs = pc.getWebCharset();
str = new JSONConverter(true, cs).serialize(pc, args, false);
formfields.put("argumentCollectionFormat", "json");
} else if (UDF.RETURN_FORMAT_SERIALIZE == argumentsCollectionFormat) {
str = new ScriptConverter().serialize(args);
formfields.put("argumentCollectionFormat", "cfml");
} else {
// Json interpreter also accepts cfscript
str = new ScriptConverter().serialize(args);
}
} catch (ConverterException e) {
throw Caster.toPageException(e);
}
// add aparams to request
formfields.put("argumentCollection", str);
/*
Iterator<Entry<Key, Object>> it = args.entryIterator();
Entry<Key, Object> e;
while(it.hasNext()){
e = it.next();
formfields.put(e.getKey().getString(), Caster.toString(e.getValue()));
}*/
Map<String, String> headers = new HashMap<String, String>();
// application/java disabled for the moment, it is not working when we have different lucee versions
headers.put("accept", "application/cfml,application/json");
HTTPResponse rsp = null;
InputStream is = null;
try {
// call remote cfc
rsp = HTTPEngine.post(url, username, password, -1, false, "UTF-8", createUserAgent(pc), proxyData, headers, formfields);
// read result
Header[] rspHeaders = rsp.getAllHeaders();
MimeType mt = getMimeType(rspHeaders, null);
int format = MimeType.toFormat(mt, -1);
if (format == -1) {
if (rsp.getStatusCode() != 200) {
boolean hasMsg = false;
String msg = rsp.getStatusText();
for (int i = 0; i < rspHeaders.length; i++) {
if (rspHeaders[i].getName().equalsIgnoreCase("exception-message")) {
msg = rspHeaders[i].getValue();
hasMsg = true;
}
}
is = rsp.getContentAsStream();
ApplicationException ae = new ApplicationException("remote component throws the following error:" + msg);
if (!hasMsg)
ae.setAdditional(KeyImpl.init("respone-body"), IOUtil.toString(is, mt.getCharset()));
throw ae;
}
throw new ApplicationException("cannot convert response with mime type [" + mt + "] to a CFML Object");
}
is = rsp.getContentAsStream();
return ReqRspUtil.toObject(pc, IOUtil.toBytes(is, false), format, mt.getCharset(), null);
} catch (IOException ioe) {
throw Caster.toPageException(ioe);
} finally {
IOUtil.closeEL(is);
HTTPEngine.closeEL(rsp);
}
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class MailClient method renameFolder.
public void renameFolder(String srcFolderName, String trgFolderName) throws MessagingException, ApplicationException {
if (srcFolderName.equalsIgnoreCase("INBOX") || srcFolderName.equalsIgnoreCase("OUTBOX"))
throw new ApplicationException("cannot rename folder [" + srcFolderName + "], this folder is protected.");
if (trgFolderName.equalsIgnoreCase("INBOX") || trgFolderName.equalsIgnoreCase("OUTBOX"))
throw new ApplicationException("cannot rename folder to [" + trgFolderName + "], this folder name is protected.");
Folder src = getFolder(srcFolderName, true, true, false);
Folder trg = getFolder(trgFolderName, null, false, true);
if (!src.renameTo(trg))
throw new ApplicationException("cannot rename folder [" + srcFolderName + "] to [" + trgFolderName + "].");
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class MailClient method getInstance.
public static MailClient getInstance(int type, String server, int port, String username, String password, boolean secure, String name, String id) throws Exception {
String uid;
if (StringUtil.isEmpty(name))
uid = createName(type, server, port, username, password, secure);
else
uid = name;
uid = type + ";" + uid + ";" + id;
PoolItem item = pool.get(uid);
if (item == null) {
if (StringUtil.isEmpty(server)) {
if (StringUtil.isEmpty(name))
throw new ApplicationException("missing server information");
else
throw new ApplicationException("there is no connection available with name [" + name + "]");
}
if (TYPE_POP3 == type)
pool.put(uid, item = new PopClient(server, port, username, password, secure));
if (TYPE_IMAP == type)
pool.put(uid, item = new ImapClient(server, port, username, password, secure));
}
return (MailClient) item;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class HtmlHeadBodyBase method processTag.
protected void processTag() throws PageException {
try {
if (StringUtil.isEmpty(action, true) || action.equals("append")) {
required(getTagName(), "text", text);
if (isValid())
actionAppend();
} else if (action.equals("reset")) {
resetIdMap();
actionReset();
} else if (action.equals("write")) {
required(getTagName(), "text", text);
resetIdMap();
if (// call isValid() to register the id if set
isValid())
actionWrite();
} else if (action.equals("read"))
actionRead();
else if (action.equals("flush"))
actionFlush();
else
throw new ApplicationException("invalid value [" + action + "] for attribute action", "values for attribute action are:append,read,reset,write");
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
Aggregations