new parse String problem

0 votes

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
asked Sep 17, 2015 in App42 Cloud API-BaaS by asasolagroup (8 points)
recategorized Sep 28, 2015 by sushil
Could you please share complete exception message which you are having in your editor console? It will help us to find the root cause of this issue.

Regards,
Himanshu Sharma
I dont haveany message in the editor console....

1 Answer

0 votes

Hello,

 

Can you comment  logger.debug("emailId is ", config.getEmailId()); from loop and see are still getting the exception. Because it seems like your custom code request doesn't comlete in 10 seconds. Please make sure, your custom code will return the response in 10 seconds.

 

Regards,

Himanshu Sharma

answered Sep 18, 2015 by hs00105 (2,005 points)
same error

 Exception :com.shephertz.app42.paas.sdk.java.App42Exception: Can not parse String :
Exception Message Can not parse String :

the problem is the

emailService.createEmailConfiguration function

if i delete this function. the program work well.

is the same error that occurred with the version of java1.8. lowering it to 1.6 everything was ok, but this function returns the error
Apologies for the delay in response. Could you please let me know is this exception coming from Java 1.6 as well or its coming only on Java 1.8 . Also, if possible then please run this method locally and print the internal logs of this method. To print the internal logs, put the below line of code before making a request of Email Service:

App42Log.setDebug(true);
 

Regards,
Himanshu Sharma
now the email is sent successfully....... but the problems do not end. Unfortunately, despite the sending it takes place with no errors I can not receive them.

I have enabled my gmail box to receive emails from external applications,

i send the email to outlook, to gmail and from otulook, from gmail address but  im not receiving it.
ok i resolved it with this permission

https://accounts.google.com/DisplayUnlockCaptcha

the email is sent and received. thank you for the help
Great to hear that your query has been resolved. Let me know if you need any other help from my side.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...