i have a new problem with i add a email service to my custom code.
this is a simple
MyCustomCode.java
package com.shephertz.app42.paas.customcode.sample;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import com.shephertz.app42.paas.customcode.Executor;
import com.shephertz.app42.paas.customcode.HttpRequestObject;
import com.shephertz.app42.paas.customcode.HttpResponseObject;
import com.shephertz.app42.paas.sdk.java.ServiceAPI;
import com.shephertz.app42.paas.sdk.java.log.LogService;
import com.shephertz.app42.paas.customcode.sample.EmailConfig;
public class MyCustomCode implements Executor {
private ServiceAPI sp = new ServiceAPI(
XXXX,
XXXX
);
private final int HTTP_STATUS_SUCCESS = 200;
private String moduleName = "App42CustomCodeTest";
private EmailConfig emailConfig = null;
public MyCustomCode()
{
emailConfig = new EmailConfig(sp);
}
/**
* Write your custom code inside this method
*/
@Override
public HttpResponseObject execute(HttpRequestObject request) {
JSONObject body = request.getBody();
JSONObject jsonResponse = new JSONObject();
try {
jsonResponse.put("name", "App42CustomCodeTest");
//....//
//....//
} catch (JSONException e) {
// Do exception Handling for JSON Parsing
}
return new HttpResponseObject(HTTP_STATUS_SUCCESS, body);
}
}
EmailConfig.java
package com.shephertz.app42.paas.customcode.sample;
import java.util.ArrayList;
import com.shephertz.app42.paas.sdk.java.ServiceAPI;
import com.shephertz.app42.paas.sdk.java.email.Email;
import com.shephertz.app42.paas.sdk.java.email.EmailService;
import com.shephertz.app42.paas.sdk.java.log.LogService;
public class EmailConfig {
String emailHost = "smtp.gmail.com";
int emailPort = 465;
String emailId = "xxxxxx@gmail.com";
String password = "jfvfhkvff";
boolean isSSL = true;
Email email = null;
public EmailConfig(ServiceAPI sp){
LogService logger = sp.buildLogService();
EmailService emailService = sp.buildEmailService();
email = emailService.createMailConfiguration(
emailHost,
emailPort,
emailId,
password,
isSSL
);
ArrayList<Email.Configuration> configList = email.getConfigList();
for(Email.Configuration config : configList)
{
logger.debug("emailId is ", config.getEmailId());
logger.debug("Host is ", config.getHost());
logger.debug("Port is ", config.getPort().toString());
logger.debug("SSL is ", config.getSsl().toString());
}
String jsonResponse = email.toString();
}
public ArrayList<Email.Configuration> getConfigList()
{
return email.getConfigList();
}
}
TestMyCustomCode.java
/**
*
*/
package com.myapp;
import java.util.HashMap;
import org.json.JSONObject;
import com.shephertz.app42.paas.customcode.Executor;
import com.shephertz.app42.paas.customcode.HttpRequestObject;
import com.shephertz.app42.paas.customcode.sample.MyCustomCode;
import com.shephertz.app42.paas.sdk.java.App42API;
import com.shephertz.app42.paas.sdk.java.App42CallBack;
import com.shephertz.app42.paas.sdk.java.ServiceAPI;
import com.shephertz.app42.paas.sdk.java.customcode.CustomCodeService;
/**
* Local Setup Tester
* @author Ajay Tiwari
*
*/
public class TestMyCustomCode {
/**
* Sets the param and body and call the execute method for test
* @throws Exception
*/
public static void testMyCodeInCloud() throws Exception {
String apiKey = "XXXX";
String secretKey = "XXXX";
ServiceAPI sp = new ServiceAPI(apiKey, secretKey);
CustomCodeService customCodeService = sp.buildCustomCodeService();
String name = "customcode";
JSONObject requestJSON = new JSONObject();
requestJSON.put("user", "demo");
customCodeService.runJavaCode(name, requestJSON, new App42CallBack() {
public void onSuccess(Object response)
{
JSONObject res= (JSONObject)response;
System.out.println("response is " + res) ;
}
public void onException(Exception ex)
{
System.out.println("Exception Message " + ex.getMessage());
}
});
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
testMyCodeInCloud();
}
}
i received the error Exception Message Can not parse String :
after several attempts I have established the source of the error. this function in the EmailConfig.java
email = emailService.createMailConfiguration(emailHost, emailPort, emailId, password, isSSL);
if i delete it, the program work well but I do not know how to fix it