Search in sources :

Example 1 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method sendRestfulMessage.

private String sendRestfulMessage(String mdwWebUrl, String message, Map<String, String> headers) throws DataAccessException {
    try {
        HttpHelper httpHelper = currentServer.getHttpHelper(mdwWebUrl + "/Services/REST");
        httpHelper.setConnectTimeout(getConnectTimeout());
        httpHelper.setReadTimeout(getReadTimeout());
        httpHelper.setHeaders(headers);
        String res = httpHelper.post(message);
        return res == null ? null : res.trim();
    } catch (IOException ex) {
        throw new DataAccessException(0, IOEXCEPTION, ex);
    }
}
Also used : IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 2 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method sendSoapMessage.

private String sendSoapMessage(String mdwWebUrl, String message, Map<String, String> headers) throws DataAccessException {
    try {
        HttpHelper httpHelper = currentServer.getHttpHelper(mdwWebUrl + "/Services/SOAP");
        httpHelper.setHeaders(headers);
        httpHelper.setConnectTimeout(getConnectTimeout());
        httpHelper.setReadTimeout(getReadTimeout());
        String res = httpHelper.post(message);
        return res == null ? null : res.trim();
    } catch (IOException ex) {
        throw new DataAccessException(0, IOEXCEPTION, ex);
    }
}
Also used : IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 3 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method executeUnitTest.

public String executeUnitTest(String message, Map<String, String> headers) throws DataAccessException {
    try {
        HttpHelper httpHelper = currentServer.getHttpHelper(currentServer.getMdwWebUrl() + "/Services/com/centurylink/mdw/testing/AutomatedTests/unit");
        httpHelper.setConnectTimeout(getConnectTimeout());
        httpHelper.setReadTimeout(getReadTimeout());
        httpHelper.setHeaders(headers);
        String res = httpHelper.post(message);
        return res == null ? null : res.trim();
    } catch (IOException ex) {
        throw new DataAccessException(0, IOEXCEPTION, ex);
    }
}
Also used : IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 4 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class Importer method main.

public static void main(String[] args) {
    if (args.length == 1 && "-h".equals(args[0])) {
        System.out.println("Example Usage: ");
        System.out.println("java com.centurylink.mdw.designer.Importer appcuid apppassword " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "http://lxdenvmtc143.dev.qintra.com:7021/maven/repository/mdw/com/centurylink/mdw/assets/camel/5.5.11/com.centurylink.mdw.camel-5.5.11.xml " + "overwrite=true");
        System.exit(0);
    }
    if (args.length != 4 && args.length != 5) {
        System.err.println("arguments: <user> <password> <jdbcUrl|fileBasedRootDir> <xmlFile|xmlFileUrl> <overwrite=(true|FALSE)>");
        System.err.println("(-h for example usage)");
        System.exit(-1);
    }
    String user = args[0];
    String password = args[1];
    // either jdbcUrl or local file path
    String arg2 = args[2];
    String xmlFile = args[3];
    boolean overwrite = (args.length == 5 && "overwrite=true".equalsIgnoreCase(args[4])) ? true : false;
    try {
        DesignerDataAccess.getAuthenticator().authenticate(user, password);
        boolean local = !arg2.startsWith("jdbc:");
        RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg2, user, "http://dummy");
        DesignerDataAccess dataAccess;
        if (local) {
            VersionControl versionControl = new VersionControlGit();
            versionControl.connect(null, null, null, new File(arg2));
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(new File(arg2));
            dataAccess = new DesignerDataAccess(restfulServer, null, user, false);
        } else {
            dataAccess = new DesignerDataAccess(restfulServer, null, user, true);
            UserVO userVO = dataAccess.getUser(user);
            if (userVO == null)
                throw new DataAccessException("User: '" + user + "' not found.");
            if (!userVO.hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN))
                throw new DataAccessException("User: '" + user + "' not authorized for " + UserRoleVO.PROCESS_DESIGN + ".");
        }
        String xml;
        if ("http://".startsWith(xmlFile) || "https://".startsWith(xmlFile)) {
            xml = new HttpHelper(new URL(xmlFile)).get();
        } else {
            xml = readFile(xmlFile);
        }
        System.out.println("Importing with arguments: " + user + " ******* " + arg2 + " " + xmlFile);
        Importer importer = new Importer(dataAccess);
        long before = System.currentTimeMillis();
        importer.importPackage(xml, overwrite);
        long afterImport = System.currentTimeMillis();
        System.out.println("Time taken for import: " + ((afterImport - before) / 1000) + " s");
        System.out.println("Please restart your server or refresh the MDW asset cache.");
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) URL(java.net.URL) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) XmlException(org.apache.xmlbeans.XmlException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) UserVO(com.centurylink.mdw.model.value.user.UserVO) File(java.io.File) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter)

Example 5 with HttpHelper

use of com.centurylink.mdw.common.utilities.HttpHelper in project mdw-designer by CenturyLinkCloud.

the class NotificationChecker method checkNotices.

private String checkNotices() {
    taskInstanceId = null;
    String msg = null;
    try {
        String urlStr = workflowProject.getServiceUrl() + "/Services/TaskActions?user=" + workflowProject.getUser().getUsername() + "&since=" + URLEncoder.encode(StringHelper.dateToString(lastResult), "utf-8") + "&max=" + MAX_NOTICES + "&format=json";
        HttpHelper httpHelper = workflowProject.getHttpHelper(urlStr);
        httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
        httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
        String response = new String(httpHelper.get());
        JSONArray actions = new JSONArray(response);
        // String[0]), lastResult);
        if (actions.length() > 0) {
            msg = "";
            UserActionVO firstAction = new UserActionVO(actions.getJSONObject(0));
            if (actions.length() == 1) {
                taskInstanceId = firstAction.getEntityId();
                msg += messageLine(firstAction);
            } else {
                for (int i = 0; i < actions.length(); i++) {
                    JSONObject action = actions.getJSONObject(i);
                    msg += messageLine(new UserActionVO(action));
                }
            }
            lastResult = firstAction.getRetrieveDate();
        }
        if (lastResult == null)
            // fall back to device time
            lastResult = new Date();
        String lastResultStr = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(lastResult);
        workflowProject.setPersistentProperty(NotificationChecker.NOTIF_CHECK_LAST_RESULT_KEY, lastResultStr);
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Check Notices", workflowProject);
    }
    return msg;
}
Also used : UserActionVO(com.centurylink.mdw.model.value.user.UserActionVO) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Aggregations

HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)21 IOException (java.io.IOException)17 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)10 URL (java.net.URL)9 JSONException (org.json.JSONException)6 XmlException (org.apache.xmlbeans.XmlException)5 SocketTimeoutException (java.net.SocketTimeoutException)4 RemoteException (java.rmi.RemoteException)4 JSONObject (org.json.JSONObject)4 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)3 MDWStatusMessageDocument (com.centurylink.mdw.bpm.MDWStatusMessageDocument)3 HashMap (java.util.HashMap)3 CoreException (org.eclipse.core.runtime.CoreException)3 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 AppSummary (com.centurylink.mdw.designer.model.AppSummary)2 DesignerHttpHelper (com.centurylink.mdw.designer.utils.DesignerHttpHelper)2 File (com.centurylink.mdw.plugin.designer.model.File)2 FileNotFoundException (java.io.FileNotFoundException)2 GeneralSecurityException (java.security.GeneralSecurityException)2