Package org.teiid.net

Examples of org.teiid.net.TeiidURL


    }
   
    protected String buildServerURL() throws TeiidSQLException {
      if ( this.alternateServers == null || this.alternateServers.length() == 0) {
        // Format:  "mm://server:port"
        return new TeiidURL(this.serverName, this.portNumber, this.secure).getAppServerURL();
      }

      // Format: "mm://server1:port,server2:port,..."
    String serverURL = this.secure ? TeiidURL.SECURE_PROTOCOL : TeiidURL.DEFAULT_PROTOCOL;
   
    if (this.serverName.indexOf(':') != -1 && !this.serverName.startsWith("[")) { //$NON-NLS-1$
      serverURL += "[" + this.serverName + "]"; //$NON-NLS-1$ //$NON-NLS-2$
    } else {
      serverURL += this.serverName;
    }
   
    serverURL += TeiidURL.COLON_DELIMITER + this.portNumber;
   
    //add in the port number if not specified
   
      String[] as = this.alternateServers.split( TeiidURL.COMMA_DELIMITER);
     
      for ( int i = 0; i < as.length; i++ ) {
        String server = as[i].trim();
        //ipv6 without port
        if (server.startsWith("[") && server.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$
          String msg = reasonWhyInvalidServerName(server.substring(1, server.length() - 1));
          if (msg != null) {
            throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", msg)); //$NON-NLS-1$
          }
          serverURL += (TeiidURL.COMMA_DELIMITER +as[i] + TeiidURL.COLON_DELIMITER + this.portNumber);
        } else {
            String[] serverParts = server.split(TeiidURL.COLON_DELIMITER, 2);
            String msg = reasonWhyInvalidServerName(serverParts[0]);
          if (msg != null) {
            throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", msg)); //$NON-NLS-1$
          }
          serverURL += (TeiidURL.COMMA_DELIMITER + serverParts[0] + TeiidURL.COLON_DELIMITER);
          if ( serverParts.length > 1 ) {
            try {
            TeiidURL.validatePort(serverParts[1]);
          } catch (MalformedURLException e) {
            throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", e.getMessage())); //$NON-NLS-1$
          }
             
            serverURL += serverParts[1];
          } else {
            serverURL += this.portNumber;
          }
        }
      }
   
    try {
      return new TeiidURL(serverURL).getAppServerURL();
    } catch (MalformedURLException e) {
      throw TeiidSQLException.create(e);
    }
    }
View Full Code Here


  @Test(expected=CommunicationException.class) public void testFailedConnect() throws Exception {
    SSLConfiguration config = new SSLConfiguration();
    listener = new SocketListener(addr.getPort(), addr.getAddress().getHostAddress(),1024, 1024, 1, config, null, BufferManagerFactory.getStandaloneBufferManager());

    Properties p = new Properties();
    String url = new TeiidURL(addr.getHostName(), listener.getPort() - 1, false).getAppServerURL();
    p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url); //wrong port
    SocketServerConnectionFactory.getInstance().getConnection(p);
  }
View Full Code Here

      assertEquals(0, stats.objectsWritten);
      assertEquals(0, stats.sockets);
    }

    Properties p = new Properties();
    String url = new TeiidURL(addr.getHostName(), listener.getPort(), clientSecure).getAppServerURL();
    p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url);
    p.setProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
    if (sscf == null) {
      sscf = new SocketServerConnectionFactory();
      sscf.initialize(socketConfig);
View Full Code Here

      public void disconnected(SocketServerInstance instance,
          SessionToken session) {
       
      }
     
    }, false, new UrlServerDiscovery(new TeiidURL("0.0.0.0", 1, false)), new Properties()); //$NON-NLS-1$
    return connection;
  }
View Full Code Here

      ConnectionException {
    listener = createListener(addr, config);
    listener1 = createListener(addr, config);
    listener1.stop();
    Properties p = new Properties();
    TeiidURL teiidUrl = new TeiidURL(addr.getHostName(), listener.getPort(), clientSecure);
    teiidUrl.getHostInfo().add(new HostInfo(addr.getHostName(), listener1.getPort()));
    String url = teiidUrl.getAppServerURL();
    p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url);
    p.setProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
    p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, Boolean.TRUE.toString());
    if (sscf == null) {
      sscf = new SocketServerConnectionFactory();
View Full Code Here

   */
  public SocketServerConnection getConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
   
    updateConnectionProperties(connectionProperties);
   
    TeiidURL url;
    try {
      url = new TeiidURL(connectionProperties.getProperty(TeiidURL.CONNECTION.SERVER_URL));
    } catch (MalformedURLException e1) {
      throw new ConnectionException(e1);
    }
   
    String discoveryStrategyName = connectionProperties.getProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, URL);

    ServerDiscovery discovery;

    if (URL.equalsIgnoreCase(discoveryStrategyName)) {
      discovery = new UrlServerDiscovery();
    } else {
      try {
        discovery = (ServerDiscovery)ReflectionHelper.create(discoveryStrategyName, null, this.getClass().getClassLoader());
      } catch (TeiidException e) {
        throw new ConnectionException(e);
      }
    }
   
    discovery.init(url, connectionProperties);
   
    return new SocketServerConnection(this, url.isUsingSSL(), discovery, connectionProperties);
  }
View Full Code Here

 
  @Test public void testLogonFailsWithMultipleHosts() throws Exception {
    Properties p = new Properties();
    SocketServerInstanceFactory instanceFactory = Mockito.mock(SocketServerInstanceFactory.class);
    Mockito.stub(instanceFactory.getServerInstance((HostInfo)Mockito.anyObject())).toThrow(new SingleInstanceCommunicationException());
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL("mm://host1:1,host2:2")); //$NON-NLS-1$
    try {
      new SocketServerConnection(instanceFactory, false, discovery, p);
      fail("exception expected"); //$NON-NLS-1$
    } catch (CommunicationException e) {
      assertEquals("No valid host available. Attempted connections to: [host1:1, host2:2]", e.getMessage()); //$NON-NLS-1$
View Full Code Here

    return createConnection(throwException, new HostInfo("0.0.0.2", 1), p); //$NON-NLS-1$
  }
 
  private SocketServerConnection createConnection(final Throwable t, final HostInfo hostInfo, Properties p)
      throws CommunicationException, ConnectionException {
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL(hostInfo.getHostName(), hostInfo.getPortNumber(), false));
    SocketServerInstanceFactory instanceFactory = new SocketServerInstanceFactory() {
      FakeILogon logon = new FakeILogon(t);
     
      @Override
      public SocketServerInstance getServerInstance(HostInfo info)
View Full Code Here

TOP

Related Classes of org.teiid.net.TeiidURL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.