public class JotyServer
extends javax.servlet.http.HttpServlet
implements org.joty.common.JotyMessenger
It accepts Http requests from the org.joty.web.WebClient object running on the client side. On the first call from a client or on new Http session (due to expiration of the preceding one), it forces the user to authenticate and manages his authentication on the dbms.
the server looks in the requesting Url for the query string parameter 'command' that can worth as follow: when the request is forwarded as http GET admitted values are {config, end}, when the request is a http POST possible values are {query, exec, trans, report}.
In the case of 'config' value for the Joty command another query string
parameter comes in to play: 'type' = {conf, confX, jotyLang, appLang}. Even
for other Joty commands other query string parameters play a role: this can
be encountered along the doPost
implementation.
As the WebClient the server uses UTF8 encoding a part from binary content for which a single byte encoding is used.
Modifier and Type | Field and Description |
---|---|
protected org.joty.access.Accessor |
m_accessor |
protected org.joty.access.BirtManager |
m_BirtManager |
protected java.util.Vector<byte[]> |
m_bytesElems |
protected java.lang.String |
m_command |
protected org.joty.common.ConfigFile |
m_configuration |
protected java.sql.Connection |
m_conn |
protected org.joty.access.DbManager.DbConnectionGrabber |
m_connGrabber |
protected java.lang.String |
m_dbLogName |
protected boolean |
m_debug |
protected org.joty.common.ErrorCarrier |
m_errorCarrier |
protected boolean |
m_logDbActions |
protected org.joty.access.MethodExecutor |
m_methodExecutor |
protected boolean |
m_msSqlServer |
protected java.util.Vector<org.joty.access.PostStatement> |
m_postStatements |
protected org.joty.common.ParamContext |
m_queryDefParamContext |
protected org.joty.access.PostStatement |
m_queryDefPostStatement |
protected boolean |
m_remoteAccessor |
protected java.util.Vector<java.lang.String> |
m_returnedValues
holds the generated values resulting by the execution of
dbExecute() |
protected org.joty.common.ConfigFile |
m_serverConfig |
protected java.lang.String |
m_singleByteEncoding |
protected boolean |
m_success |
protected boolean |
m_use_BIRT |
protected org.joty.common.XmlTextEncoder |
m_xmlEncoder |
Constructor and Description |
---|
JotyServer() |
Modifier and Type | Method and Description |
---|---|
void |
afterReportRender(java.lang.String arg0) |
void |
ASSERT(boolean predicate) |
protected boolean |
attributePredicate(javax.servlet.http.HttpServletRequest request,
java.lang.String attr,
boolean defTruth) |
void |
beforeReportRender() |
protected void |
beginTrans() |
protected java.lang.String |
buildXmlResult()
Envelopes the content of the
m_returnedValues member in a convenient xml structure. |
protected boolean |
checkCredentials(javax.servlet.http.HttpServletRequest request,
java.lang.String command,
boolean sessionIsALive) |
protected boolean |
checkRequestPostContent(java.lang.String postedContent) |
protected boolean |
commit() |
protected void |
dbExecute()
Performs the execution of the statements held by the
m_postStatements member either the transaction is the case or a
single statement is to be executed. |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
It is responsible of building the Joty response for the request of configuration
data and for the request of ending the session.
|
protected void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Builds the most part of the responses since almost all the Joty web
commands are dispatched through an http post command, because they
require a body to be delivered.
|
protected java.lang.String |
encodedBytes() |
protected void |
endTrans() |
protected boolean |
executeSql(java.lang.String sql)
Executes an sql statement either it be participating in a transaction or standing alone
|
protected java.lang.Boolean |
executeStmnt(java.lang.String sql)
Serves
executeSql in executing an sql statement. |
protected java.lang.String |
getNodeValue(org.w3c.dom.Node node,
java.lang.String name) |
protected java.lang.String |
getPostedContent(javax.servlet.http.HttpServletRequest request)
Gets the body of the Http Post command.
|
protected java.lang.String |
getReportXml(java.lang.String reportName,
java.lang.String formatType,
java.lang.String language,
boolean twoProcesses)
Accepts data identifying the report to be executed, use the BIRT Engine
for the elaboration of it.
|
protected java.lang.String |
getResponseFromLogin(java.lang.String user,
java.lang.String pwd,
java.lang.String query) |
protected java.lang.String |
getResultFromException(java.lang.Exception e) |
protected java.lang.String |
getResultFromFailure(java.lang.String msg) |
protected java.lang.String |
getResultFromFailure(java.lang.String msg,
java.lang.String code) |
protected java.lang.String |
getResultSetAsXml(java.sql.ResultSet result,
boolean onlyMetadata,
boolean withBinaries)
Basing on the Joty protocol this method builds the xml code corresponding
to the result received in input and destined to be returned to the client
|
protected void |
getStmntItems(org.w3c.dom.Node currNode,
org.joty.access.PostStatement stnmt)
From the xml node received in input this method extracts the list of
Item objects to be assigned to the BasicPostStatement.m_items
member. |
protected java.lang.String |
getXmlFromDb(java.lang.String sqlText,
boolean onlyMetadata,
boolean withBinaries)
Executes the sql statetement received in input and encodes the derived
result set in xml code, basing on the Joty protocol.
|
protected java.lang.String |
idSqlSubst(java.lang.String stmnt)
Replaces any numbered place holder occurrence with the corresponding element in the vector
m_returnedValues |
void |
init()
Executed once, it performs initialization of the JotyServlet instance:
|
boolean |
isDesignTime() |
void |
jotyMessage(java.lang.Exception e) |
void |
jotyMessage(java.lang.String text) |
void |
jotyMessage(java.lang.Throwable t) |
void |
jotyWarning(java.lang.String text) |
protected org.joty.access.BirtManager |
reportManager() |
protected boolean |
rollback() |
protected void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected java.lang.String |
singleByteEncoding() |
protected java.lang.String |
xmlEncodeBinaryContent(java.lang.String binaryContent) |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
protected java.sql.Connection m_conn
protected java.lang.String m_command
protected java.util.Vector<org.joty.access.PostStatement> m_postStatements
protected org.joty.access.PostStatement m_queryDefPostStatement
protected java.util.Vector<byte[]> m_bytesElems
protected boolean m_success
protected org.joty.common.ErrorCarrier m_errorCarrier
protected java.util.Vector<java.lang.String> m_returnedValues
dbExecute()
protected org.joty.common.ConfigFile m_configuration
protected org.joty.common.ConfigFile m_serverConfig
protected java.lang.String m_singleByteEncoding
protected boolean m_logDbActions
protected org.joty.common.XmlTextEncoder m_xmlEncoder
protected boolean m_debug
protected java.lang.String m_dbLogName
protected boolean m_use_BIRT
protected org.joty.access.BirtManager m_BirtManager
protected org.joty.access.Accessor m_accessor
protected boolean m_remoteAccessor
protected org.joty.common.ParamContext m_queryDefParamContext
protected org.joty.access.DbManager.DbConnectionGrabber m_connGrabber
protected org.joty.access.MethodExecutor m_methodExecutor
protected boolean m_msSqlServer
protected boolean attributePredicate(javax.servlet.http.HttpServletRequest request, java.lang.String attr, boolean defTruth)
protected void beginTrans() throws java.sql.SQLException, javax.naming.NamingException
java.sql.SQLException
javax.naming.NamingException
protected java.lang.String buildXmlResult()
m_returnedValues
member in a convenient xml structure.dbExecute()
,
m_returnedValues
protected boolean checkCredentials(javax.servlet.http.HttpServletRequest request, java.lang.String command, boolean sessionIsALive) throws java.io.IOException
java.io.IOException
protected boolean checkRequestPostContent(java.lang.String postedContent)
protected boolean commit()
protected void dbExecute() throws java.sql.SQLException, javax.naming.NamingException
m_postStatements
member either the transaction is the case or a
single statement is to be executed. For each PostStatement object found
in the vector, it calls
Accessor.setPostStatement(PostStatement, boolean)
by means of
which the ParamContext instance used by the Accessor object is fed with
new ContextParam objects extracted by the set of Item objects.
If the m_method
member has a value the
MethodExecutor#exec(BasicPostStatement, Boolean, Connection)
is
invoked.
If the m_sql
member has a value executeSql
is called
after the sql text could have been transformed either by a literal
substitution or by the substitutions of every numbered 'gen-id' place
holders with their respective Id instances previously generated upon
the execution of preceding BasicPostStatement objects in the same call of this
method ;
In all other case suitable actions take place; these cases manage old features of the previous version of Joty that have been made surviving.
java.sql.SQLException
javax.naming.NamingException
MethodExecutor
,
executeSql(String)
,
PostStatement.nameSubst(Accessor, String)
,
idSqlSubst(String)
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
getPostedBodyElements
for loading into convenient structures the data present in the request
body.
then, again depending on the particular Joty web command, the task is dispatched to other serving methods to be accomplished.
If the application works in 'Accessor mode' and the application
Accessor
object lives on the server side this object is used
either for picking the effective statements up in order to be executed or to apply
literals substitution on the statements coming from the request.
doPost
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
getPostedBodyElements(java.lang.String)
,
getXmlFromDb(java.lang.String, boolean, boolean)
,
getResponseFromLogin(java.lang.String, java.lang.String, java.lang.String)
,
getReportXml(java.lang.String, java.lang.String, java.lang.String, boolean)
,
dbExecute()
,
Accessor
protected java.lang.String encodedBytes()
protected void endTrans()
protected boolean executeSql(java.lang.String sql)
sql
- the statement textexecuteStmnt(java.lang.String)
protected java.lang.Boolean executeStmnt(java.lang.String sql) throws javax.naming.NamingException
executeSql
in executing an sql statement.
As it can be noted currently the method manages only binary writing if
the m_bytesElems
vector is not empty. This is not a limitation
because in Joty 2.0 still a writing of a large blob object is managed in
a dedicated way and now, at most, is accompanied by the writing of a
small blob object. That is, it is never embedded in a transaction set of
statements composed by sql of various nature.
In the other case the method manages statement execution that either
infers value generation for the field indicated by the m_autoId
member or not.
sql
- the statement textjavax.naming.NamingException
org.joty.workstation.gui.ImageComponent
protected java.lang.String getNodeValue(org.w3c.dom.Node node, java.lang.String name)
protected java.lang.String getPostedContent(javax.servlet.http.HttpServletRequest request)
request
- protected java.lang.String getReportXml(java.lang.String reportName, java.lang.String formatType, java.lang.String language, boolean twoProcesses)
On failure the output of the call to getResultFromFailure
is
returned instead.
For the meaning of the parameters here not documented see
BirtManager.buildReport(String, String, boolean)
method.
reportName
- formatType
- language
- the language so that the suitable report design folder is
chosen as input context.twoProcesses
- BirtManager
protected java.lang.String getResponseFromLogin(java.lang.String user, java.lang.String pwd, java.lang.String query) throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String getResultFromException(java.lang.Exception e)
protected java.lang.String getResultFromFailure(java.lang.String msg)
protected java.lang.String getResultFromFailure(java.lang.String msg, java.lang.String code)
protected java.lang.String getResultSetAsXml(java.sql.ResultSet result, boolean onlyMetadata, boolean withBinaries) throws java.sql.SQLException
result
- the ResultSet object to be encoded in Joty response.onlyMetadata
- if true only the 'Structure' xml node is returned (the
response will contain only the description of the fields o the
result set)withBinaries
- if true the binary content of the possible fields of type
JotyTypes._smallBlobs
is includedjava.sql.SQLException
protected void getStmntItems(org.w3c.dom.Node currNode, org.joty.access.PostStatement stnmt)
Item
objects to be assigned to the BasicPostStatement.m_items
member.currNode
- the source xml node-stnmt
- the target PostStatement object-BasicPostStatement.Item
protected java.lang.String getXmlFromDb(java.lang.String sqlText, boolean onlyMetadata, boolean withBinaries)
sqlText
- input sql code.onlyMetadata
- see getResultSetAsXml
withBinaries
- " "getResultSetAsXml(java.sql.ResultSet, boolean, boolean)
protected java.lang.String idSqlSubst(java.lang.String stmnt)
m_returnedValues
stmnt
- the sql statementpublic void init() throws javax.servlet.ServletException
creates server logs, loads configuration content from two different configuration file 'ServerSideJoty.xml' and 'JotyServe.xml', either to be used on the server side or to be dispatched to the client, loads all the language vectors in order to serve any different language request, load the proper jdbc driver and prepares it for connections.
If the configuration 'remoteAccessor' item is true the method
instantiates the application Accessor
object.
On the success of the previously described activities, at last, it creates the
MethodExecutor
, the ReportManager
and the
BirtManager
objects (the latter only if the configuration
'use_BIRT_engine' item is true)
The method, also, instantiate a DbConnectionGrabber
object the
methods of which are used along the whole life of the
servlet .
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
ConfigFile
,
MethodExecutor
,
ReportManager
,
BirtManager
,
DbManager.DbConnectionGrabber
protected org.joty.access.BirtManager reportManager()
protected boolean rollback()
protected void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
protected java.lang.String singleByteEncoding()
protected java.lang.String xmlEncodeBinaryContent(java.lang.String binaryContent) throws java.lang.Exception
java.lang.Exception
public void jotyWarning(java.lang.String text)
jotyWarning
in interface org.joty.common.JotyMessenger
public void jotyMessage(java.lang.String text)
jotyMessage
in interface org.joty.common.JotyMessenger
public void jotyMessage(java.lang.Throwable t)
jotyMessage
in interface org.joty.common.JotyMessenger
public void jotyMessage(java.lang.Exception e)
jotyMessage
in interface org.joty.common.JotyMessenger
public void ASSERT(boolean predicate)
ASSERT
in interface org.joty.common.JotyMessenger
public boolean isDesignTime()
isDesignTime
in interface org.joty.common.JotyMessenger
public void afterReportRender(java.lang.String arg0)
afterReportRender
in interface org.joty.common.JotyMessenger
public void beforeReportRender()
beforeReportRender
in interface org.joty.common.JotyMessenger