Permalink
Browse files

added JAR assembly

  • Loading branch information...
1 parent 7829a85 commit 73d290168df9a46ca25492cdd349e3ae1512deec Sidney Maestre committed Sep 27, 2012
View
107 java/pom.xml 100644 → 100755
@@ -24,20 +24,13 @@
<artifactId>java-example</artifactId>
<packaging>jar</packaging>
<version>0.1.0-SNAPSHOT</version>
-
+
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <customcode.version>0.4.4</customcode.version>
+ <customcode.version>0.5.0</customcode.version>
</properties>
- <pluginRepositories>
- <pluginRepository>
- <id>onejar-maven-plugin.googlecode.com</id>
- <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
- </pluginRepository>
- </pluginRepositories>
-
<dependencies>
<dependency>
<groupId>com.stackmob</groupId>
@@ -50,50 +43,74 @@
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1.1</version>
+ </dependency>
</dependencies>
- <build>
+ <build>
<finalName>${project.artifactId}-${project.version}</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <finalName>${project.artifactId}-${project.version}-Assembled</finalName>
+ <appendAssemblyId>true</appendAssemblyId>
+ <filters>
+ <filter>src/main/filters/${env}/${build.env}/filter-common.properties</filter>
+ <filter>src/main/filters/${env}/${build.env}/filter-${user.name}.properties</filter>
+ </filters>
+ <descriptors>
+ <descriptor>src/main/assembly/distribution.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ <archive>
+ <manifest>
+ <mainClass>com.stackmob.example.EntryPointExtender</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
<archive>
<manifest>
<mainClass>com.stackmob.example.EntryPointExtender</mainClass>
</manifest>
</archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.dstovall</groupId>
- <artifactId>onejar-maven-plugin</artifactId>
- <version>1.4.4</version>
- <executions>
- <execution>
- <configuration>
- <onejarVersion>0.97</onejarVersion>
- <attachToBuild>true</attachToBuild>
- <classifier>onejar</classifier>
- </configuration>
- <goals>
- <goal>one-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
+ </configuration>
+ </plugin>
+ </plugins>
</build>
</project>
@@ -0,0 +1,28 @@
+<assembly>
+ <id>distribution</id>
+ <formats>
+ <format>jar</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/</outputDirectory>
+ <unpack>true</unpack>
+ <scope>runtime</scope>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>commons-lang:commons-lang</exclude>
+ <exclude>commons-logging:commons-logging</exclude>
+ <exclude>commons-cli:commons-cli</exclude>
+ <exclude>jsch:jsch</exclude>
+ <exclude>org.apache.maven.wagon:wagon-ssh</exclude>
+ <exclude>plexus:plexus-container-default</exclude>
+ </excludes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
No changes.
No changes.
@@ -48,6 +48,12 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
+// Added JSON parsing to handle JSON posted in the body
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
public class SendGrid implements CustomCodeMethod {
//Create your SendGrid Acct at sendgrid.com
@@ -70,6 +76,7 @@ public String getMethodName() {
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) {
int responseCode = 0;
String responseBody = "";
+ String username = "";
String body = "";
String url = "";
String to = "";
@@ -78,10 +85,23 @@ public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider
String api_key = API_KEY;
LoggerService logger = serviceProvider.getLoggerService(SendGrid.class);
-
- // username should be a valid username in the StackMob user schema
- String username = request.getParams().get("username");
-
+
+ //Log the JSON object passed to the StackMob Logs
+ logger.debug(request.getBody());
+
+ JSONParser parser = new JSONParser();
+
+ try {
+
+ Object obj = parser.parse(request.getBody());
+ JSONObject jsonObject = (JSONObject) obj;
+
+ username = (String) jsonObject.get("username");
+
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
if (username == null || username.isEmpty()) {
HashMap<String, String> errParams = new HashMap<String, String>();
errParams.put("error", "the username passed was empty or null");
@@ -199,7 +219,6 @@ public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider
Map<String, Object> map = new HashMap<String, Object>();
map.put("response_body", responseBody);
- map.put("encodedURL", url);
return new ResponseToProcess(responseCode, map);
}
View
@@ -46,96 +46,101 @@
//Create your Twilio Acct at twilio.com and enter
//Your accountsid and accesstoken below.
- static String accountsid = "YOUR_ACCOUNTSID";
- static String accesstoken = "YOUR_ACCESSTOKEN";
+ static String accountsid = "ACda54cd4d640564dc517b7001bb8934a8";
+ static String accesstoken = "49dcd6ce57c0a6fdfbad23093136b960";
@Override
public String getMethodName() {
return "twilio_sms";
}
+
@Override
public List<String> getParams() {
return Arrays.asList("tophonenumber","message");
- }
+ }
+
@Override
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) {
-
- LoggerService logger = serviceProvider.getLoggerService(TwilioSMS.class);
+
+ LoggerService logger = serviceProvider.getLoggerService(TwilioSMS.class);
- // TO phonenumber should be YOUR cell phone
- String toPhoneNumber = request.getParams().get("tophonenumber");
+ // TO phonenumber should be YOUR cel phone
+ String toPhoneNumber = request.getParams().get("tophonenumber");
- // FROM phonenumber should be one create in the Twilio dashboard at twilio.com
- String fromPhoneNumber = "YOUR_TWILIO_NUMBER";
+ // FROM phonenumber should be one create in the twilio dashboard at twilio.com
+ String fromPhoneNumber = "9259488599";
- // text message you want to send
- String message = request.getParams().get("message");
+ // text message you want to send
+ String message = request.getParams().get("message");
- if (toPhoneNumber == null || toPhoneNumber.isEmpty()) {
- logger.error("Missing to phone number");
- }
- if (message == null || message.isEmpty()) {
- logger.error("Missing message");
- }
+ if (toPhoneNumber == null || toPhoneNumber.equals("")) {
+ logger.error("Missing phone number");
+ }
- String body = "To=" + toPhoneNumber + "&From=" + fromPhoneNumber + "&Body=" + message;
+ if (message == null || message.equals("")) {
+ logger.error("Missing message");
+ }
- int responseCode = 0;
- String responseBody = "";
- String url = "https://api.twilio.com/2010-04-01/Accounts/" + accountsid + "/SMS/Messages.json";
+ String body = "To=" + toPhoneNumber + "&From=" + fromPhoneNumber + "&Body=" + message;
+
+ int responseCode = 0;
+ String responseBody = "";
+
+ String url = "https://api.twilio.com/2010-04-01/Accounts/" + accountsid + "/SMS/Messages.json";
- String pair = accountsid + ":" + accesstoken;
+ String pair = accountsid + ":" + accesstoken;
- // Base 64 Encode the accountsid/accesstoken
- byte[] b =Base64.encodeBase64(pair.getBytes());
- String encodedString = new String(b);
+ // Base 64 Encode the accountsid/accesstoken
+ byte[] b =Base64.encodeBase64(pair.getBytes());
+ String encodedString = new String(b);
- Header accept = new Header("Accept-Charset", "utf-8");
- Header auth = new Header("Authorization","Basic " + encodedString);
- Header content = new Header("Content-Type", "application/x-www-form-urlencoded");
+ Header accept = new Header("Accept-Charset", "utf-8");
+ Header auth = new Header("Authorization","Basic " + encodedString);
+ Header content = new Header("Content-Type", "application/x-www-form-urlencoded");
- Set<Header> set = new HashSet();
- set.add(accept);
- set.add(content);
- set.add(auth);
+ Set<Header> set = new HashSet();
+ set.add(accept);
+ set.add(content);
+ set.add(auth);
- try {
- HttpService http = serviceProvider.getHttpService();
+ try {
+ HttpService http = serviceProvider.getHttpService();
- PostRequest req = new PostRequest(url,set,body);
+ PostRequest req = new PostRequest(url,set,body);
- HttpResponse resp = http.post(req);
- responseCode = resp.getCode();
- responseBody = resp.getBody();
+ HttpResponse resp = http.post(req);
+ responseCode = resp.getCode();
+ responseBody = resp.getBody();
- } catch(TimeoutException e) {
- logger.error(e.getMessage(), e);
- responseCode = -1;
- responseBody = e.getMessage();
+ } catch(TimeoutException e) {
+ logger.error(e.getMessage(), e);
+ responseCode = -1;
+ responseBody = e.getMessage();
- } catch(AccessDeniedException e) {
- logger.error(e.getMessage(), e);
- responseCode = -1;
- responseBody = e.getMessage();
+ } catch(AccessDeniedException e) {
+ logger.error(e.getMessage(), e);
+ responseCode = -1;
+ responseBody = e.getMessage();
- } catch(MalformedURLException e) {
- logger.error(e.getMessage(), e);
- responseCode = -1;
- responseBody = e.getMessage();
+ } catch(MalformedURLException e) {
+ logger.error(e.getMessage(), e);
+ responseCode = -1;
+ responseBody = e.getMessage();
- } catch(ServiceNotActivatedException e) {
- logger.error(e.getMessage(), e);
- responseCode = -1;
- responseBody = e.getMessage();
- }
+ } catch(ServiceNotActivatedException e) {
+ logger.error(e.getMessage(), e);
+ responseCode = -1;
+ responseBody = e.getMessage();
+ }
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("response_body", responseBody);
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("response_body", responseBody);
return new ResponseToProcess(responseCode, map);
}
+
}

0 comments on commit 73d2901

Please sign in to comment.