我想在身份验证失败后返回401 HTTP_response。我试图通过使用下面的配置的http:response-builder组件来做到这一点。我不关心流程中的任何内容,一旦达到这一点,它需要做的就是这个。
<flow name="main" doc:name="main">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8081/example" doc:name="HTTP" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<cxf:proxy-service namespace=""
service="" payload="envelope"
wsdlLocation=""
enableMuleSoapHeaders="false" doc:name="ProxyService"/>
<cxf:proxy-client payload="envelope" enableMuleSoapHeaders="true" doc:name="ProxyClient" />
<http:outbound-endpoint exchange-pattern="request-response"
address=""
doc:name="request" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<logger message="The payload after the request is:#[payload]"
level="INFO" doc:name="Logger" />
<choice doc:name="Choice">
...
<otherwise>
<processor-chain>
<logger message="Failed authentication is:#[payload]" level="INFO"
doc:name="Logger" />
<http:response-builder status="401"
doc:name="HTTP Response Builder">
<set-payload value="Authentication Failed" />
</http:response-builder>
</processor-chain>
</otherwise>
我通过soapUI收到的错误
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Could not find a transformer to transform "SimpleDataType{type=org.mule.transport.http.HttpResponse, mimeType='text/xml'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}". (org.mule.api.transformer.TransformerException). Message payload is of type: PostMethod</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>.
对我来说这说我当前的消息是text / xml,并且它试图返回一个未知类型。我已经尝试将构建器的内容类型设置为text / xml,结果相同
编辑:当前状态为HTTP / 1.1 500内部服务器错误
非常感谢您的阅读时间和任何回复。
答案 0 :(得分:1)
您不能使用您使用它的http:response-builder
因为它的输出不会由HTTP入站端点直接处理,而是由cxf:proxy-service
处理。当响应来到下游流到入站端点时,它会命中cxf:proxy-service
,它负责准备SOAP响应:它只能处理具有SOAP有效负载的消息,并且将会严格控制状态代码,覆盖在流程中其他地方设置它的任何尝试。此外,在您的情况下,您正在构建一个非SOAP响应,这将使cxf:proxy-service
在处理响应时更加不快。
因此,诀窍是将失败登录的检测与HTTP响应的构建分开,并在流的响应阶段找到HTTP响应构建。这给出了:
<flow name="main" doc:name="main">
<http:inbound-endpoint exchange-pattern="request-response"
address="http://localhost:8081/example" doc:name="HTTP" />
<response>
<expression-filter expression="#[flowVars.authenticationFailed]" />
<http:response-builder status="401"
doc:name="HTTP Response Builder">
<set-payload value="Authentication Failed" />
</http:response-builder>
</response>
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<cxf:proxy-service namespace=""
service="" payload="envelope"
wsdlLocation=""
enableMuleSoapHeaders="false" doc:name="ProxyService"/>
<cxf:proxy-client payload="envelope" enableMuleSoapHeaders="true" doc:name="ProxyClient" />
<http:outbound-endpoint exchange-pattern="request-response"
address=""
doc:name="request" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<logger message="The payload after the request is:#[payload]"
level="INFO" doc:name="Logger" />
<set-variable variableName="authenticationFailed" value="false" />
<choice doc:name="Choice">
...
<otherwise>
<processor-chain>
<logger message="Failed authentication is:#[payload]" level="INFO"
doc:name="Logger" />
<set-variable variableName="authenticationFailed" value="true" />
</processor-chain>
</otherwise>
请注意使用流变量(名为authenticationFailed
)来控制响应。