我一直在使用Citrus作为我的自动化框架并遇到了这个问题。
我正在调用一个Web服务,它通过https调用调用另一个服务器来获取访问令牌。我想使用静态端点适配器对getToken的响应进行硬编码。
我的代码:
http().client(BPS_Create_Customer_PS_endpoint)
.send()
.post()
.contentType("application/soap+xml;charset=UTF-8")
.fork(true)
.payload(new ClassPathResource("BPS_Create_Requests/valid.xml"));
// HardCoded response withing context.xml will be sent first for getToken request
// For Second call from BPS should come here and respond
http().server(Server)
.receive()
.get()
.contentType("application/json;charset=UTF-8");
http().server(Server)
.send()
.response()
.contentType("application/json;charset=UTF-8")
.payload(new ClassPathResource("Output/valid.json"));
http().server(BS_Customer)
.receive()
.post("/services/BS-Customer-PS")
.contentType("application/soap+xml;charset=UTF-8");
http().server(BS_Customer)
.send()
.response()
.withApplicationContext(applicationContext)
.contentType("application/soap+xml;charset=UTF-8;action='urn:mediate'")
.payload(new ClassPathResource("BS_Mock_Outputs/createCustomerResponse.xml"));
http().client(BPS_Create_Customer_UW_PS_endpoint)
.receive()
.response(HttpStatus.OK)
.payload(new ClassPathResource("BPS_Create_Responses/valid.xml"));
Context.xml文件
<citrus-http:client id="BPS_Create_Customer_PS_endpoint"
request-url="${Server_Endpoint}/services/BPS-Create-Customer-UW-PS.BPS-Create-Customer-UW-PSHttpSoap12Endpoint"
timeout="30000"/>
<citrus-http:server id="BS_Customer"
port="8085"
auto-start="true"/>
<citrus-http:server id="Server"
port="8092"
auto-start="true"/>
<citrus-http:server id="Token"
port="8091"
auto-start="true"
endpoint-adapter="getToken"/>
<citrus:static-response-adapter id="getToken">
<citrus:payload>
<![CDATA[]
{
"access_token": "00D0k000000Cp3S!ARIAQCFUdlJgqeZF_wh_Ifc6YOf7bHqnlRKN3l5ZNWXMLEqZk5lXqAogfKPZVx7E5UV9UKushYCzup7X",
"instance_url": "https://ValidURL",
"id": "https://ValidURL/id/00D023/0050k000000E3SqAAK",
"token_type": "Bearer",
"issued_at": "1494984553384",
"signature": "t7VDcWe8oJDR/6ZzfllrOK2QI1OXg5S9OUoc="
}
]]>
</citrus:payload>
<citrus:header>
<citrus:element name="content-type" value="application/json"/>
<citrus:element name="charset" value="UTF-8"/>
<citrus:element name="content-security-policy" value="reflected-xss block;report-uri /_/ContentDomainCSPNoAuth?type=xss"/>
<citrus:element name="content-Encoding" value="gzip"/>
<citrus:element name="Authorization" value="Bearer 0b79bab50daca910b000d4f1a2b675d604257e42"/>
</citrus:header>
</citrus:static-response-adapter>
错误:
TID:[ - 1] [] [2017-05-17 12:33:27,726]错误{org.apache.synapse.transport.passthru.TargetHandler} - I / O错误:无法识别的SSL消息,明文连接? {} org.apache.synapse.transport.passthru.TargetHandler javax.net.ssl.SSLException:无法识别的SSL消息,明文连接? at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:156) at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:868) at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781) 在javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) 在org.apache.http.nio.reactor.ssl.SSLIOSession.doUnwrap(SSLIOSession.java:245) 在org.apache.http.nio.reactor.ssl.SSLIOSession.doHandshake(SSLIOSession.java:280) at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:410) 在org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:119) at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:159) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316) 在org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277) 在org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor $ Worker.run(AbstractMultiworkerIOReactor.java:586) 在java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
您的令牌http服务器应该使用ssl连接器,如下所示:
<citrus-http:server id="Token"
connector="sslConnector"
endpoint-adapter="getToken"
auto-start="true"/>
<bean id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg>
<bean class="org.eclipse.jetty.server.Server"></bean>
</constructor-arg>
<constructor-arg>
<list>
<bean class="org.eclipse.jetty.server.SslConnectionFactory">
<constructor-arg>
<bean class="org.eclipse.jetty.util.ssl.SslContextFactory">
<property name="keyStorePath" value="/path/to/keystore.jks"/>
<property name="keyStorePassword" value="secret"/>
</bean>
</constructor-arg>
<constructor-arg value="http/1.1"/>
</bean>
<bean class="org.eclipse.jetty.server.HttpConnectionFactory">
<constructor-arg>
<bean class="org.eclipse.jetty.server.HttpConfiguration">
<constructor-arg>
<bean class="org.eclipse.jetty.server.HttpConfiguration">
<property name="secureScheme" value="https"/>
<property name="securePort" value="8443"/>
</bean>
</constructor-arg>
<property name="customizers">
<list>
<bean class="org.eclipse.jetty.server.SecureRequestCustomizer"/>
</list>
</property>
</bean>
</constructor-arg>
</bean>
</list>
</constructor-arg>
<property name="port" value="8443" />
</bean>