Java 类java.net.UnknownServiceException 实例源码

项目:GitHub    文件:CallTest.java   
@Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
  // Configure the client with only TLS configurations. No cleartext!
  client = client.newBuilder()
      .connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS))
      .build();

  server.enqueue(new MockResponse());

  Request request = new Request.Builder().url(server.url("/")).build();
  try {
    client.newCall(request).execute();
    fail();
  } catch (UnknownServiceException expected) {
    assertEquals("CLEARTEXT communication not enabled for client", expected.getMessage());
  }
}
项目:GitHub    文件:CallTest.java   
@Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
  // Configure the client with only TLS configurations. No cleartext!
  client = client.newBuilder()
      .connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS))
      .build();

  server.enqueue(new MockResponse());

  Request request = new Request.Builder().url(server.url("/")).build();
  try {
    client.newCall(request).execute();
    fail();
  } catch (UnknownServiceException expected) {
    assertEquals("CLEARTEXT communication not enabled for client", expected.getMessage());
  }
}
项目:incubator-netbeans    文件:FileURL.java   
public InputStream getInputStream() throws IOException, UnknownServiceException {
    connect();

    if (iStream == null) {
        try {
            if (fo.isFolder()) {
                iStream = new FIS(fo);
            } else {
                iStream = fo.getInputStream();
            }
        } catch (FileNotFoundException e) {
            ExternalUtil.exception(e);
            throw e;
        }
    }

    return iStream;
}
项目:XSnow    文件:GsonResponseBodyConverter.java   
@Override
public T convert(@NonNull ResponseBody value) throws IOException {
    if (adapter != null && gson != null) {
        JsonReader jsonReader = gson.newJsonReader(value.charStream());
        try {
            T data = adapter.read(jsonReader);
            if (data == null) throw new UnknownServiceException("server back data is null");
            if (data instanceof ApiResult) {
                ApiResult apiResult = (ApiResult) data;
                if (!ResponseHelper.isSuccess(apiResult)) {
                    throw new UnknownServiceException(apiResult.getMsg() == null ? "unknow error" : apiResult.getMsg());
                }
            }
            return data;
        } finally {
            value.close();
        }
    } else {
        return null;
    }
}
项目:AndroidBasicLibs    文件:GsonResponseBodyConverter.java   
@Override
public T convert(ResponseBody value) throws IOException {
    if (adapter != null && gson != null) {
        JsonReader jsonReader = gson.newJsonReader(value.charStream());
        try {
            T data = adapter.read(jsonReader);
            if (data == null) throw new UnknownServiceException("server back data is null");
            if (data instanceof ApiResult) {
                ApiResult apiResult = (ApiResult) data;
                if (!ApiException.isSuccess(apiResult)) {
                    throw new UnknownServiceException(apiResult.getMsg() == null ? "unknow error" : apiResult.getMsg());
                }
            }
            return data;
        } finally {
            value.close();
        }
    } else {
        return null;
    }
}
项目:boohee_v5.6    文件:ConnectionSpecSelector.java   
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
    ConnectionSpec tlsConfiguration = null;
    int size = this.connectionSpecs.size();
    for (int i = this.nextModeIndex; i < size; i++) {
        ConnectionSpec connectionSpec = (ConnectionSpec) this.connectionSpecs.get(i);
        if (connectionSpec.isCompatible(sslSocket)) {
            tlsConfiguration = connectionSpec;
            this.nextModeIndex = i + 1;
            break;
        }
    }
    if (tlsConfiguration == null) {
        throw new UnknownServiceException("Unable to find acceptable protocols. isFallback="
                + this.isFallback + ", modes=" + this.connectionSpecs + ", supported " +
                "protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
    }
    this.isFallbackPossible = isFallbackPossible(sslSocket);
    Internal.instance.apply(tlsConfiguration, sslSocket, this.isFallback);
    return tlsConfiguration;
}
项目:SuperHttp    文件:GsonResponseBodyConverter.java   
@Override
public T convert(@NonNull ResponseBody value) throws IOException {
    if (adapter != null && gson != null) {
        JsonReader jsonReader = gson.newJsonReader(value.charStream());
        try {
            T data = adapter.read(jsonReader);
            if (data == null) throw new UnknownServiceException("server back data is null");
            if (data instanceof ApiResult) {
                ApiResult apiResult = (ApiResult) data;
                if (!ResponseHelper.isSuccess(apiResult)) {
                    throw new UnknownServiceException(apiResult.getMsg() == null ? "unknow error" : apiResult.getMsg());
                }
            }
            return data;
        } finally {
            value.close();
        }
    } else {
        return null;
    }
}
项目:PriorityOkHttp    文件:CallTest.java   
@Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
  // Configure the client with only TLS configurations. No cleartext!
  client = client.newBuilder()
      .connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS))
      .build();

  server.enqueue(new MockResponse());

  Request request = new Request.Builder().url(server.url("/")).build();
  try {
    client.newCall(request).execute();
    fail();
  } catch (UnknownServiceException expected) {
    assertTrue(expected.getMessage().contains("CLEARTEXT communication not supported"));
  }
}
项目:zapp    文件:MediathekListFragment.java   
@Override
public void onFailure(@NonNull Call<MediathekAnswer> call, @NonNull Throwable t) {
    adapter.setLoading(false);
    swipeRefreshLayout.setRefreshing(false);

    if (!call.isCanceled()) {
        // ignore canceled calls, because it most likely was canceled by app code
        Timber.e(t);

        if (t instanceof SSLHandshakeException || t instanceof UnknownServiceException) {
            showError(R.string.error_mediathek_ssl_error);
        } else {
            showError(R.string.error_mediathek_info_not_available);
        }
    }
}
项目:Okhttp    文件:CallTest.java   
@Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception {
  // Configure the client with only TLS configurations. No cleartext!
  client = client.newBuilder()
      .connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS))
      .build();

  server.enqueue(new MockResponse());

  Request request = new Request.Builder().url(server.url("/")).build();
  try {
    client.newCall(request).execute();
    fail();
  } catch (UnknownServiceException expected) {
    assertEquals("CLEARTEXT communication not enabled for client", expected.getMessage());
  }
}
项目:RTSP-Java-UrlConnection    文件:RtspURLConnection.java   
/**
 * Sets the supported RTSP method by the server
 * 
 * @throws IOException
 */
protected void setSupportedMethods() throws IOException {
    options();
    if (isSuccessfullResponse()) {
        String pub = responses.findValue("Public");
        if (pub != null) {
            StringTokenizer st = new StringTokenizer(pub, ",");
            if (st.countTokens() > 0) {
                List<String> l = new ArrayList<String>();
                l.add(OPTIONS);
                String s;
                while (st.hasMoreTokens()) {
                    s = st.nextToken().trim();
                    if (Arrays.binarySearch(getPlatformPossibleMethods(), s) >= 0) {
                        Debug.println(" ADD SRV METHOD " + s);
                        l.add(s);
                    }
                }
                this.supportedMethods = l.toArray(new String[l.size()]);
                return;
            }
        }
    }
    throw new UnknownServiceException("Cannot retreive server supported rtsp methods.");
}
项目:bitbucket-api-client-java    文件:OAuthClient.java   
/**
 * Returns an authorized Bitbucket API service.
 * @param authorizationCode authorization code received by the redirection
 * endpoint
 * @return authorized Bitbucket API service
 * @throws IOException if an I/O exception has occurred
 * @throws NullPointerException if this object has no client credentials
 * @since 5.0
 */
public Service getService(String authorizationCode)
        throws IOException {
    AuthorizationCodeFlow flow = getAuthorizationCodeFlow(true);
    AuthorizationCodeTokenRequest request
            = flow.newTokenRequest(authorizationCode);
    if (redirectionEndpointUri != null) {
        request.setRedirectUri(redirectionEndpointUri);
    }

    TokenResponse tokenResponse = request.execute();
    String tokenType = tokenResponse.getTokenType();
    if (!tokenType.equals(BEARER_TOKEN_TYPE)) {
        throw new UnknownServiceException("Unsupported token type");
    }
    return new RestService(
            flow.createAndStoreCredential(tokenResponse, getUser()));
}
项目:qemu-java    文件:QEmuProcess.java   
/**
 * @throws NoRouteToHostException if the process is terminated.
 * @throws UnknownServiceException if the process has no known monitor address.
 */
@Nonnull
public QApiConnection getConnection() throws IOException {
    if (monitor == null)
        throw new UnknownServiceException("No monitor address known.");

    try {
        // If this succeeds, then we have exited.
        int exitValue = process.exitValue();
        connection = null;
        throw new NoRouteToHostException("Process terminated with exit code " + exitValue);
    } catch (IllegalThreadStateException e) {
    }

    synchronized (lock) {
        if (connection != null)
            return connection;
        connection = new QApiConnection(monitor);
        return connection;
    }
}
项目:vbrowser    文件:VRLConnection.java   
public InputStream getInputStream() throws IOException
{
    if (this.connected == false)
        connect();

    if (node instanceof VStreamReadable)
    {
        return ((VStreamReadable) node).createInputStream();
    }
    else if (node instanceof VDir)
    {
        // Directories do not have stream read methods.
        // possibly the 'index.html' file is meant, but
        // here we don't know what the caller wants.
        throw new UnknownServiceException("VRS: Location is a directory:" + node);
    }
    else
    {
        throw new UnknownServiceException("VRS: Location is not streamreadable:" + node);
    }
}
项目:vbrowser    文件:VRLConnection.java   
public OutputStream getOutputStream() throws IOException
{
    if (this.connected == false)
        connect();

    if (node instanceof VStreamReadable)
    {
        return ((VStreamWritable) node).createOutputStream();
    }
    else if (node instanceof VDir)
    {
        // Directories do not have stream read methods.
        // possibly the 'index.html' file is meant, but
        // here we don't know what the caller wants.
        throw new UnknownServiceException("VRS: Location is a directory:" + node);
    }
    else
    {
        throw new UnknownServiceException("VRS: location is not streamwritable:" + node);
    }
}
项目:GitHub    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
项目:GitHub    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
项目:incubator-netbeans    文件:NbinstURLStreamHandler.java   
public void connect() throws IOException {
    if (f == null) {
        f = NbinstURLMapper.decodeURL(url);
        if (f == null) {
            throw new FileNotFoundException("Cannot find: " + url); // NOI18N
        }
    }
    if (!f.isFile()) {
        throw new UnknownServiceException();
    }
}
项目:incubator-netbeans    文件:FileURL.java   
public OutputStream getOutputStream() throws IOException, UnknownServiceException {
    connect();

    if (fo.isFolder()) {
        throw new UnknownServiceException();
    }

    if (oStream == null) {
        FileLock flock = fo.lock();
        oStream = new LockOS(fo.getOutputStream(flock), flock);
    }

    return oStream;
}
项目:incubator-netbeans    文件:SourceConnection.java   
public @Override InputStream getInputStream() throws IOException, UnknownServiceException {
    connect();

    if (iStream == null) {
        if (fo.isFolder()) {
            throw new FileNotFoundException("Can not read from a folder.");
        } else {
            iStream = fo.getInputStream();
        }
    }

    return iStream;
}
项目:lams    文件:WebForm.java   
protected WebResponse submitRequest( String event, WebRequest request ) throws IOException, SAXException {
    try {
        return super.submitRequest( event, request );
    } catch (UnknownServiceException e) {
        throw new UnsupportedActionException( "HttpUnit does not support " + request.getURL().getProtocol() + " URLs in form submissions" );
    }
}
项目:PriorityOkHttp    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
项目:Okhttp    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
项目:monsoon    文件:TcpCollectorTest.java   
@Test
public void connectServiceError() throws Exception {
    Mockito.doThrow(new UnknownServiceException()).when(mockSocket).connect(Mockito.any());

    final TcpCollector.ConnectDatum result;
    try (TcpCollector tcpCollector = new TcpCollector(dstAddress, GROUP)) {
        result = tcpCollector.tryConnect(mockSocket);
    }

    assertThat(result.getResult(), equalTo(TcpCollector.ConnectResult.UNKNOWN_SERVICE));
    Mockito.verify(mockSocket, times(1)).connect(Mockito.eq(dstAddress));
    Mockito.verifyNoMoreInteractions(mockSocket);
}
项目:AndroidProjects    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
项目:AndroidAppLib    文件:ConnectionSpecSelector.java   
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
    ConnectionSpec tlsConfiguration = null;
    for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
        ConnectionSpec connectionSpec = connectionSpecs.get(i);
        if (connectionSpec.isCompatible(sslSocket)) {
            tlsConfiguration = connectionSpec;
            nextModeIndex = i + 1;
            break;
        }
    }

    if (tlsConfiguration == null) {
        // This may be the first time a connection has been attempted and the socket does not support
        // any the required protocols, or it may be a retry (but this socket supports fewer
        // protocols than was suggested by a prior socket).
        throw new UnknownServiceException(
                "Unable to find acceptable protocols. isFallback=" + isFallback
                        + ", modes=" + connectionSpecs
                        + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
    }

    isFallbackPossible = isFallbackPossible(sslSocket);

    Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

    return tlsConfiguration;
}
项目:PiratePlayar    文件:Announce.java   
/**
 * Create a {@link TrackerClient} annoucing to the given tracker address.
 *
 * @param torrent The torrent the tracker client will be announcing for.
 * @param peer The peer the tracker client will announce on behalf of.
 * @param tracker The tracker address as a {@link URI}.
 * @throws UnknownHostException If the tracker address is invalid.
 * @throws UnknownServiceException If the tracker protocol is not supported.
 */
private TrackerClient createTrackerClient(SharedTorrent torrent, Peer peer,
    URI tracker) throws UnknownHostException, UnknownServiceException {
    String scheme = tracker.getScheme();

    if ("http".equals(scheme) || "https".equals(scheme)) {
        return new HTTPTrackerClient(torrent, peer, tracker);
    } else if ("udp".equals(scheme)) {
        return new UDPTrackerClient(torrent, peer, tracker);
    }

    throw new UnknownServiceException(
        "Unsupported announce scheme: " + scheme + "!");
}
项目:ant    文件:ResourceOutputTest.java   
@Test
public void testurloutput() throws IOException {
    File f = project.resolveFile("testurloutput");
    try {
        FILE_UTILS.createNewFile(f);
        testoutput(new URLResource(f));
        fail("should have caught UnknownServiceException");
    } catch (UnknownServiceException e) {
        //TODO assert exception message
    } finally {
        if (!f.delete()) {
            f.deleteOnExit();
        }
    }
}
项目:cn1    文件:UnknownServiceExceptionTest.java   
/**
 * @tests java.net.UnknownServiceException#UnknownServiceException()
 */
public void test_Constructor() {
    try {
        if (true) {
            throw new UnknownServiceException();
        }
        fail("Exception not thrown");
    } catch (UnknownServiceException e) {
        // Expected
    }
}
项目:cn1    文件:UnknownServiceExceptionTest.java   
/**
 * @tests java.net.UnknownServiceException#UnknownServiceException(java.lang.String)
 */
public void test_ConstructorLjava_lang_String() {
    try {
        if (true) {
            throw new UnknownServiceException("test");
        }
        fail("Constructor failed");
    } catch (UnknownServiceException e) {
        assertEquals("Wrong exception message", "test", e.getMessage());
    }
}
项目:spring-restlet    文件:DefaultMultipartFormParser.java   
public Collection<FormDataItem> parse(Request request)
throws IOException  {
    FileItemFactory factory = new DiskFileItemFactory();
    //ServletFileUpload upload = new ServletFileUpload(factory);
    RestletFileUpload upload = new RestletFileUpload(factory);
    try {
        List<FileItem> fileItems = upload.parseRequest(request);
        return convertToFormData(fileItems);
    } catch (FileUploadException e) {
        UnknownServiceException use = new UnknownServiceException("File upload error.");
        use.initCause(e);
        throw use;
    }
}
项目:freeVM    文件:UnknownServiceExceptionTest.java   
/**
 * @tests java.net.UnknownServiceException#UnknownServiceException(java.lang.String)
 */
public void test_ConstructorLjava_lang_String() {
    // Test for method java.net.UnknownServiceException(java.lang.String)
    try {
        if (true)
            throw new UnknownServiceException("HelloWorld");
    } catch (UnknownServiceException e) {
        assertTrue("Wrong exception message: " + e.toString(), e
                .getMessage().equals("HelloWorld"));
        return;
    }
    fail("Constructor failed");
}
项目:freeVM    文件:UnknownServiceExceptionTest.java   
/**
 * @tests java.net.UnknownServiceException#UnknownServiceException()
 */
public void test_Constructor() {
    try {
        if (true) {
            throw new UnknownServiceException();
        }
        fail("Exception not thrown");
    } catch (UnknownServiceException e) {
        // Expected
    }
}
项目:freeVM    文件:UnknownServiceExceptionTest.java   
/**
 * @tests java.net.UnknownServiceException#UnknownServiceException(java.lang.String)
 */
public void test_ConstructorLjava_lang_String() {
    try {
        if (true) {
            throw new UnknownServiceException("test");
        }
        fail("Constructor failed");
    } catch (UnknownServiceException e) {
        assertEquals("Wrong exception message", "test", e.getMessage());
    }
}
项目:afc    文件:URLConnection.java   
@Override
public OutputStream getOutputStream() throws IOException {
       connect();
    if (getDoOutput()) {
        OutputStream os = new FileOutputStream(this.file);
        if (getUseCaches()) {
            os = new BufferedOutputStream(os);
        }
        return os;
    }
    throw new UnknownServiceException(Locale.getString("E1")); //$NON-NLS-1$
   }
项目:afc    文件:URLConnection.java   
@Override
public InputStream getInputStream() throws IOException {
       connect();
    if (getDoInput()) {
        InputStream is = new FileInputStream(this.file);
        if (getUseCaches()) {
            is = new BufferedInputStream(is);
        }
        return is;
    }
    throw new UnknownServiceException("E2"); //$NON-NLS-1$
   }
项目:bitworker    文件:Announce.java   
/**
 * Create a {@link TrackerClient} annoucing to the given tracker address.
 *
 * @param torrent The torrent the tracker client will be announcing for.
 * @param peer The peer the tracker client will announce on behalf of.
 * @param tracker The tracker address as a {@link URI}.
 * @throws UnknownHostException If the tracker address is invalid.
 * @throws UnknownServiceException If the tracker protocol is not supported.
 */
private TrackerClient createTrackerClient(SharedTorrent torrent, Peer peer,
    URI tracker) throws UnknownHostException, UnknownServiceException {
    String scheme = tracker.getScheme();

    if ("http".equals(scheme) || "https".equals(scheme)) {
        return new HTTPTrackerClient(torrent, peer, tracker);
    } else if ("udp".equals(scheme)) {
        return new UDPTrackerClient(torrent, peer, tracker);
    }

    throw new UnknownServiceException(
        "Unsupported announce scheme: " + scheme + "!");
}
项目:shindig-1.1-BETA5-incubating    文件:DefaultMultipartFormParser.java   
public Collection<FormDataItem> parse(HttpServletRequest servletRequest)
    throws IOException  {
  FileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload upload = new ServletFileUpload(factory);

  try {
    @SuppressWarnings("unchecked")
    List<FileItem> fileItems = upload.parseRequest(servletRequest);
    return convertToFormData(fileItems);
  } catch (FileUploadException e) {
    UnknownServiceException use = new UnknownServiceException("File upload error.");
    use.initCause(e);
    throw use; 
  }
}
项目:GitHub    文件:RealConnection.java   
public void connect(
    int connectTimeout, int readTimeout, int writeTimeout, boolean connectionRetryEnabled) {
  if (protocol != null) throw new IllegalStateException("already connected");

  RouteException routeException = null;
  List<ConnectionSpec> connectionSpecs = route.address().connectionSpecs();
  ConnectionSpecSelector connectionSpecSelector = new ConnectionSpecSelector(connectionSpecs);

  if (route.address().sslSocketFactory() == null) {
    if (!connectionSpecs.contains(ConnectionSpec.CLEARTEXT)) {
      throw new RouteException(new UnknownServiceException(
          "CLEARTEXT communication not enabled for client"));
    }
    String host = route.address().url().host();
    if (!Platform.get().isCleartextTrafficPermitted(host)) {
      throw new RouteException(new UnknownServiceException(
          "CLEARTEXT communication to " + host + " not permitted by network security policy"));
    }
  }

  while (true) {
    try {
      if (route.requiresTunnel()) {
        connectTunnel(connectTimeout, readTimeout, writeTimeout);
      } else {
        connectSocket(connectTimeout, readTimeout);
      }
      establishProtocol(connectionSpecSelector);
      break;
    } catch (IOException e) {
      closeQuietly(socket);
      closeQuietly(rawSocket);
      socket = null;
      rawSocket = null;
      source = null;
      sink = null;
      handshake = null;
      protocol = null;
      http2Connection = null;

      if (routeException == null) {
        routeException = new RouteException(e);
      } else {
        routeException.addConnectException(e);
      }

      if (!connectionRetryEnabled || !connectionSpecSelector.connectionFailed(e)) {
        throw routeException;
      }
    }
  }

  if (http2Connection != null) {
    synchronized (connectionPool) {
      allocationLimit = http2Connection.maxConcurrentStreams();
    }
  }
}
项目:GitHub    文件:RealConnection.java   
public void connect(int connectTimeout, int readTimeout, int writeTimeout,
    boolean connectionRetryEnabled, Call call, EventListener eventListener) {
  if (protocol != null) throw new IllegalStateException("already connected");

  RouteException routeException = null;
  List<ConnectionSpec> connectionSpecs = route.address().connectionSpecs();
  ConnectionSpecSelector connectionSpecSelector = new ConnectionSpecSelector(connectionSpecs);

  if (route.address().sslSocketFactory() == null) {
    if (!connectionSpecs.contains(ConnectionSpec.CLEARTEXT)) {
      throw new RouteException(new UnknownServiceException(
          "CLEARTEXT communication not enabled for client"));
    }
    String host = route.address().url().host();
    if (!Platform.get().isCleartextTrafficPermitted(host)) {
      throw new RouteException(new UnknownServiceException(
          "CLEARTEXT communication to " + host + " not permitted by network security policy"));
    }
  }

  while (true) {
    try {
      if (route.requiresTunnel()) {
        connectTunnel(connectTimeout, readTimeout, writeTimeout, call, eventListener);
        if (rawSocket == null) {
          // We were unable to connect the tunnel but properly closed down our resources.
          break;
        }
      } else {
        connectSocket(connectTimeout, readTimeout, call, eventListener);
      }
      establishProtocol(connectionSpecSelector, call, eventListener);
      eventListener.connectEnd(call, route.socketAddress(), route.proxy(), protocol);
      break;
    } catch (IOException e) {
      closeQuietly(socket);
      closeQuietly(rawSocket);
      socket = null;
      rawSocket = null;
      source = null;
      sink = null;
      handshake = null;
      protocol = null;
      http2Connection = null;

      eventListener.connectFailed(call, route.socketAddress(), route.proxy(), null, e);

      if (routeException == null) {
        routeException = new RouteException(e);
      } else {
        routeException.addConnectException(e);
      }

      if (!connectionRetryEnabled || !connectionSpecSelector.connectionFailed(e)) {
        throw routeException;
      }
    }
  }

  if (route.requiresTunnel() && rawSocket == null) {
    ProtocolException exception = new ProtocolException("Too many tunnel connections attempted: "
        + MAX_TUNNEL_ATTEMPTS);
    throw new RouteException(exception);
  }

  if (http2Connection != null) {
    synchronized (connectionPool) {
      allocationLimit = http2Connection.maxConcurrentStreams();
    }
  }
}