0

我正在运行一个程序,它将针对 url 生成一些负载,并使用 RestTemplate 进一步使用相同的 URL。

我点击的 url 将返回一个简单的字符串Hello World作为响应。

下面是将对 url 生成负载的程序。

public class ShellbareboneLnP {

    public static void main(String[] args) {

        try {

            // create thread pool with given size
            ExecutorService service = Executors.newFixedThreadPool(threads);

            // queue some tasks
            long startTime = System.currentTimeMillis();
            long endTime = startTime + (durationOfRun * 60 * 1000);

            for (int i = 0; i < threads; i++) {
                service.submit(new ShellBareboneTask(endTime));
            }

            service.shutdown();
            service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        } catch (InterruptedException e) {
            LOG.warn("Threw a Interrupted Exception in" + CNAME + ".ShellbareboneLnP: boss told me to stop...Not my fault!!");
        } catch (Exception e) {
            LOG.warn("Threw a Exception in" + CNAME + e);
        } finally {
        }
    }
}


class ShellBareboneTask implements Runnable {

    private static final Logger LOG = Logger.getLogger(ShellBareboneTask.class.getName());
    public static ConcurrentHashMap<String, AtomicInteger> exceptionMap = new ConcurrentHashMap<String, AtomicInteger>();
    private final long endTime;


    /**
     * Constructor to pass the values
     * 
     * @param durationOfRun
     */
    public ShellBareboneTask(long endTime) {
        this.endTime = endTime;
    }


    @Override
    public void run() {

        try {

            RestTemplate restTemplate = new RestTemplate();

            while (System.currentTimeMillis() <= endTime) {

                PerformanceTimer timer = PerformanceTimer.getInstance();
                restTemplate.getForObject("some_url", String.class);
                timer.getDuration();

            }
        } catch (Exception e) {
            handleException(e.getCause() != null ? e.getCause().toString() : e.toString());
            e.printStackTrace();
        }

    }
}

每次程序运行一段时间后,我都会收到以下异常。我不确定是什么导致了这些异常。有人能帮我一下吗?

java.lang.IllegalArgumentException: No matching constant for [0]
    at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:426)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
16:04:20,889 ERROR ShellBareboneTask:300 - java.lang.IllegalArgumentException: No matching constant for [0]
java.lang.IllegalArgumentException: No matching constant for [0]
    at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:426)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
16:04:22,248 ERROR ShellBareboneTask:300 - java.net.SocketException: Unexpected end of file from server
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:782)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
16:04:24,955 ERROR ShellBareboneTask:300 - java.net.SocketException: Connection reset
16:04:24,955 ERROR ShellBareboneTask:300 - java.net.SocketException: Connection reset
16:04:24,955 ERROR ShellBareboneTask:300 - java.net.SocketException: Unexpected end of file from server
16:04:24,955 ERROR ShellBareboneTask:300 - java.net.SocketException: Connection reset
org.springframework.web.client.ResourceAccessException: I/O error: Connection reset; nested exception is java.net.SocketException: Connection reset
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
org.springframework.web.client.ResourceAccessException: I/O error: Connection reset; nested exception is java.net.SocketException: Connection reset at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:179)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:269)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:328)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:700)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
org.springframework.web.client.ResourceAccessException: I/O error: Connection reset; nested exception is java.net.SocketException: Connection reset
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:179)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:269)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:328)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:700)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more

    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:179)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:269)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:328)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:700)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:782)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
16:04:27,617 ERROR ShellBareboneTask:300 - java.net.SocketException: Unexpected end of file from server
16:04:27,618 ERROR ShellBareboneTask:300 - java.net.SocketException: Unexpected end of file from server
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:782)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:782)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
16:04:39,469 ERROR ShellBareboneTask:300 - java.net.SocketException: Unexpected end of file from server
org.springframework.web.client.ResourceAccessException: I/O error: Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
    at com.hostdomain.market.shell.barebone.lnp.ShellBareboneTask.run(ShellbareboneLnP.java:271)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
    at java.lang.Thread.run(Thread.java:736)
Caused by: java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:782)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:779)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:390)
    at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
    at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
    at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:439)
    ... 9 more
4

3 回答 3

5

java.lang.IllegalArgumentException:org.springframework.http.HttpStatus.valueOf(HttpStatus.java:426) 处的 [0] 没有匹配的常量

异常消息表明您的服务器端代码生成了一个响应,状态代码为:0,这是无效的。

你可以发布你的服务器端代码吗?

于 2013-08-01T01:30:08.590 回答
1

我在使用 Spring 版本 3 时遇到了同样的错误,升级到 4.2.2 后它得到了解决。

于 2015-12-28T11:56:05.733 回答
-2

我最近遇到了类似的问题。

我通过将ClientHttpRequest更改为HttpComponentsClient找到了解决方案。

这是我所做的:

restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());

希望能帮助到你

于 2014-02-01T16:53:03.057 回答