/** * Creates a socket-binding if it doesn't already exists. * * @param port port of the connector, which will be converted to socket-binding * @param name name of the protocol which is used by connector (ajp/http/https) * @return name of the socket-binding so it cant be referenced in connector * @throws NodeGenerationException if createDefaultSocket fails to unmarshall socket-bindings */ private static String createSocketBinding( String port, String name, ServerMigratorResource resource) throws NodeGenerationException { // TODO: Refactor and change the logic MIGR-71 for (SocketBindingBean sb : resource.getSocketTemp()) { if (sb.getSocketPort().equals(port)) { return sb.getSocketName(); } if (sb.getSocketName().equals(name)) { name = "createdSocket"; } } SocketBindingBean socketBinding = new SocketBindingBean(); for (SocketBindingBean sb : resource.getSocketBindings()) { if (sb.getSocketPort().equals(port)) { return sb.getSocketName(); } } for (SocketBindingBean sb : resource.getSocketBindings()) { if (sb.getSocketName().equals(name)) { name = name.concat(resource.getRandomSocket().toString()); } } socketBinding.setSocketName(name); socketBinding.setSocketPort(port); resource.getSocketBindings().add(socketBinding); return name; }
/** * 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); } }