{"action":"created","comment":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/comments/45475452","id":45475452,"diff_hunk":"@@ -0,0 +1,486 @@\n+/*\n+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com\n+ * The software in this package is published under the terms of the CPAL v1.0\n+ * license, a copy of which has been included with this distribution in the\n+ * LICENSE.txt file.\n+ */\n+package org.mule;\n+\n+import static org.mule.api.transport.PropertyScope.INBOUND;\n+import org.mule.api.MuleContext;\n+import org.mule.api.MuleEvent;\n+import org.mule.api.MuleException;\n+import org.mule.api.MuleMessage;\n+import org.mule.api.MuleRuntimeException;\n+import org.mule.api.transformer.Converter;\n+import org.mule.api.transformer.DataType;\n+import org.mule.api.transformer.MessageTransformer;\n+import org.mule.api.transformer.Transformer;\n+import org.mule.api.transformer.TransformerException;\n+import org.mule.api.transformer.TransformerMessagingException;\n+import org.mule.api.transport.PropertyScope;\n+import org.mule.config.i18n.CoreMessages;\n+import org.mule.transformer.TransformerUtils;\n+import org.mule.transformer.types.DataTypeFactory;\n+import org.mule.transformer.types.MimeTypes;\n+\n+import java.io.InputStream;\n+import java.util.Arrays;\n+import java.util.List;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+\n+public class TransformationService\n+{\n+\n+    private static final Log logger = LogFactory.getLog(TransformationService.class);\n+\n+    private MuleContext muleContext;\n+\n+    public TransformationService(MuleContext muleContext)\n+    {\n+        this.muleContext = muleContext;\n+    }\n+\n+    /**\n+     * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the\n+     * message. This method provides the only way to alter the paylaod of this message without recreating a\n+     * copy of the message\n+     * @param event the event being processed\n+     * @param transformers the transformers to apply to the message payload\n+     * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a\n+     * are incompatible with the message payload\n+     */\n+    public void applyTransformers(MuleMessage message, MuleEvent event, List<? extends Transformer> transformers) throws MuleException\n+    {\n+        applyTransformers(message, event, transformers, null);\n+    }\n+\n+    /**\n+     * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the\n+     * message. This method provides the only way to alter the paylaod of this message without recreating a\n+     * copy of the message\n+     * @param event the event being processed\n+     * @param transformers the transformers to apply to the message payload\n+     * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a\n+     * are incompatible with the message payload\n+     */\n+    public void applyTransformers(MuleMessage message, MuleEvent event, Transformer... transformers) throws MuleException\n+    {\n+        applyTransformers(message, event, Arrays.asList(transformers), null);\n+    }\n+\n+    /**\n+     * Will apply a list of transformers to the payload of the message. This *Will* change the payload of the\n+     * message. This method provides the only way to alter the paylaod of this message without recreating a\n+     * copy of the message\n+     * @param event the event being processed\n+     * @param transformers the transformers to apply to the message payload\n+     * @param outputType the required output type for this transformation. by adding this parameter some additional\n+     * transformations will occur on the message payload to ensure that the final payload is of the specified type.\n+     * If no transformers can be found in the registry that can transform from the return type of the transformation\n+     * list to the outputType and exception will be thrown\n+     * @throws TransformerException if a transformation error occurs or one or more of the transformers passed in a\n+     * are incompatible with the message payload\n+     */\n+    public void applyTransformers(MuleMessage message, MuleEvent event, List<? extends Transformer> transformers, Class<?> outputType) throws MuleException\n+    {\n+        if (!transformers.isEmpty())\n+        {\n+            applyAllTransformers(message, event, transformers);\n+        }\n+\n+        if (null != outputType && !message.getPayload().getClass().isAssignableFrom(outputType))\n+        {\n+            message.setPayload(getPayload(message, DataTypeFactory.create(outputType)));\n+        }\n+    }\n+\n+\n+    /**\n+     * Will attempt to obtain the payload of this message with the desired Class type. This will\n+     * try and resolve a transformer that can do this transformation. If a transformer cannot be found\n+     * an exception is thrown.  Any transformers added to the registry will be checked for compatibility\n+     * @param outputType the desired return type\n+     * @return The converted payload of this message. Note that this method will not alter the payload of this\n+     * message *unless* the payload is an InputStream in which case the stream will be read and the payload will become\n+     * the fully read stream.\n+     * @throws TransformerException if a transformer cannot be found or there is an error during transformation of the\n+     * payload\n+     */\n+    public <T> T getPayload(MuleMessage message, Class<T> outputType) throws TransformerException\n+    {\n+        return getPayload(message, DataTypeFactory.create(outputType), message.getEncoding());\n+    }\n+\n+    /**\n+     * Will attempt to obtain the payload of this message with the desired Class type. This will\n+     * try and resolve a transformer that can do this transformation. If a transformer cannot be found\n+     * an exception is thrown.  Any transformers added to the registry will be checked for compatability\n+     * @param outputType the desired return type\n+     * @return The converted payload of this message. Note that this method will not alter the payload of this\n+     * message *unless* the payload is an InputStream in which case the stream will be read and the payload will become\n+     * the fully read stream.\n+     * @throws TransformerException if a transformer cannot be found or there is an error during transformation of the\n+     * payload\n+     */\n+    public <T> T getPayload(MuleMessage message, DataType<T> outputType) throws TransformerException\n+    {\n+        return getPayload(message, outputType, message.getEncoding());\n+    }\n+\n+    /**\n+     * Converts the message implementation into a String representation. If encoding\n+     * is required it will use the encoding set on the message\n+     *\n+     * @return String representation of the message payload\n+     * @throws Exception Implementation may throw an endpoint specific exception\n+     *\n+     */\n+    public final String getPayloadAsString(MuleMessage message) throws Exception\n+    {\n+        return getPayloadAsString(message, message.getEncoding());\n+    }\n+\n+    /**\n+     * Get the message payload for logging without throwing exception","path":"core/src/main/java/org/mule/TransformationService.java","position":147,"original_position":147,"commit_id":"400a796ebbd4a10ccc8ccfcad6931957d286f39d","original_commit_id":"400a796ebbd4a10ccc8ccfcad6931957d286f39d","user":{"login":"pablokraan","id":561399,"avatar_url":"https://avatars.githubusercontent.com/u/561399?v=3","gravatar_id":"","url":"https://api.github.com/users/pablokraan","html_url":"https://github.com/pablokraan","followers_url":"https://api.github.com/users/pablokraan/followers","following_url":"https://api.github.com/users/pablokraan/following{/other_user}","gists_url":"https://api.github.com/users/pablokraan/gists{/gist_id}","starred_url":"https://api.github.com/users/pablokraan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pablokraan/subscriptions","organizations_url":"https://api.github.com/users/pablokraan/orgs","repos_url":"https://api.github.com/users/pablokraan/repos","events_url":"https://api.github.com/users/pablokraan/events{/privacy}","received_events_url":"https://api.github.com/users/pablokraan/received_events","type":"User","site_admin":false},"body":"Get > Gets","created_at":"2015-11-20T14:45:07Z","updated_at":"2015-11-20T14:45:07Z","html_url":"https://github.com/mulesoft/mule/pull/2169#discussion_r45475452","pull_request_url":"https://api.github.com/repos/mulesoft/mule/pulls/2169","_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments/45475452"},"html":{"href":"https://github.com/mulesoft/mule/pull/2169#discussion_r45475452"},"pull_request":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2169"}}},"pull_request":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/2169","id":51073174,"html_url":"https://github.com/mulesoft/mule/pull/2169","diff_url":"https://github.com/mulesoft/mule/pull/2169.diff","patch_url":"https://github.com/mulesoft/mule/pull/2169.patch","issue_url":"https://api.github.com/repos/mulesoft/mule/issues/2169","number":2169,"state":"open","locked":false,"title":"MULE-9068 Remove transformation methods from MuleMessage","user":{"login":"dfeist","id":380765,"avatar_url":"https://avatars.githubusercontent.com/u/380765?v=3","gravatar_id":"","url":"https://api.github.com/users/dfeist","html_url":"https://github.com/dfeist","followers_url":"https://api.github.com/users/dfeist/followers","following_url":"https://api.github.com/users/dfeist/following{/other_user}","gists_url":"https://api.github.com/users/dfeist/gists{/gist_id}","starred_url":"https://api.github.com/users/dfeist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfeist/subscriptions","organizations_url":"https://api.github.com/users/dfeist/orgs","repos_url":"https://api.github.com/users/dfeist/repos","events_url":"https://api.github.com/users/dfeist/events{/privacy}","received_events_url":"https://api.github.com/users/dfeist/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-18T11:35:11Z","updated_at":"2015-11-20T14:45:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"134fa9a259b7f527f7972712c87aafeedeaa34d7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mulesoft/mule/pulls/2169/commits","review_comments_url":"https://api.github.com/repos/mulesoft/mule/pulls/2169/comments","review_comment_url":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mulesoft/mule/issues/2169/comments","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/400a796ebbd4a10ccc8ccfcad6931957d286f39d","head":{"label":"mulesoft:MULE-9068","ref":"MULE-9068","sha":"400a796ebbd4a10ccc8ccfcad6931957d286f39d","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","created_at":"2012-12-07T19:23:06Z","updated_at":"2015-11-20T03:40:20Z","pushed_at":"2015-11-20T14:16:23Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":177195,"stargazers_count":251,"watchers_count":251,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":298,"mirror_url":null,"open_issues_count":19,"forks":298,"open_issues":19,"watchers":251,"default_branch":"mule-3.x"}},"base":{"label":"mulesoft:mule-4.x","ref":"mule-4.x","sha":"d0deb41e954bac187ad99ebff7780433e3ea17de","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","created_at":"2012-12-07T19:23:06Z","updated_at":"2015-11-20T03:40:20Z","pushed_at":"2015-11-20T14:16:23Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":177195,"stargazers_count":251,"watchers_count":251,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":298,"mirror_url":null,"open_issues_count":19,"forks":298,"open_issues":19,"watchers":251,"default_branch":"mule-3.x"}},"_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2169"},"html":{"href":"https://github.com/mulesoft/mule/pull/2169"},"issue":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2169"},"comments":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2169/comments"},"review_comments":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2169/comments"},"review_comment":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2169/commits"},"statuses":{"href":"https://api.github.com/repos/mulesoft/mule/statuses/400a796ebbd4a10ccc8ccfcad6931957d286f39d"}}}}