gpt4 book ai didi

ssl - 来自 grails 应用程序的 handshake_failure

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:42 27 4
gpt4 key购买 nike

当我使用 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)

来 self 的 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 服务器的统计信息看起来正常:https://www.ssllabs.com/ssltest/analyze.html?d=api.logz.io

如何使用此 API?

最佳答案

正如支持 channel 中的回答,以下 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

关于ssl - 来自 grails 应用程序的 handshake_failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41337467/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com