Search in sources :

Example 6 with HttpHelper

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

the class RestfulServer method post.

public String post(String path, String request) throws IOException {
    String url = getServiceUrl();
    if (path != null)
        url += "/" + path;
    HttpHelper httpHelper = getHttpHelper(url);
    httpHelper.setConnectTimeout(getConnectTimeout());
    httpHelper.setReadTimeout(getReadTimeout());
    return httpHelper.post(request);
}
Also used : HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper)

Example 7 with HttpHelper

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

the class RestfulServer method invokeResourceService.

public String invokeResourceService(String path) throws DataAccessException, IOException {
    String url = getMdwWebUrl() + (path.startsWith("/") ? "Services/" + path : "/Services/" + path);
    String response = null;
    try {
        HttpHelper httpHelper = getHttpHelper(url);
        httpHelper.setConnectTimeout(getConnectTimeout());
        httpHelper.setReadTimeout(getReadTimeout());
        response = httpHelper.get();
    } catch (SocketTimeoutException ex) {
        throw new IOException("Timeout after " + getReadTimeout() + " ms", ex);
    } catch (FileNotFoundException ex) {
        throw ex;
    } catch (IOException ex) {
        throw new IOException("Unable to connect to " + getMdwWebUrl(), ex);
    }
    if (response != null && (response.trim().startsWith("<xs:MDWStatusMessage") || response.trim().startsWith("<bpm:MDWStatusMessage"))) {
        try {
            MDWStatusMessageDocument msgDoc = MDWStatusMessageDocument.Factory.parse(response, Compatibility.namespaceOptions());
            throw new DataAccessException(msgDoc.getMDWStatusMessage().getStatusMessage());
        } catch (Exception ex) {
            throw new DataAccessException(-1, response, ex);
        }
    }
    return response;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) FileNotFoundException(java.io.FileNotFoundException) MDWStatusMessageDocument(com.centurylink.mdw.bpm.MDWStatusMessageDocument) IOException(java.io.IOException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) JSONException(org.json.JSONException) SocketTimeoutException(java.net.SocketTimeoutException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) XmlException(org.apache.xmlbeans.XmlException)

Example 8 with HttpHelper

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

the class RestfulServer method delete.

public String delete(String path, String request) throws IOException {
    String url = getServiceUrl();
    if (path != null)
        url += "/" + path;
    HttpHelper httpHelper = getHttpHelper(url);
    httpHelper.setConnectTimeout(getConnectTimeout());
    httpHelper.setReadTimeout(getReadTimeout());
    return httpHelper.delete(request);
}
Also used : HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper)

Example 9 with HttpHelper

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

the class RestfulServer method launchSynchronousProcess.

public String launchSynchronousProcess(Long processId, String masterRequestId, String owner, Long ownerId, Map<VariableVO, String> variables, String responseVarName, boolean oldFormat) throws XmlException, JSONException, IOException {
    if (isSchemaVersion61()) {
        return launchProcess(processId, masterRequestId, owner, ownerId, variables);
    } else {
        ActionRequestDocument actionRequestDoc = getLaunchProcessBaseDoc(processId, masterRequestId, owner, ownerId);
        Parameter syncParam = actionRequestDoc.getActionRequest().getAction().addNewParameter();
        syncParam.setName("mdw.Synchronous");
        syncParam.setStringValue("true");
        Parameter responseVarParam = actionRequestDoc.getActionRequest().getAction().addNewParameter();
        responseVarParam.setName("mdw.ResponseVariableName");
        responseVarParam.setStringValue(responseVarName);
        for (VariableVO variableVO : variables.keySet()) {
            Parameter parameter = actionRequestDoc.getActionRequest().getAction().addNewParameter();
            parameter.setName(variableVO.getVariableName());
            parameter.setType(variableVO.getVariableType());
            String stringValue = variables.get(variableVO);
            parameter.setStringValue(stringValue);
        }
        try {
            HttpHelper httpHelper = getHttpHelper(getMdwWebUrl() + "/Services/REST");
            httpHelper.setConnectTimeout(getConnectTimeout());
            httpHelper.setReadTimeout(getReadTimeout());
            String request;
            if (oldFormat)
                request = DesignerCompatibility.getInstance().getOldActionRequest(actionRequestDoc);
            else
                request = actionRequestDoc.xmlText(getXmlOptions());
            return httpHelper.post(request);
        } catch (SocketTimeoutException ex) {
            throw new RemoteException("Timeout after " + getReadTimeout() + " ms", ex);
        } catch (IOException ex) {
            throw new RemoteException("Unable to connect to " + getMdwWebUrl(), ex);
        }
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Parameter(com.centurylink.mdw.service.Parameter) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) ActionRequestDocument(com.centurylink.mdw.service.ActionRequestDocument)

Example 10 with HttpHelper

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

the class Discoverer method crawlForPackageFiles.

/**
 * Crawls to find any package XML or JSON files.
 */
private void crawlForPackageFiles(Folder parent) throws DiscoveryException, IOException, InterruptedException {
    if (progressMonitor.isCanceled())
        throw new InterruptedException();
    String parentUrl = getFullUrl(parent);
    if (httpHelper == null)
        httpHelper = new HttpHelper(new URL(parentUrl));
    httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
    httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
    if (// topLevel
    !parent.hasParent())
        httpHelper.setFollowHtmlHeadMetaRefresh(true);
    String content = httpHelper.get();
    if (content.startsWith("{")) {
        parseJsonPacakges(parent, content);
    } else {
        if (content.startsWith("<!"))
            content = content.substring(content.indexOf('\n') + 1);
        if (content.contains("&nbsp;"))
            content = content.replaceAll("&nbsp;", "").replace("<HR size=\"1\" noshade=\"noshade\">", "");
        if (!parent.hasParent() && httpHelper.getRedirect() != null)
            parent.setName(httpHelper.getRedirect().toString());
        try {
            List<String> links = parseDirectoryResponse(content);
            if (!parent.hasParent())
                topLevelFolders = links.size();
            if (latestVersionsOnly) {
                List<String> latestLinks = new ArrayList<>();
                String latestDir = null;
                for (String link : links) {
                    if (// snapshots excluded from
                    !link.startsWith("6") && !link.endsWith("-SNAPSHOT/")) // "latest only"
                    {
                        if (link.matches("[0-9.]*/")) {
                            if ((latestDir == null || latestDir.compareTo(link) < 0))
                                latestDir = link;
                        } else {
                            latestLinks.add(link);
                        }
                    }
                }
                if (latestDir != null)
                    latestLinks.add(latestDir);
                links = latestLinks;
            }
            for (String link : links) {
                if (!link.startsWith("6") && link.endsWith("/") && (MdwPlugin.getSettings().isIncludePreviewBuilds() || !link.endsWith("-SNAPSHOT/"))) {
                    // directory
                    if (!parent.hasParent())
                        progressMonitor.subTask("Scanning " + link);
                    Folder child = new Folder(link.substring(0, link.length() - 1));
                    if (link.matches("[0-9.]*/"))
                        parent.addChild(0, child);
                    else
                        parent.addChild(child);
                    httpHelper = null;
                    crawlForPackageFiles(child);
                    if (// topLevel
                    !parent.hasParent())
                        progressMonitor.worked(80 / topLevelFolders);
                } else if (link.endsWith(".xml") || link.endsWith(".json")) {
                    // XML or JSON file
                    File child = new File(parent, link);
                    parent.addChild(0, child);
                    child.setUrl(new URL(getFullUrl(child)));
                }
            }
        } catch (InterruptedException iex) {
            throw iex;
        } catch (Exception ex) {
            throw new DiscoveryException("Error crawling: " + parentUrl, ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Folder(com.centurylink.mdw.plugin.designer.model.Folder) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) File(com.centurylink.mdw.plugin.designer.model.File) URL(java.net.URL) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

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