/** * Attach JAIN-SIP <tt>SipProvider</tt> and <tt>ListeningPoint</tt> to the stack either for clear * communications or TLS. Clear UDP and TCP <tt>ListeningPoint</tt>s are not handled separately as * the former is a fallback for the latter (depending on the size of the data transmitted). Both * <tt>ListeningPoint</tt>s must be bound to the same address and port in order for the related * <tt>SipProvider</tt> to be created. If a UDP or TCP <tt>ListeningPoint</tt> cannot bind, retry * for both on another port. * * @param preferredPort which port to try first to bind. * @param retries how many times should we try to find a free port to bind * @param secure whether to create the TLS SipProvider. or the clear UDP/TCP one. * @throws TransportNotSupportedException in case we try to create a provider for a transport not * currently supported by jain-sip * @throws InvalidArgumentException if we try binding to an illegal port (which we won't) * @throws ObjectInUseException if another <tt>SipProvider</tt> is already associated with this * <tt>ListeningPoint</tt>. * @throws TransportAlreadySupportedException if there is already a ListeningPoint associated to * this <tt>SipProvider</tt> with the same transport of the <tt>ListeningPoint</tt>. * @throws TooManyListenersException if we try to add a new <tt>SipListener</tt> with a * <tt>SipProvider</tt> when one was already registered. */ private void createProvider(int preferredPort, int retries, boolean secure) throws TransportNotSupportedException, InvalidArgumentException, ObjectInUseException, TransportAlreadySupportedException, TooManyListenersException { String context = (secure ? "TLS: " : "clear UDP/TCP: "); if (retries < 0) { // very unlikely to happen with the default 50 retries logger.error(context + "couldn't find free ports to listen on."); return; } ListeningPoint tlsLP = null; ListeningPoint udpLP = null; ListeningPoint tcpLP = null; try { if (secure) { tlsLP = this.stack.createListeningPoint( NetworkUtils.IN_ADDR_ANY, preferredPort, ListeningPoint.TLS); if (logger.isTraceEnabled()) logger.trace("TLS secure ListeningPoint has been created."); this.secureJainSipProvider = this.stack.createSipProvider(tlsLP); this.secureJainSipProvider.addSipListener(this); } else { udpLP = this.stack.createListeningPoint( NetworkUtils.IN_ADDR_ANY, preferredPort, ListeningPoint.UDP); tcpLP = this.stack.createListeningPoint( NetworkUtils.IN_ADDR_ANY, preferredPort, ListeningPoint.TCP); if (logger.isTraceEnabled()) logger.trace("UDP and TCP clear ListeningPoints have " + "been created."); this.clearJainSipProvider = this.stack.createSipProvider(udpLP); this.clearJainSipProvider.addListeningPoint(tcpLP); this.clearJainSipProvider.addSipListener(this); } if (logger.isTraceEnabled()) logger.trace(context + "SipProvider has been created."); } catch (InvalidArgumentException ex) { // makes sure we didn't leave an open listener // as both UDP and TCP listener have to bind to the same port if (tlsLP != null) this.stack.deleteListeningPoint(tlsLP); if (udpLP != null) this.stack.deleteListeningPoint(udpLP); if (tcpLP != null) this.stack.deleteListeningPoint(tcpLP); // FIXME: "Address already in use" is not working // as ex.getMessage() displays in the locale language in SC // (getMessage() is always supposed to be English though) // this should be a temporary workaround // if (ex.getMessage().indexOf("Address already in use") != -1) // another software is probably using the port if (ex.getCause() instanceof java.io.IOException) { if (logger.isDebugEnabled()) logger.debug("Port " + preferredPort + " seems in use for either TCP or UDP."); // tries again on a new random port int currentlyTriedPort = NetworkUtils.getRandomPortNumber(); if (logger.isDebugEnabled()) logger.debug("Retrying bind on port " + currentlyTriedPort); this.createProvider(currentlyTriedPort, retries - 1, secure); } else throw ex; } }
private GdcNotification(CommandLine ln, Properties defaults) { try { cliParams = parse(ln, defaults); cliParams.setHttpConfig( new NamePasswordConfiguration( "https", cliParams.get(CLI_PARAM_GDC_HOST[0]), cliParams.get(CLI_PARAM_GDC_USERNAME[0]), cliParams.get(CLI_PARAM_GDC_PASSWORD[0]))); String config = cliParams.get(CLI_PARAM_CONFIG); if (config != null && config.length() > 0) { execute(config); } else { l.error("No config file given."); commandsHelp(); System.exit(1); } finishedSucessfuly = true; } catch (ConnectionException e) { l.error("Can't connect to SFDC: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("Can't connect to SFDC:", e); } catch (InvalidArgumentException e) { l.error("Invalid command line argument: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("Invalid command line argument:", e); l.info(commandsHelp()); } catch (SfdcException e) { l.error("Error communicating with SalesForce: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("Error communicating with SalesForce.", e); } catch (IOException e) { l.error( "Encountered an IO problem. Please check that all files that you use in your command line arguments and commands exist. More info: '" + e.getMessage() + "'"); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug( "Encountered an IO problem. Please check that all files that you use in your command line arguments and commands exist. More info: '" + e.getMessage() + "'", e); } catch (InternalErrorException e) { Throwable c = e.getCause(); if (c != null && c instanceof SQLException) { l.error( "Error extracting data. Can't process the incoming data. Please check the CSV file " + "separator and consistency (same number of columns in each row). Also, please make sure " + "that the number of columns in your XML config file matches the number of rows in your " + "data source. Make sure that your file is readable by other users (particularly the mysql user). " + "More info: '" + c.getMessage() + "'"); l.debug( "Error extracting data. Can't process the incoming data. Please check the CSV file " + "separator and consistency (same number of columns in each row). Also, please make sure " + "that the number of columns in your XML config file matches the number of rows in your " + "data source. Make sure that your file is readable by other users (particularly the mysql user). " + "More info: '" + c.getMessage() + "'", c); } else { l.error("Internal error: " + e.getMessage()); c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("REST API invocation error: ", e); } } catch (HttpMethodException e) { l.error("Error executing GoodData REST API: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("Error executing GoodData REST API.", e); } catch (GdcRestApiException e) { l.error("REST API invocation error: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { if (c instanceof HttpMethodException) { HttpMethodException ex = (HttpMethodException) c; String msg = ex.getMessage(); if (msg != null && msg.length() > 0 && msg.indexOf("/ldm/manage") > 0) { l.error("Error creating/updating logical data model (executing MAQL DDL)."); if (msg.indexOf(".date") > 0) { l.error("Bad time dimension schemaReference."); } else { l.error( "You are either trying to create a data object that already exists " + "(executing the same MAQL multiple times) or providing a wrong reference " + "or schemaReference in your XML configuration."); } } } l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("REST API invocation error: ", e); } catch (GdcException e) { l.error("Unrecognized error: " + e.getMessage()); Throwable c = e.getCause(); while (c != null) { l.error("Caused by: " + c.getMessage()); c = c.getCause(); } l.debug("Unrecognized error: ", e); } }