@Override public void loadAS5Data(MigrationContext ctx) throws LoadMigrationException { // TBC: Maybe use FileUtils and list all files with that name? File file = Utils.createPath( super.getGlobalConfig().getAS5Config().getDir(), "server", super.getGlobalConfig().getAS5Config().getProfileName(), "deploy", "jbossweb.sar", "server.xml"); if (!file.canRead()) throw new LoadMigrationException( "Cannot find/open file: " + file.getAbsolutePath(), new FileNotFoundException()); try { Unmarshaller unmarshaller = JAXBContext.newInstance(ServerAS5Bean.class).createUnmarshaller(); ServerAS5Bean serverAS5 = (ServerAS5Bean) unmarshaller.unmarshal(file); MigrationData mData = new MigrationData(); for (ServiceBean s : serverAS5.getServices()) { mData.getConfigFragments().add(s.getEngine()); mData.getConfigFragments().addAll(s.getConnectorAS5s()); } ctx.getMigrationData().put(ServerMigrator.class, mData); } catch (JAXBException e) { throw new LoadMigrationException("Failed parsing logging config file: " + file.getPath(), e); } }
@Override public void createActions(MigrationContext ctx) throws MigrationException { ServerMigratorResource resource = new ServerMigratorResource(); try { createDefaultSockets(ctx, resource); } catch (LoadMigrationException e) { throw new MigrationException("Migration of web server failed: " + e.getMessage(), e); } for (IConfigFragment fragment : ctx.getMigrationData().get(ServerMigrator.class).getConfigFragments()) { String what = null; try { if (fragment instanceof ConnectorAS5Bean) { what = "connector"; ctx.getActions() .addAll( createConnectorCliAction( migrateConnector((ConnectorAS5Bean) fragment, resource, ctx))); } else if (fragment instanceof EngineBean) { what = "Engine (virtual-server)"; ctx.getActions().add(createVirtualServerCliAction(migrateEngine((EngineBean) fragment))); } else throw new MigrationException( "Config fragment unrecognized by " + this.getClass().getSimpleName() + ": " + fragment); } catch (CliScriptException | NodeGenerationException e) { throw new MigrationException("Migration of the " + what + " failed: " + e.getMessage(), e); } } for (SocketBindingBean sb : resource.getSocketBindings()) { try { ctx.getActions().add(createSocketBindingCliAction(sb)); } catch (CliScriptException e) { throw new MigrationException( "Creation of the new socket-binding failed: " + e.getMessage(), e); } } }
/** * Loads socket-bindings, which are already defined in fresh standalone files. * * @param ctx migration context * @throws LoadMigrationException if unmarshalling socket-bindings from standalone file fails */ private void createDefaultSockets(MigrationContext ctx, ServerMigratorResource resource) throws LoadMigrationException { try { Unmarshaller unmarshaller = JAXBContext.newInstance(SocketBindingBean.class).createUnmarshaller(); // TODO: Read over Management API. MIGR-71 NodeList bindings = ctx.getAS7ConfigXmlDoc().getElementsByTagName("socket-binding"); for (int i = 0; i < bindings.getLength(); i++) { if (!(bindings.item(i) instanceof Element)) { continue; } SocketBindingBean socketBinding = (SocketBindingBean) unmarshaller.unmarshal(bindings.item(i)); if ((socketBinding.getSocketName() != null) || (socketBinding.getSocketPort() != null)) { resource.getSocketTemp().add(socketBinding); } } } catch (JAXBException e) { throw new LoadMigrationException( "Parsing of socket-bindings in standalone file failed: " + e.getMessage(), e); } }
/** * Migrates a connector from AS5 to AS7 * * @param connector object representing connector in AS5 * @return migrated AS7's connector * @throws NodeGenerationException if socket-binding cannot be created or set */ private ConnectorAS7Bean migrateConnector( ConnectorAS5Bean connector, ServerMigratorResource resource, MigrationContext ctx) throws NodeGenerationException { ConnectorAS7Bean connAS7 = new ConnectorAS7Bean(); connAS7.setEnabled("true"); connAS7.setEnableLookups(connector.getEnableLookups()); connAS7.setMaxPostSize(connector.getMaxPostSize()); connAS7.setMaxSavePostSize(connector.getMaxSavePostSize()); connAS7.setProtocol(connector.getProtocol()); connAS7.setProxyName(connector.getProxyName()); connAS7.setProxyPort(connector.getProxyPort()); connAS7.setRedirectPort(connector.getRedirectPort()); // Ajp connector need scheme too. So http is set. connAS7.setScheme("http"); // Socket-binding String protocol = null; if (connector.getProtocol().equals("HTTP/1.1")) { protocol = "true".equalsIgnoreCase(connector.getSslEnabled()) ? "https" : "http"; } else { // TODO: This can't be just assumed! protocol = "ajp"; } connAS7.setSocketBinding(createSocketBinding(connector.getPort(), protocol, resource)); // Name connAS7.setConnectorName(protocol); // SSL enabled? if ("true".equalsIgnoreCase(connector.getSslEnabled())) { connAS7.setScheme("https"); connAS7.setSecure(connector.getSecure()); connAS7.setSslName("ssl"); connAS7.setVerifyClient(connector.getClientAuth()); if (connector.getKeystoreFile() != null) { String fName = new File(connector.getKeystoreFile()).getName(); connAS7.setCertifKeyFile(AS7_CONFIG_DIR_PLACEHOLDER + "/keys/" + fName); CopyFileAction action = createCopyActionForKeyFile(resource, fName); if (action != null) ctx.getActions().add(action); } // TODO: No sure which protocols can be in AS5. if ((connector.getSslProtocol().equals("TLS")) || (connector.getSslProtocol() == null)) { connAS7.setSslProtocol("TLSv1"); } else { connAS7.setSslProtocol(connector.getSslProtocol()); } connAS7.setCiphers(connector.getCiphers()); connAS7.setKeyAlias(connAS7.getKeyAlias()); // TODO: AS 7 has just one password, while AS 5 has keystorePass and truststorePass. connAS7.setPassword(connector.getKeystorePass()); } return connAS7; }