{"record":{"id":"9299ec6953c6f711","repo":"jeecgboot/JeecgBoot","slug":"url-http-https-9299ec","errorCode":null,"errorMessage":"网页URL格式不正确，请以http://或https://开头","messagePattern":"网页URL格式不正确，请以http://或https://开头","errorType":"validation","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/EmbeddingHandler.java","lineNumber":773,"sourceCode":"    }\n\n    /**\n     * 解析网页内容，使用Jsoup爬取并转换为Markdown\n     *\n     * @param doc 知识库文档（metadata中需包含website字段）\n     * @return Markdown格式的网页内容\n     * @date 2026/3/19\n     */\n    private String parseWebPage(AiragKnowledgeDoc doc) {\n        String metadata = doc.getMetadata();\n        AssertUtils.assertNotEmpty(\"请先配置网页URL\", metadata);\n        JSONObject metadataJson = JSONObject.parseObject(metadata);\n        String website = metadataJson.getString(LLMConsts.KNOWLEDGE_DOC_METADATA_WEBSITE);\n        AssertUtils.assertNotEmpty(\"请先配置网页URL\", website);\n\n        Matcher matcher = LLMConsts.WEB_PATTERN.matcher(website);\n        if (!matcher.matches()) {\n            throw new JeecgBootException(\"网页URL格式不正确，请以http://或https://开头\");\n        }\n\n        try {\n            WebPageParser webPageParser = new WebPageParser();\n            String content = webPageParser.parseToMarkdown(website);\n            if (oConvertUtils.isEmpty(content)) {\n                throw new JeecgBootException(\"网页内容为空，请检查URL是否可访问\");\n            }\n            log.info(\"网页解析成功, URL: {}, 内容长度: {}\", website, content.length());\n            return content;\n        } catch (JeecgBootException e) {\n            throw e;\n        } catch (Exception e) {\n            log.error(\"网页解析失败, URL: {}, 错误: {}\", website, e.getMessage(), e);\n            throw new JeecgBootException(\"网页解析失败: \" + e.getMessage());\n        }\n    }\n","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/EmbeddingHandler.java#L755-L791","documentation":"Thrown by EmbeddingHandler.parseWebPage() when the website URL from document metadata does not match LLMConsts.WEB_PATTERN, which is the regex ^(http|https)://.* — requiring the URL to start with http:// or https://. This is a format validation before attempting to fetch and parse the web page.","triggerScenarios":"A knowledge-base document of web-page type whose metadata JSON 'website' field does not begin with 'http://' or 'https://'. For example: 'ftp://example.com', 'www.example.com', 'example.com/page', or a URL with a leading space.","commonSituations":"User enters a URL without the protocol prefix (e.g. 'www.example.com' instead of 'https://www.example.com'); the metadata field was populated programmatically without protocol normalization; trailing/leading whitespace prevents the regex match.","solutions":["Ensure the website URL in the document metadata starts with 'http://' or 'https://'.","If building the metadata programmatically, prepend 'https://' when the protocol is missing.","Trim whitespace from the URL before storing it in metadata."],"exampleFix":"// before\nString website = \"www.example.com/page\"; // stored in metadata\n\n// after\nString website = \"www.example.com/page\";\nif (!website.startsWith(\"http://\") && !website.startsWith(\"https://\")) {\n    website = \"https://\" + website;\n}\nmetadataJson.put(LLMConsts.KNOWLEDGE_DOC_METADATA_WEBSITE, website);","handlingStrategy":"validation","validationCode":"if (website == null || (!website.startsWith(\"http://\") && !website.startsWith(\"https://\"))) {\n    throw new JeecgBootException(\"网页URL必须以http://或https://开头\");\n}","typeGuard":"private static boolean isValidWebUrl(String url) {\n    return url != null && Pattern.compile(\"^(http|https)://.*\").matcher(url).matcher(url).matches();\n}","tryCatchPattern":null,"preventionTips":["Always prepend 'https://' to URLs missing a protocol before storing in metadata.","Trim whitespace from URLs before validation.","Use URL-based input validation at the frontend to enforce protocol prefix."],"tags":["validation","url","web-parsing","rag"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}