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);
}
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;
}
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);
}
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);
}
}
}
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(" "))
content = content.replaceAll(" ", "").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);
}
}
}
Aggregations