Skip to content

Instantly share code, notes, and snippets.

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;
import org.mule.util.IOUtils;
ObjectStoreManager objectStoreManager = ((ObjectStoreManager)
muleContext.getRegistry().get(MuleProperties.OBJECT_STORE_MANAGER));
ObjectStore objectStore = objectStoreManager.getObjectStore(MuleProperties.OBJECT_STORE_DEFAULT_IN_MEMORY_NAME);
@johndemic
johndemic / gist:2766264
Created May 22, 2012 03:03
Dispatching to a VM queue with MuleClient
@RequestMapping(method = RequestMethod.POST)
public void save(@RequestBody Product product) throws Exception {
muleClient.dispatch("vm://products", product, null);
}
@johndemic
johndemic / gist:2766255
Created May 22, 2012 03:01
Submit and Audit Product Data
<flow name="submitAndAuditProductDefinitions">
<vm:inbound-endpoint path="products" exchange-pattern="one-way"/>
<all>
<jms:outbound-endpoint queue="products" exchange-pattern="one-way"/>
<http:outbound-endpoint host="api.acmesoft.com" port="80" path="productAudit"
exchange-pattern="one-way"/>
</all>
</flow>
@johndemic
johndemic / gist:2766225
Created May 22, 2012 02:47
Synchronously Invoke JMS
@ResponseBody
@RequestMapping(method = RequestMethod.POST)
public Product save(@RequestBody Product product) throws Exception {
MuleMessage response = muleClient.send("jms://products", product, null, 2000);
if (response == null || response.getPayload() instanceof NullPayload) {
throw new InvalidProductResponseException();
} else {
return (Product) response.getPayload();
}
}
@johndemic
johndemic / gist:2766208
Created May 22, 2012 02:41
Dispatching Product Data to JMS
@RequestMapping(method = RequestMethod.POST)
public void save(@RequestBody Product product) throws Exception {
muleClient.dispatch("jms://products", product, null);
}
@johndemic
johndemic / gist:2766194
Created May 22, 2012 02:38
ProductController with AutoWired MuleClient
@RequestMapping("/products")
@Controller
public class ProductController {
@Autowired
MuleClient muleClient;
@RequestMapping(method = RequestMethod.POST)
public void save(@RequestBody Product product) throws Exception {
// ToDo implement code to dispatch to JMS
@johndemic
johndemic / gist:2766189
Created May 22, 2012 02:36
Wiring up MuleClient with Spring
<bean name="muleClient" class="org.mule.module.client.MuleClient" scope="singleton">
<constructor-arg value="META-INF/mule/mule-config.xml"/>
</bean>
@johndemic
johndemic / gist:2766160
Created May 22, 2012 02:34
Mule Client Mule Configuration
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:mule-xml="http://www.mulesoft.org/schema/mule/xml"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
<spring:beans>
<spring:bean name="copyInboundToOutboundPropertiesTransformer" class="org.mule.transformer.TransformerTemplate" doc:name="Bean">
<spring:constructor-arg>
<spring:bean class="org.mule.pattern.core.support.CopyInboundToOutboundPropertiesTransformerCallback"/>
</spring:constructor-arg>
</spring:bean>