Skip to content

Instantly share code, notes, and snippets.

@pjmuley
pjmuley / mysql.xml
Created July 25, 2016 22:23
MySQL Dependency
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-cxf</artifactId>
<version>${mule.version}</version>
</dependency>
<dependency>
<groupId>com.mulesoft.weave</groupId>
<artifactId>mule-plugin-weave</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.mulesoft.com/schemas/Mule/Schema.xsd"><soapenv:Header/><soapenv:Body><sch:getLoanRequest xmlns:sch="http://www.mulesoft.com/schemas/Mule/Schema.xsd"><sch:loanId>102</sch:loanId></sch:getLoanRequest></soapenv:Body></soapenv:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns0:getLoanResponse xmlns:ns0="http://www.mulesoft.com/schemas/Mule/Schema.xsd">
<ns0:loanList>
<ns0:loan>
<ns0:loanId>102</ns0:loanId>
<ns0:customerId>2</ns0:customerId>
<ns0:loanType>auto</ns0:loanType>
<ns0:loanAmount>33436.49</ns0:loanAmount>
<ns0:monthlyPayment>676.48</ns0:monthlyPayment>
<ns0:interestRate>12.56</ns0:interestRate>
</ns0:loan>
String client_id="85b56xxxxxxxxxxxxxxxxxxxxxxxxxb968fd";
String client_secret="2B792xxxxxxxxxxxxxxxxxxxxxx3B3b1";
String authURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/authorize";
// Get access token required for publish/subscribe API's
Client client = Client.create();
WebResource webResource = client.resource(authURI);
String input = "client_id="+client_id+"&client_secret="+client_secret+"&grant_type=client_credentials";
ClientResponse response = webResource.header("Content-Type", "application/x-www-form-urlencoded")
.accept("application/json")
.post(ClientResponse.class, input);
String queueName="myQueue";
String queueMessage="This is my test message";
String brokerURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/organizations/";
brokerURI = brokerURI + orgId +"/environments/"+ envId +"/destinations/"+ queueName+"/messages";
// Post message to existing queue using API
String messageId=UUID.randomUUID().toString();
String postURI=brokerURI+"/"+messageId;
System.out.println(postURI);
String queueName="myQueue";
String queueMessage="This is my test message";
String brokerURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/organizations/";
brokerURI = brokerURI + orgId +"/environments/"+ envId +"/destinations/"+ queueName+"/messages";
// Get message from existing queue using API
WebResource webResourceGet = client.resource(brokerURI);
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("poolingTime","10000");
String queueName="myQueue";
String queueMessage="This is my test message";
String brokerURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/organizations/";
brokerURI = brokerURI + orgId +"/environments/"+ envId +"/destinations/"+ queueName+"/messages";
// Post message to existing queue using API
String messageId=UUID.randomUUID().toString();
String postURI=brokerURI+"/"+messageId;
System.out.println(postURI);
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.util.UUID;