|
Mule 3.3.0 at MuleStudio 1.3.0 buildDate: 201206141902
logger retrieves:
WARN 2012-06-18 14:25:19,528 [[jiratests].jiratestsFlow1.stage1.02] org.mule.MessagePropertiesContext: Detected an attempt to get a invocation or session property, but a MuleEvent hasn't been created using this message yet. Key: issue2CloseRepoName
config xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:github="http://www.mulesoft.org/schema/mule/github" xmlns:debugger="http://www.mulesoft.org/schema/mule/debugger" xmlns:context="http://www.springframework.org/schema/context" xmlns:jira="http://www.mulesoft.org/schema/mule/jira" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" versi
on="EE-3.3.0" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/github http://www.mulesoft.org/schema/mule/github/1.0/mule-github.xsd http://www.mulesoft.org/schema/mule/debugger http://www.mulesoft.org/schema/mule/debugger/current/mule-debugger.xsd http://www.mulesoft.org/schema/mule/jira http://www.mulesoft.org/schema/mule/jira/2.0/mule-jira.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 http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd http://www.mulesoft.org/schema/mule/http s ">
<jira:config name="Jira" connectionUser="naitse" connectionPassword="Nomad83" connectionAddress="http://localhost:8668/rpc/soap/jirasoapservice-v2" doc:name="Jira"/>
<context:property-placeholder location="mule.qa.properties"/>
<github:config name="Github" user="naitse" password="Nomad83" doc:name="Github"/>
<flow name="jiratestsFlow1" doc:name="jiratestsFlow1">
<poll frequency="900000">
<jira:get-issue config-ref="Jira" issueKey="CLDCONNECT-160" doc:name="Jira"/>
</poll>
<foreach collection="payload.customFieldValues" doc:name="customFieldValues">
<logger message="#[groovy:payload.customfieldId]" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="groovy:payload.customfieldId.equals('${git.customField.repoName}')">
<processor-chain>
<message-properties-transformer overwrite="true" scope="session" doc:name="Message Properties">
<add-message-property key="issue2CloseRepoName" value="#[groovy:payload.values[0]]"/>
</message-properties-transformer>
</processor-chain>
</when>
<when expression="groovy:payload.customfieldId.equals('${git.customField.gitIssueId}')">
<processor-chain>
<message-properties-transformer overwrite="true" scope="session" doc:name="Message Properties">
<add-message-property key="issue2CloseGitIssueId" value="#[groovy:payload.values[0]]"/>
</message-properties-transformer>
</processor-chain>
</when>
<otherwise>
<processor-chain>
<logger message="bla" level="INFO" doc:name="Logger"/>
</processor-chain>
</otherwise>
</choice>
</foreach>
<logger level="INFO" doc:name="Logger"/>
<component class="HttpCloseRequest" doc:name="Java"/> <!-- that is the transformer -->
</flow>
</mule>
the transformer:
import java.net.*;
import org.mule.api.MuleMessage;
import org.mule.api.context.MuleContextAware;
import org.mule.api.transformer.TransformerException;
import org.mule.api.transport.PropertyScope;
import org.mule.transformer.AbstractMessageTransformer;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
public class HttpCloseRequest extends AbstractMessageTransformer{
<at> Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
String repoName = message.getProperty("issue2CloseRepoName" , PropertyScope.SESSION);
String gitIssueId = message.getProperty("issue2CloseGitIssueId", PropertyScope.SESSION);
String result = null;
try {
URL url = new URL("https://api.github.com/repos/naitse/" +repoName + "/issues/" + gitIssueId);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
String query = "{\"state\":\"closed\"}";
connection.setRequestProperty("Content-length",String.valueOf (query.length()));
connection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
connection.setRequestProperty("Authorization", "token "+"bfc5433b6b64bd9fd75bac21e4a88e1c3fe44f7a");
connection.setRequestProperty("Content-Type","application/json");
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
// open up the output stream of the connection
DataOutputStream output = new DataOutputStream( connection.getOutputStream() );
// write out the data
output.writeBytes( query );
output.close();
// get ready to read the response from the cgi script
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null)
{
sb.append(line);
}
rd.close();
result = sb.toString();
return result;
}
catch(Exception e)
{
return e;
}
}
}
NOTE the workarround was use the following instead of the message arg:
MuleMessage muleMessage = RequestContext.getEvent().getMessage();
|