Search in sources :

Example 1 with AppServiceHeader

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);
}
Also used : MimeHeaders(javax.xml.soap.MimeHeaders) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader)

Example 2 with AppServiceHeader

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();
}
Also used : IFactoryAppService(org.cerberus.crud.factory.IFactoryAppService) AppService(org.cerberus.crud.entity.AppService) MessageEvent(org.cerberus.engine.entity.MessageEvent) IAppServiceHeaderService(org.cerberus.crud.service.IAppServiceHeaderService) JSONArray(org.json.JSONArray) IFactoryAppServiceContent(org.cerberus.crud.factory.IFactoryAppServiceContent) AppServiceContent(org.cerberus.crud.entity.AppServiceContent) ArrayList(java.util.ArrayList) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader) IAppServiceService(org.cerberus.crud.service.IAppServiceService) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) Answer(org.cerberus.util.answer.Answer) IFactoryAppService(org.cerberus.crud.factory.IFactoryAppService) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) IAppServiceContentService(org.cerberus.crud.service.IAppServiceContentService) IFactoryAppServiceContent(org.cerberus.crud.factory.IFactoryAppServiceContent) ILogEventService(org.cerberus.crud.service.ILogEventService)

Example 3 with AppServiceHeader

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;
}
Also used : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FactoryAppServiceHeader(org.cerberus.crud.factory.impl.FactoryAppServiceHeader) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 4 with AppServiceHeader

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;
}
Also used : AppService(org.cerberus.crud.entity.AppService) IFactoryAppService(org.cerberus.crud.factory.IFactoryAppService) AppServiceContent(org.cerberus.crud.entity.AppServiceContent) ArrayList(java.util.ArrayList) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader)

Example 5 with AppServiceHeader

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;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) IFactoryAppServiceHeader(org.cerberus.crud.factory.IFactoryAppServiceHeader) AppServiceHeader(org.cerberus.crud.entity.AppServiceHeader)

Aggregations

AppServiceHeader (org.cerberus.crud.entity.AppServiceHeader)14 IFactoryAppServiceHeader (org.cerberus.crud.factory.IFactoryAppServiceHeader)10 ArrayList (java.util.ArrayList)9 MessageEvent (org.cerberus.engine.entity.MessageEvent)7 AppService (org.cerberus.crud.entity.AppService)6 AppServiceContent (org.cerberus.crud.entity.AppServiceContent)6 AnswerItem (org.cerberus.util.answer.AnswerItem)5 IFactoryAppService (org.cerberus.crud.factory.IFactoryAppService)4 JSONObject (org.json.JSONObject)4 CerberusException (org.cerberus.exception.CerberusException)3 Answer (org.cerberus.util.answer.Answer)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 AnswerList (org.cerberus.util.answer.AnswerList)2 IOException (java.io.IOException)1