Source:
<code>public void execute(CommandLineArgument[] args) { if (arguments[ARG_IMPORT_FILE_IDX].isEnabled() || arguments[ARG_IMPORT_URL_IDX].isEnabled()) { if (!arguments[ARG_END_URL_IDX].isEnabled()) { CommandLine.error("Endpoint URL must be specified."); } String endpointUriStr = arguments[ARG_END_URL_IDX].getArguments().firstElement(); URI endpointUri = null; try { <START> new URL(endpointUriStr); endpointUri = new URI(endpointUriStr, true); <END> } catch (Exception e) { CommandLine.error("Invalid Endpoint URL.\n" + e.getMessage()); } if (arguments[ARG_IMPORT_FILE_IDX].isEnabled()) { String filePath = args[ARG_IMPORT_FILE_IDX].getArguments().firstElement(); File file = new File(filePath); if (!file.exists() || !file.canRead()) { CommandLine.error("Cannot read file: " + file.getAbsolutePath()); } if (!file.isFile()) { CommandLine.error("Invalid File."); } try { GraphQlParser.parse(FileUtils.readFileToString(file, "UTF-8"), endpointUri); } catch (IOException e) { CommandLine.error("Cannot read file.\n" + e.getMessage()); } } if (arguments[ARG_IMPORT_URL_IDX].isEnabled()) { String schemaUriStr = arguments[ARG_IMPORT_URL_IDX].getArguments().firstElement(); URI schemaUri = null; try { new URL(schemaUriStr); schemaUri = new URI(schemaUriStr, true); } catch (Exception e) { CommandLine.error("Invalid Schema URL.\n" + e.getMessage()); } GraphQlParser.parse(schemaUri, endpointUri); } } if (arguments[ARG_END_URL_IDX].isEnabled()) { String endpointUriStr = arguments[ARG_END_URL_IDX].getArguments().firstElement(); URI endpointUri = null; try { new URL(endpointUriStr); endpointUri = new URI(endpointUriStr, true); } catch (Exception e) { CommandLine.error("Invalid Endpoint URL.\n" + e.getMessage()); } GraphQlParser.introspect(endpointUri); } }</code><technical_language>Move internal utility class ensure URL validations consistent avoid duplication</technical_language>

Target:
public void execute(CommandLineArgument[] args) { if (args[ARG_IMPORT_FILE_IDX].isEnabled() || args[ARG_IMPORT_URL_IDX].isEnabled()) { if (!args[ARG_END_URL_IDX].isEnabled()) { CommandLine.error(Constant.messages.getString("graphql.error.emptyendurl")); return; } GraphQlParser parser; try { parser = new GraphQlParser( args[ARG_END_URL_IDX].getArguments().firstElement(), HttpSender.MANUAL_REQUEST_INITIATOR); parser.addRequesterListener(new HistoryPersister()); } catch (URIException e) { CommandLine.error( Constant.messages.getString("graphql.error.invalidurl", e.getMessage())); return; } if (args[ARG_IMPORT_FILE_IDX].isEnabled()) { try { parser.importFile(args[ARG_IMPORT_FILE_IDX].getArguments().firstElement()); } catch (IOException e) { CommandLine.error(e.getMessage()); } } else if (args[ARG_IMPORT_URL_IDX].isEnabled()) { try { parser.importUrl(args[ARG_IMPORT_URL_IDX].getArguments().firstElement()); } catch (IOException e) { CommandLine.error( Constant.messages.getString( "graphql.error.invalidurl", e.getMessage())); } } } else if (args[ARG_END_URL_IDX].isEnabled()) { try { GraphQlParser parser = new GraphQlParser( args[ARG_END_URL_IDX].getArguments().firstElement(), HttpSender.MANUAL_REQUEST_INITIATOR); parser.addRequesterListener(new HistoryPersister()); parser.introspect(); } catch (IOException e) { CommandLine.error( Constant.messages.getString("graphql.error.invalidurl", e.getMessage())); } } }