0

我一直在使用 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 消息,明文连接?在 sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:156) 在 sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:868) 在 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) 在 org.apache.http.nio.reactor.ssl.SSLIOSession。

4

1 回答 1

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>
于 2017-05-19T12:49:24.827 回答