use of org.cerberus.crud.entity.AppServiceHeader in project cerberus-source by cerberustesting.
the class SoapService method createSoapRequest.
@Override
public SOAPMessage createSoapRequest(String envelope, String method, List<AppServiceHeader> header, String token) throws SOAPException, IOException, SAXException, ParserConfigurationException {
String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);
boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();
MimeHeaders headers = new MimeHeaders();
for (AppServiceHeader appServiceHeader : header) {
headers.addHeader(appServiceHeader.getKey(), appServiceHeader.getValue());
}
InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8"));
MessageFactory messageFactory = MessageFactory.newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL);
return messageFactory.createMessage(headers, input);
}
use of org.cerberus.crud.entity.AppServiceHeader in project cerberus-source by cerberustesting.
the class CreateAppService method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
final void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
JSONObject jsonResponse = new JSONObject();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
response.setContentType("text/html;charset=UTF-8");
String charset = request.getCharacterEncoding();
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
// Parameter that needs to be secured --> We SECURE+DECODE them
String service = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("service"), null, charset);
String group = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("group"), "", charset);
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
String attachementurl = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("attachementurl"), "", charset);
String operation = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("operation"), "", charset);
String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), null, charset);
String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), "", charset);
String method = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("method"), "", charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String servicePath = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("servicePath"), "", charset);
String serviceRequest = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("serviceRequest"), null, charset);
// Prepare the final answer.
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(service)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "SoapLibrary").replace("%OPERATION%", "Create").replace("%REASON%", "SoapLibrary name is missing!"));
finalAnswer.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
appServiceService = appContext.getBean(IAppServiceService.class);
appServiceFactory = appContext.getBean(IFactoryAppService.class);
appServiceHeaderService = appContext.getBean(IAppServiceHeaderService.class);
appServiceContentService = appContext.getBean(IAppServiceContentService.class);
appServiceContentFactory = appContext.getBean(IFactoryAppServiceContent.class);
appServiceHeaderFactory = appContext.getBean(IFactoryAppServiceHeader.class);
AppService appService = appServiceFactory.create(service, type, method, application, group, serviceRequest, description, servicePath, attachementurl, operation, request.getRemoteUser(), null, null, null);
ans = appServiceService.create(appService);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPrivateCalls("/CreateAppService", "CREATE", "Create AppService : " + service, request);
}
// Update content
if (request.getParameter("contentList") != null) {
JSONArray objContentArray = new JSONArray(request.getParameter("contentList"));
List<AppServiceContent> contentList = new ArrayList();
contentList = getContentListFromRequest(request, appContext, service, objContentArray);
// Update the Database with the new list.
ans = appServiceContentService.compareListAndUpdateInsertDeleteElements(service, contentList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
// Update header
if (request.getParameter("headerList") != null) {
JSONArray objHeaderArray = new JSONArray(request.getParameter("headerList"));
List<AppServiceHeader> headerList = new ArrayList();
headerList = getHeaderListFromRequest(request, appContext, service, objHeaderArray);
// Update the Database with the new list.
ans = appServiceHeaderService.compareListAndUpdateInsertDeleteElements(service, headerList);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.entity.AppServiceHeader in project cerberus-source by cerberustesting.
the class AppServiceHeaderDAO method readByKey.
@Override
public AnswerItem<AppServiceHeader> readByKey(String service, String key) {
AnswerItem ans = new AnswerItem();
AppServiceHeader result = null;
final String query = "SELECT * FROM `appserviceheader` srh WHERE `service` = ? and `key` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.service : " + service);
LOG.debug("SQL.param.key : " + key);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, service);
preStat.setString(1, key);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.crud.entity.AppServiceHeader in project cerberus-source by cerberustesting.
the class FactoryAppService method create.
@Override
public AppService create(String service, String type, String method, String application, String group, String serviceRequest, String description, String servicePath, String attachementURL, String operation, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif) {
AppService s = new AppService();
s.setService(service);
s.setServiceRequest(serviceRequest);
s.setGroup(group);
s.setDescription(description);
s.setServicePath(servicePath);
s.setAttachementURL(attachementURL);
s.setOperation(operation);
s.setMethod(method);
s.setApplication(application);
s.setType(type);
s.setUsrCreated(usrCreated);
s.setUsrModif(usrModif);
s.setDateCreated(dateCreated);
s.setDateModif(dateModif);
List<AppServiceContent> objectContentList = new ArrayList<>();
s.setContentList(objectContentList);
List<AppServiceHeader> objectHeaderList = new ArrayList<>();
s.setHeaderList(objectHeaderList);
List<AppServiceHeader> objectResponseHeaderList = new ArrayList<>();
s.setResponseHeaderList(objectResponseHeaderList);
return s;
}
use of org.cerberus.crud.entity.AppServiceHeader in project cerberus-source by cerberustesting.
the class UpdateAppService method getHeaderListFromRequest.
private List<AppServiceHeader> getHeaderListFromRequest(HttpServletRequest request, ApplicationContext appContext, String service, JSONArray json) throws CerberusException, JSONException, UnsupportedEncodingException {
List<AppServiceHeader> headerList = new ArrayList();
for (int i = 0; i < json.length(); i++) {
JSONObject objectJson = json.getJSONObject(i);
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
boolean delete = objectJson.getBoolean("toDelete");
int sort = objectJson.getInt("sort");
String key = objectJson.getString("key");
String value = objectJson.getString("value");
String active = objectJson.getString("active");
String description = objectJson.getString("description");
if (!delete) {
headerList.add(appServiceHeaderFactory.create(service, key, value, active, sort, description, request.getRemoteUser(), null, request.getRemoteUser(), null));
}
}
return headerList;
}
Aggregations