Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Open Web Page action, some URL were not displayed #2991

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*******************************************************************************/
package org.csstudio.display.builder.model.util;

import static org.csstudio.display.builder.model.ModelPlugin.logger;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -24,6 +22,7 @@
import java.nio.file.Paths;
import java.time.Duration;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.csstudio.display.builder.model.DisplayModel;
import org.csstudio.display.builder.model.ModelPlugin;
Expand All @@ -37,6 +36,7 @@
@SuppressWarnings("nls")
public class ModelResourceUtil
{
public final static Logger logger = Logger.getLogger(ModelResourceUtil.class.getPackageName());
/** Schema used for the built-in display examples */
public static final String EXAMPLES_SCHEMA = "examples";

Expand Down Expand Up @@ -309,49 +309,57 @@ private static String doResolveResource(final String parent_display, final Strin
*/
private static boolean canOpenUrl(final String resource_name)
{
boolean canOpenUrl = false;
final URL example = getExampleURL(resource_name);
if (example != null)
{
try
{
example.openStream().close();
return true;
canOpenUrl = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the handling of example:... URLs?

Copy link
Contributor Author

@Mathis-Hu Mathis-Hu Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using a flag for code coverage, but I can get back to original code if it's an issue

}
catch (Exception ex)
{
return false;
logger.log(Level.SEVERE, "URL cannot open " + resource_name , ex);
}
}

if (! isURL(resource_name))
return false;
// This implementation is expensive:
// On success, caller will soon open the URL again.
// In practice, not too bad because second time around
// is usually quite fast as result of web server cache.
//
// Alternative would be to always return the stream as
// a result, updating all callers from
//
// resolved = ModelResourceUtil.resolveResource(parent_display, display_file);
// stream = ModelResourceUtil.openResourceStream(resolved)
//
// to just
//
// stream = ModelResourceUtil.resolveResource(parent_display, display_file);
//
// This can break code which really just needs the resolved name.
if (isURL(resource_name)) {
// This implementation is expensive:
// On success, caller will soon open the URL again.
// In practice, not too bad because second time around
// is usually quite fast as result of web server cache.
//
// Alternative would be to always return the stream as
// a result, updating all callers from
//
// resolved = ModelResourceUtil.resolveResource(parent_display, display_file);
// stream = ModelResourceUtil.openResourceStream(resolved)
//
// to just
//
// stream = ModelResourceUtil.resolveResource(parent_display, display_file);
//
// This can break code which really just needs the resolved name.

try
{
final InputStream stream = openURL(resource_name);
stream.close();
return true;
}
catch (Exception ex)
{
return false;
try
{
//In case of https an authentication is request
//It sends an Exception Connection refused:
//Use openConnection instead of openStream
//Stream is not OK for a https
URL url = new URL(resource_name);
url.openConnection();
canOpenUrl = true;
}
catch (Exception ex)
{
ex.printStackTrace();
logger.log(Level.SEVERE, "URL cannot open " + resource_name , ex);
}
}

return canOpenUrl;
}

/** Check for "examples:.."
Expand Down
Loading