Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssl 来自grails应用程序的握手失败_Ssl_Grails_Grails 2.5 - Fatal编程技术网

Ssl 来自grails应用程序的握手失败

Ssl 来自grails应用程序的握手失败,ssl,grails,grails-2.5,Ssl,Grails,Grails 2.5,当我使用curl查询logz.io时,它的作用如下: curl -XPOST 'https://api.logz.io/v1/query' --header "X-USER-TOKEN : VALID_TOKEN" --header "Content-Type: application/json" -d '{"queryString" : "query","timestamp" : {"gte":1482157546000}}' 但是,当我尝试用JAVA 8执行相同的操作时 java vers

当我使用
curl
查询logz.io时,它的作用如下:

curl -XPOST 'https://api.logz.io/v1/query' --header "X-USER-TOKEN : VALID_TOKEN" --header "Content-Type: application/json" -d '{"queryString" : "query","timestamp" : {"gte":1482157546000}}'
但是,当我尝试用JAVA 8执行相同的操作时

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
从我的grails 2.5.4应用程序:

String  baseUrl = "https://api.logz.io/v1/"
String  query = "query"
String apiKey = "VALID_TOKEN"

withHttp(uri: baseUrl) { 
    def bodyContent = [ 
        queryString: query 
    ] 
    def json = post(path: 'query', body: bodyContent) { 
        headers.'X-USER-TOKEN' = apiKey 
    } 
    return json 
}
我有:

| Error 2016-12-26 18:41:06,144 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - SSLHandshakeException occurred when processing request: [GET] /cms/offer/findWhoEditedAllocationItems/14787265
Received fatal alert: handshake_failure. Stacktrace follows:
Message: Received fatal alert: handshake_failure
    Line | Method
->>  192 | getSSLException                 in sun.security.ssl.Alerts
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    154 | getSSLException                 in     ''
|   2023 | recvAlert . . . . . . . . . . . in sun.security.ssl.SSLSocketImpl
|   1125 | readRecord                      in     ''
|   1375 | performInitialHandshake . . . . in     ''
|   1403 | startHandshake                  in     ''
|   1387 | startHandshake . . . . . . . .  in     ''
|    553 | connectSocket                   in org.apache.http.conn.ssl.SSLSocketFactory
|    412 | connectSocket . . . . . . . . . in     ''
|    179 | openConnection                  in org.apache.http.impl.conn.DefaultClientConnectionOperator
|    328 | open . . . . . . . . . . . . .  in org.apache.http.impl.conn.ManagedClientConnectionImpl
|    612 | tryConnect                      in org.apache.http.impl.client.DefaultRequestDirector
|    447 | execute . . . . . . . . . . . . in     ''
|    884 | doExecute                       in org.apache.http.impl.client.AbstractHttpClient
|     82 | execute . . . . . . . . . . . . in org.apache.http.impl.client.CloseableHttpClient
|     55 | execute                         in     ''
|    477 | doRequest . . . . . . . . . . . in groovyx.net.http.HTTPBuilder
|    359 | post                            in     ''
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke                          in     ''
|     43 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke                          in java.lang.reflect.Method
|   1426 | jlrMethodInvoke . . . . . . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|     93 | invoke                          in org.codehaus.groovy.reflection.CachedMethod
|    325 | doMethodInvoke . . . . . . . .  in groovy.lang.MetaMethod
|   1210 | invokeMethod                    in groovy.lang.MetaClassImpl
|   1123 | invokeMethod . . . . . . . . .  in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod                    in groovy.lang.MetaClassImpl
|   1122 | invokeMethod . . . . . . . . .  in     ''
|   1123 | invokeMethod                    in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|     69 | callCurrent                     in org.codehaus.groovy.runtime.callsite.PogoMetaClassSite
|     52 | defaultCallCurrent . . . . . .  in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    154 | callCurrent                     in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    174 | callCurrent . . . . . . . . . . in     ''
|     24 | doCall                          in com.example.logz.LogzService$__tt__getResultFromQuery_closure3
|     -1 | doCall . . . . . . . . . . . .  in     ''
|     -2 | invoke0                         in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke . . . . . . . . . . . .  in     ''
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|   1426 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|    210 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce
|     71 | call                            in org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite
|     48 | defaultCall . . . . . . . . . . in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    113 | call                            in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    117 | call . . . . . . . . . . . . .  in     ''
|     93 | doCall                          in RestGrailsPlugin$_closure4
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke                          in     ''
|     43 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke                          in java.lang.reflect.Method
|   1426 | jlrMethodInvoke . . . . . . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|     93 | invoke                          in org.codehaus.groovy.reflection.CachedMethod
|    325 | doMethodInvoke . . . . . . . .  in groovy.lang.MetaMethod
|   1210 | invokeMethod                    in groovy.lang.MetaClassImpl
|   1123 | invokeMethod . . . . . . . . .  in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod                    in groovy.lang.MetaClassImpl
|   1084 | invokeMethod . . . . . . . . .  in     ''
|   1123 | invokeMethod                    in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|    917 | invokePogoMethod                in org.codehaus.groovy.runtime.InvokerHelper
|    900 | invokeMethod . . . . . . . . .  in     ''
|    189 | invoke                          in org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod$AnonymousMetaMethod
|    251 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce
|     59 | callCurrent                     in org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite
|     52 | defaultCallCurrent . . . . . .  in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    154 | callCurrent                     in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    174 | callCurrent . . . . . . . . . . in     ''
|     20 | $tt__getResultFromQuery         in com.example.logz.LogzService
|     -1 | doCall . . . . . . . . . . . .  in com.example.logz.LogzService$_getResultFromQuery_closure1
|     -2 | invoke0                         in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke . . . . . . . . . . . .  in     ''
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|   1426 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     93 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.reflection.CachedMethod
|    325 | doMethodInvoke                  in groovy.lang.MetaMethod
|   1210 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|   1123 | invokeMethod                    in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|    426 | call                            in groovy.lang.Closure
|     -1 | call . . . . . . . . . . . . .  in com.example.logz.LogzService$_getResultFromQuery_closure1
|    442 | call                            in groovy.lang.Closure
|     -1 | call . . . . . . . . . . . . .  in com.example.logz.LogzService$_getResultFromQuery_closure1
|     90 | doInTransaction                 in org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate$2
|    133 | execute . . . . . . . . . . . . in org.springframework.transaction.support.TransactionTemplate
|     87 | execute                         in org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate
|     -1 | getResultFromQuery . . . . . .  in com.example.logz.LogzService
|     -2 | invoke0                         in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke . . . . . . . . . . . .  in     ''
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|   1426 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     93 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.reflection.CachedMethod
|    325 | doMethodInvoke                  in groovy.lang.MetaMethod
|     -1 | call . . . . . . . . . . . . .  in groovy.lang.MetaMethod$doMethodInvoke$0
|     48 | defaultCall                     in org.codehaus.groovy.runtime.callsite.CallSiteArray
|     -1 | call . . . . . . . . . . . . .  in groovy.lang.MetaMethod$doMethodInvoke$0
|    184 | doCall                          in GrailsMelodyGrailsPlugin$_closure4$_closure16$_closure17
|     -1 | invoke . . . . . . . . . . . .  in sun.reflect.GeneratedMethodAccessor399
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|   1426 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     93 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.reflection.CachedMethod
|     84 | invoke                          in org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod
|   1121 | invokeMethod . . . . . . . . .  in groovy.lang.ExpandoMetaClass
|   1019 | invokeMethod                    in groovy.lang.MetaClassImpl
|     42 | call . . . . . . . . . . . . .  in org.codehaus.groovy.runtime.callsite.PogoMetaClassSite
|     48 | defaultCall                     in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    113 | call . . . . . . . . . . . . .  in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    125 | call                            in     ''
|    161 | findWhoEditedAllocationItems .  in com.example.sale.OfferController
|     -2 | invoke0                         in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke . . . . . . . . . . . .  in     ''
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|   1426 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|    154 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper
|    375 | handleAction                    in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|    252 | executeAction . . . . . . . . . in     ''
|    205 | handleURI                       in     ''
|    126 | handleURI . . . . . . . . . . . in     ''
|     72 | handleRequest                   in org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController
|     50 | handle . . . . . . . . . . . .  in org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
|    347 | doDispatch                      in org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
|    893 | doService . . . . . . . . . . . in org.springframework.web.servlet.DispatcherServlet
|    967 | processRequest                  in org.springframework.web.servlet.FrameworkServlet
|    858 | doGet . . . . . . . . . . . . . in     ''
|    620 | service                         in javax.servlet.http.HttpServlet
|    843 | service . . . . . . . . . . . . in org.springframework.web.servlet.FrameworkServlet
|    727 | service                         in javax.servlet.http.HttpServlet
|    303 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|     52 | doFilter . . . . . . . . . . .  in org.apache.tomcat.websocket.server.WsFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    101 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    101 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    101 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    748 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.ApplicationDispatcher
|    486 | processRequest                  in     ''
|    411 | doForward . . . . . . . . . . . in     ''
|    338 | forward                         in     ''
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke                          in     ''
|     43 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    498 | invoke                          in java.lang.reflect.Method
|   1426 | jlrMethodInvoke . . . . . . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|    150 | invoke                          in net.bull.javamelody.JspWrapper
|    285 | invoke . . . . . . . . . . . .  in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|     -1 | forward                         in com.sun.proxy.$Proxy49
|    178 | forwardRequestForUrlMappingInfo in org.codehaus.groovy.grails.web.mapping.UrlMappingUtils
|    144 | forwardRequestForUrlMappingInfo in     ''
|    135 | forwardRequestForUrlMappingInfo in     ''
|    216 | doFilterInternal                in org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    198 | doFilter                        in net.bull.javamelody.MonitoringFilter
|    176 | doFilter . . . . . . . . . . .  in     ''
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     69 | doFilterInternal                in org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     67 | doFilterInternal                in org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    449 | executeChain                    in org.apache.shiro.web.servlet.AbstractShiroFilter
|    365 | call . . . . . . . . . . . . .  in org.apache.shiro.web.servlet.AbstractShiroFilter$1
|     90 | doCall                          in org.apache.shiro.subject.support.SubjectCallable
|     83 | call . . . . . . . . . . . . .  in     ''
|    383 | execute                         in org.apache.shiro.subject.support.DelegatingSubject
|    362 | doFilterInternal . . . . . . .  in org.apache.shiro.web.servlet.AbstractShiroFilter
|    125 | doFilter                        in org.apache.shiro.web.servlet.OncePerRequestFilter
|    344 | invokeDelegate . . . . . . . .  in org.springframework.web.filter.DelegatingFilterProxy
|    261 | doFilter                        in     ''
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|     85 | doFilterInternal . . . . . . .  in org.springframework.web.filter.CharacterEncodingFilter
|    107 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    344 | invokeDelegate . . . . . . . .  in org.springframework.web.filter.DelegatingFilterProxy
|    261 | doFilter                        in     ''
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    220 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardWrapperValve
|    122 | invoke                          in org.apache.catalina.core.StandardContextValve
|    171 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardHostValve
|    103 | invoke                          in org.apache.catalina.valves.ErrorReportValve
|    116 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardEngineValve
|    408 | service                         in org.apache.catalina.connector.CoyoteAdapter
|   1070 | process . . . . . . . . . . . . in org.apache.coyote.http11.AbstractHttp11Processor
|    611 | process                         in org.apache.coyote.AbstractProtocol$AbstractConnectionHandler
|    316 | run . . . . . . . . . . . . . . in org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor
|   1142 | runWorker                       in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
|     61 | run                             in org.apache.tomcat.util.threads.TaskThread$WrappingRunnable
^    745 | run . . . . . . . . . . . . . . in java.lang.Thread
我还尝试在启动应用程序时添加标志:
-Ddeployment.security.TLSv1.2=true
,但它仍然返回相同的错误

api.logz.io
服务器的状态看起来正常:


如何使用此API?

正如支持频道中所回答的,以下java 8代码正在运行:

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {
    public static void main(String[] args) throws IOException {

        String token = "XXX";
        String url = "https://api.logz.io/v1/query";

        String query = "{ \"queryString\": \"*\" }";

        URL myurl = new URL(url);
        HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
        con.setRequestMethod("POST");

        con.setRequestProperty("Content-length", String.valueOf(query.length()));
        con.setRequestProperty("Content-Type","application/json");
        con.setRequestProperty("X-USER-TOKEN",token);
        con.setDoOutput(true);
        con.setDoInput(true);

        DataOutputStream output = new DataOutputStream(con.getOutputStream());
        output.writeBytes(query);
        output.close();

        BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
        StringBuilder sb = new StringBuilder();

        reader.lines().forEach(sb::append);

        System.out.println(sb.toString());
    }
}

因此,我认为问题在于grails,而不是支持频道中回答的Java 8,以下Java 8代码正在工作:

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {
    public static void main(String[] args) throws IOException {

        String token = "XXX";
        String url = "https://api.logz.io/v1/query";

        String query = "{ \"queryString\": \"*\" }";

        URL myurl = new URL(url);
        HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
        con.setRequestMethod("POST");

        con.setRequestProperty("Content-length", String.valueOf(query.length()));
        con.setRequestProperty("Content-Type","application/json");
        con.setRequestProperty("X-USER-TOKEN",token);
        con.setDoOutput(true);
        con.setDoInput(true);

        DataOutputStream output = new DataOutputStream(con.getOutputStream());
        output.writeBytes(query);
        output.close();

        BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
        StringBuilder sb = new StringBuilder();

        reader.lines().forEach(sb::append);

        System.out.println(sb.toString());
    }
}

所以我认为问题出在grails上,而不是Java 8上,谢谢你的提示,不过我仍然在寻找一种groovish的方法来解决它。酷。当你找到答案时更新:)@Michal_Szulc你能解决这个问题吗。我对Grails3.3.10和java8true也有同样的理解,谢谢你的提示,但是我仍然在寻找一种groovish的方法来解决它。酷。当你找到答案时更新:)@Michal_Szulc你能解决这个问题吗。我对Grails3.3.10和Java8也有同样的看法。经过进一步的调查,我怀疑这个问题可能与SNI有关,因为我们目前使用的rest通信库依赖于旧的ApacheHttpClient。更多信息:和可能的fork继任者:如果不能自由创建问题,应该能够处理这个问题,我们可以解决它。经过进一步调查,我怀疑这个问题可能与SNI有关,因为我们目前使用的rest通信的lib依赖于旧的apache httpclient。更多信息:和可能的fork继任者:应该能够处理这个问题,如果不能自由地创建一个问题,我们可以解决它。