0

我在 mule config xml 中有一个变量,我想在 Java 文件中访问它。我怎么做?我找到以下方法:

  • 使用组件
  • 使用变压器
  • 使用脚本,例如 groovy

我想将该变量发送到 java 文件,并将其导入到 java 文件中的数据库。我的配置是:

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
    http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
    http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd ">

<set-variable variableName="remoteClientAddress"
    value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
<message-properties-transformer name="setProperty"
    scope="session" doc:name="Message Properties">
    <add-message-property key="remoteClientAddress"
        value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
</message-properties-transformer>


<flow name="service-cxf-wsdlfirstFlow1" doc:name="service-cxf-wsdlfirstFlow1">
    <http:inbound-endpoint host="localhost" port="8085"
        path="Weather/Service" exchange-pattern="request-response" doc:name="HTTP">
    </http:inbound-endpoint>
    <set-variable variableName="remoteClientAddress"
        value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
    <message-properties-transformer doc:name="myproperty"
        scope="session">
        <add-message-property key="remoteClientAddress"
            value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
    </message-properties-transformer>

    <component doc:name="classTest" class="org.mule.example.scripting.IpClient" />

    <logger
        message="#[groovy:message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS')]"
        level="INFO" doc:name="Logger" />
    <cxf:proxy-service payload="envelope" service="Weather"
        wsdlLocation="http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
        namespace="http://ws.cdyne.com/WeatherWS/" validationEnabled="true"
        doc:name="SOAP">
    </cxf:proxy-service>

    <copy-properties propertyName="SOAPAction" doc:name="Property" />

    <cxf:proxy-client payload="body"
        enableMuleSoapHeaders="true" doc:name="SOAP" />

    <outbound-endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
        exchange-pattern="request-response" doc:name="Generic">
    </outbound-endpoint>


</flow>

我的骡子版本是 CE 3.3.0。我使用组件来定义 java 类的位置,但是在运行我的项目后我有一些错误:

ERROR 2013-02-27 11:15:20,129 [[mule-sample_].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 

Message               : Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
]
Code                  : MULE_ERROR-321
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
] (org.mule.model.resolvers.EntryPointNotFoundException)
org.mule.model.resolvers.DefaultEntryPointResolverSet:52 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/model/resolvers/EntryPointNotFoundException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
]
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:52)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:343)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:86)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
4

2 回答 2

1

根据 eoyu 给出的添加属性

<set-variable variableName="remoteClientAddress" value ="#[message.inboundProperties    ['MULE_REMOTE_CLIENT_ADDRESS']]"/>

这会将属性设置为 INVOCATION 范围内的 mulemessage。

您可以使用以下代码行访问 IpClient 组件中的属性

  msg.getProperty("remoteClientAddress", PropertyScope.INVOCATION);

前任:

@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
    MuleMessage msg = eventContext.getMessage();

    String remClient = msg.getProperty("remoteClientAddress", PropertyScope.INVOCATION);

希望这可以帮助。

于 2013-02-27T14:41:36.897 回答
0
<message-properties-transformer name="myScope"  scope="session">
    <add-message-property key="remoteClientAddress"
        value ="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
</message-properties-transformer>
于 2013-02-27T06:21:56.400 回答