当前位置: 首页>>代码示例>>Java>>正文


Java SocketTimeoutException类代码示例

本文整理汇总了Java中java.net.SocketTimeoutException的典型用法代码示例。如果您正苦于以下问题:Java SocketTimeoutException类的具体用法?Java SocketTimeoutException怎么用?Java SocketTimeoutException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SocketTimeoutException类属于java.net包,在下文中一共展示了SocketTimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onError

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public void onError(Throwable e) {
    if(subscriberOnListener != null && context != null)
    {
        if (e instanceof SocketTimeoutException) {
            subscriberOnListener.onError(-1001, "网络超时,请检查您的网络状态");
        } else if (e instanceof ConnectException) {
            subscriberOnListener.onError(-1002, "网络链接中断,请检查您的网络状态");
        } else if(e instanceof ExceptionApi){
            subscriberOnListener.onError(((ExceptionApi)e).getCode(), ((ExceptionApi)e).getMsg());
        }
        else
        {
            subscriberOnListener.onError(-1003, "未知错误:" + e.getMessage());
        }
    }
    else
    {
        if(disposable != null && !disposable.isDisposed())
            disposable.dispose();
    }
}
 
开发者ID:wanliyang1990,项目名称:AppServiceRestFul,代码行数:23,代码来源:HttpSubscriber.java

示例2: getErrorMessage

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "SocketTimeoutException";
    } else if (t instanceof IOException) {
        errorMessage = "Network Gone Down";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = cause.getLocalizedMessage();
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:22,代码来源:ApiErrorUtils.java

示例3: run

import java.net.SocketTimeoutException; //导入依赖的package包/类
public void run() {
    try {
        while (!socket.isClosed()) {
            pause.get().await();
            try {
                Socket source = socket.accept();
                pause.get().await();
                if (receiveBufferSize > 0) {
                    source.setReceiveBufferSize(receiveBufferSize);
                }
                LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
                synchronized (connections) {
                    connections.add(new Bridge(source, target));
                }
            } catch (SocketTimeoutException expected) {
            }
        }
    } catch (Exception e) {
        LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:22,代码来源:SocketProxy.java

示例4: run

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public void run() {
          try {
              while (!socket.isClosed()) {
                  pause.get().await();
                  try {
                      Socket source = socket.accept();
                      pause.get().await();
                      if (receiveBufferSize > 0) {
                          source.setReceiveBufferSize(receiveBufferSize);
                      }
                      LOG.info("accepted " + source + ", receiveBufferSize:" + source.getReceiveBufferSize());
                      synchronized (connections) {
                          connections.add(new Bridge(source, target));
                      }
                  } catch (SocketTimeoutException expected) {
                  }
              }
          } catch (Exception e) {
              LOG.debug("acceptor: finished for reason: " + e.getLocalizedMessage());
          }
      }
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:23,代码来源:SocketProxy.java

示例5: getStringByWalk

import java.net.SocketTimeoutException; //导入依赖的package包/类
public static List<String> getStringByWalk(SnmpAccess snmp, final String oid)
        throws SocketTimeoutException, SocketException, AbortedException,
        IOException, RepeatedOidException, SnmpResponseException {
    List<String> result = new ArrayList<String>();
    AbstractWalkProcessor<List<String>> walker =
            new AbstractWalkProcessor<List<String>>(result) {
                private static final long serialVersionUID = 1L;

                public void process(VarBind varbind) {
                    StringSnmpEntry entry = new StringSnmpEntry(oid, varbind);
                    result.add(entry.getValue());
                }
            };
    snmp.walk(oid, walker);
    return walker.getResult();
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:17,代码来源:SnmpUtil.java

示例6: initSocket

import java.net.SocketTimeoutException; //导入依赖的package包/类
public static void initSocket(final Socket s, final String host, final int port, final JSONObject error)
		throws SocketException, IOException {
	final SocketAddress endpoint = new InetSocketAddress(host, port);
	try {
		s.setSoTimeout(1000);
		s.connect(endpoint, 1000);
	} catch (SocketTimeoutException | ConnectException | UnknownHostException e) {
		error.put("class", e.getClass().getSimpleName());
		error.put("message", e.getMessage());
	}
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:12,代码来源:TestUtil.java

示例7: readTimeouts

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test public void readTimeouts() throws IOException {
  // This relies on the fact that MockWebServer doesn't close the
  // connection after a response has been sent. This causes the client to
  // try to read more bytes than are sent, which results in a timeout.
  MockResponse timeout =
      new MockResponse().setBody("ABC").clearHeaders().addHeader("Content-Length: 4");
  server.enqueue(timeout);
  server.enqueue(new MockResponse().setBody("unused")); // to keep the server alive

  URLConnection connection = urlFactory.open(server.url("/").url());
  connection.setReadTimeout(1000);
  InputStream in = connection.getInputStream();
  assertEquals('A', in.read());
  assertEquals('B', in.read());
  assertEquals('C', in.read());
  try {
    in.read(); // if Content-Length was accurate, this would return -1 immediately
    fail();
  } catch (SocketTimeoutException expected) {
  }
  in.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:URLConnectionTest.java

示例8: getMultipleSnmpEntries

import java.net.SocketTimeoutException; //导入依赖的package包/类
public static List<SnmpEntry> getMultipleSnmpEntries(SnmpAccess snmp,
                                                     final List<String> oids) throws SocketTimeoutException, SocketException,
        AbortedException, IOException, SnmpResponseException, NoSuchMibException {
    String[] oidarray = oids.toArray(new String[oids.size()]);
    Map<String, VarBind> gots = snmp.multiGet(oidarray);
    List<SnmpEntry> result = new ArrayList<SnmpEntry>();
    for (Map.Entry<String, VarBind> got : gots.entrySet()) {
        String oid = got.getKey();
        VarBind vb = got.getValue();
        PDU.Generic pdu = (PDU.Generic) vb.getPdu();
        if (pdu.getErrorStatus() > 0) {
            throw new IOException("got ErrorStatus=" + pdu.getErrorStatus());
        }
        if (SnmpV2ResponseException.noSuchInstance == vb.getV2ResponseException()) {
            throw new NoSuchMibException(oid);
        }
        SnmpEntry se = new SnmpEntry(oid, vb);
        result.add(se);
    }
    return result;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:22,代码来源:SnmpUtil.java

示例9: intercept

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public Response intercept(final Chain chain) throws IOException {

    final Request request = chain.request();
    final Response response;
    try {
        // try the call
        response = chain.proceed(request);

        //noinspection IfStatementWithNegatedCondition
        if (response.code() != HTTP_CODE_202) {
            return response;
        } else {
            response.body().close();
            return repeatRequest(chain, request);
        }
    } catch (final SocketTimeoutException e) {
        throw e;
    }
}
 
开发者ID:MikeFot,项目名称:Java--Steam-Loader,代码行数:21,代码来源:RetryPolicyInterceptor.java

示例10: expect100ContinueTimesOutWithoutContinue

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test public void expect100ContinueTimesOutWithoutContinue() throws Exception {
  server.enqueue(new MockResponse()
      .setSocketPolicy(SocketPolicy.NO_RESPONSE));

  client = client.newBuilder()
      .readTimeout(500, TimeUnit.MILLISECONDS)
      .build();

  Request request = new Request.Builder()
      .url(server.url("/"))
      .header("Expect", "100-continue")
      .post(RequestBody.create(MediaType.parse("text/plain"), "abc"))
      .build();

  Call call = client.newCall(request);
  try {
    call.execute();
    fail();
  } catch (SocketTimeoutException expected) {
  }

  RecordedRequest recordedRequest = server.takeRequest();
  assertEquals("", recordedRequest.getBody().readUtf8());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:CallTest.java

示例11: requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutDisabledInRequestObject_TakesPrecedenceOverClientConfiguration() {
    final int socketTimeout = REQUEST_TIMEOUT;
    // Client configuration is set arbitrarily low so that the request will be aborted if
    // the client configuration is incorrectly honored over the request config
    httpClient = new AmazonHttpClient(
            new ClientConfiguration().withSocketTimeout(socketTimeout).withRequestTimeout(1).withMaxErrorRetry(0));

    try {
        EmptyHttpRequest request = newGetRequest();
        request.setOriginalRequest(new EmptyAmazonWebServiceRequest().withSdkRequestTimeout(0));
        execute(httpClient, request);
        fail("Exception expected");
    } catch (AmazonClientException e) {
        assertThat(e.getCause(), instanceOf(SocketTimeoutException.class));
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:UnresponsiveServerTests.java

示例12: getNotFoundError

import java.net.SocketTimeoutException; //导入依赖的package包/类
private static String getNotFoundError(CoreException ce) {
    IStatus status = ce.getStatus();
    Throwable t = status.getException();
    if(t instanceof UnknownHostException ||
       // XXX maybe a different msg ?     
       t instanceof SocketTimeoutException || 
       t instanceof NoRouteToHostException ||
       t instanceof ConnectException) 
    {
        Bugzilla.LOG.log(Level.FINER, null, t);
        return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");                   // NOI18N
    }
    String msg = getMessage(ce);
    if(msg != null) {
        msg = msg.trim().toLowerCase();
        if(HTTP_ERROR_NOT_FOUND.equals(msg)) {
            Bugzilla.LOG.log(Level.FINER, "returned error message [{0}]", msg);                     // NOI18N
            return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");               // NOI18N
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BugzillaExecutor.java

示例13: getErrorMessage

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        switch (((HttpException) t).code()){
            case 500:
                errorMessage = "Server Down Customize message";
                break;
            case 400:
                errorMessage= "Bad Request Customize Message";
                break;
            default:
                break;

        }
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "Slow Network Connection";
    } else if (t instanceof IOException) {
        errorMessage = "Network Gone Down";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = "OOPs!! Something went wrong";
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:32,代码来源:ApiErrorUtils.java

示例14: getErrorMessage

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Override
public  String getErrorMessage(Throwable t) {
    String errorMessage = "OOPs!! Something went wrong";

    Timber.d(t);

    if (t instanceof HttpException) {
        errorMessage = "Errorcode"+((HttpException) t).code()+" "+t.getLocalizedMessage();
    } else if (t instanceof SocketTimeoutException) {
        errorMessage = "Internet Problem";
    } else if (t instanceof IOException) {
        errorMessage = "Internet Problem";
    }

    Throwable cause = t.getCause();
    if (cause instanceof RaveException) {
        errorMessage = "Server Bug: "+cause.getLocalizedMessage();
    }

    return errorMessage;
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:22,代码来源:ApiErrorUtils.java

示例15: testRetrySocket

import java.net.SocketTimeoutException; //导入依赖的package包/类
@Test
public void testRetrySocket() throws Exception {
    final BackgroundException failure = new BackgroundException(new SocketTimeoutException(""));
    SessionBackgroundAction<Void> a = new SessionBackgroundAction<Void>(new StatelessSessionPool(
            new TestLoginConnectionService(),
            new NullSession(new Host(new TestProtocol(), "t")), PathCache.empty(),
            new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), new AlertCallback() {
        @Override
        public boolean alert(final Host repeatableBackgroundAction, final BackgroundException f, final StringBuilder transcript) {
            assertEquals(failure, f);
            return false;
        }
    }, new DisabledProgressListener(), new DisabledTranscriptListener()) {
        @Override
        public Void run(final Session<?> session) throws BackgroundException {
            throw failure;
        }
    };
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:20,代码来源:SessionBackgroundActionTest.java


注:本文中的java.net.SocketTimeoutException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。