Skip to Content

Problemas no Adapter Module

Boa tarde grupo, fiz um adapter module mas quando fui utiliza-lo no meu adapter de e-mail o mesmo me retorna o erro

MP: Exception caught with cause java.lang.NullPointerException.

Preciso de ajuda pois coloquei Audit messages para Debug e para acompanhar em que passos do codigo estava passando, mas ele dá o erro acima e não retorna nenhuma das mensagens de log.

Segue o codigo que implementei posso estar fazendo algo errado.

/*
 * Created on 05/03/2010
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package samples;
import java.rmi.RemoteException;
import java.util.Iterator;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

import com.sap.aii.af.mp.module.Module;
import com.sap.aii.af.mp.module.ModuleContext;
import com.sap.aii.af.mp.module.ModuleData;
import com.sap.aii.af.mp.module.ModuleException;
import com.sap.aii.af.ra.ms.api.Message;
import com.sap.aii.af.ra.ms.api.MessageDirection;
import com.sap.aii.af.ra.ms.api.Payload;
import com.sap.aii.af.service.auditlog.Audit;
import com.sap.aii.af.service.auditlog.AuditDirection;
import com.sap.aii.af.service.auditlog.AuditLogStatus;
import com.sap.aii.af.service.auditlog.AuditMessageKey;

/**
* @ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>
* @ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>
* @ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>
* @ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>
* @stateless
*/
public class CondenseAttachment implements SessionBean, Module {

    public void ejbCreate(){
		// TODO Auto-generated method stub
    }
	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbActivate()
	 */
	public void ejbActivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbPassivate()
	 */
	public void ejbPassivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbRemove()
	 */
	public void ejbRemove() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
	 */
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see com.sap.aii.af.mp.module.Module#process(com.sap.aii.af.mp.module.ModuleContext, com.sap.aii.af.mp.module.ModuleData)
	 */
	public ModuleData process( ModuleContext moduleContext,	ModuleData inputModuleData) throws ModuleException {

		try {
			//Declaração de Variaveis
			String content = "";
			Object obj = null;
			Message msg = null;
			AuditMessageKey amk = null;
			//OutputMessage é uma classe gerada
			
			OutputMessage parseobj = new OutputMessage();
			  obj = inputModuleData.getPrincipalData();
			  msg = (Message) obj;
			  if (msg.getMessageDirection().equals(MessageDirection.OUTBOUND))
				amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.OUTBOUND);
			  else
				amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.INBOUND);
			   Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Entrou com sucesso no ModuleBean: ");
			}
			catch (Exception e) {
			  ModuleException me = new ModuleException(e);
			  throw me;
			}

			//Le os attachments para ler o conteudo
			try {
				Iterator itr = msg.getAttachmentIterator();
				Audit.addAuditLogEntry(	amk,AuditLogStatus.SUCCESS,"Lendo anexos do Email");
				Payload payload = null;
                while (itr.hasNext()) {
					payload = (Payload) itr.next();
					String contentType = payload.getContentType();
					// Content Type traz algo como: text/plain;charset="UTF-8";name="file.txt"
					contentType = contentType.replaceAll(""","");
									int i = contentType.lastIndexOf(".") + 1;
									String extName = contentType.substring(i);
				//Checa se o arquivo lido é um xml	
				if (extName.equalsIgnoreCase("xml")) {
                    //Checa o nome do attachment e exclui o MainDocument
					if (!payload.getName().equalsIgnoreCase("MainDocument")) {
						Audit.addAuditLogEntry(	amk,AuditLogStatus.SUCCESS,"Nome do anexo: " + payload.getName());
						//calls the method to parse attachment content. 
						content = content + parseobj.parseMessage(payload.getInputStream());
					}
				}
				}
				content = content + "</MessageSplit>";
				//Creates a Text payload to set the email content.
				Message msgPrinc = (Message) inputModuleData.getPrincipalData();
				Payload payloadPric = msg.getDocument();
				payloadPric.setContent(content.getBytes("UTF-8"));
				inputModuleData.setPrincipalData(msgPrinc);
				Audit.addAuditLogEntry(amk,	AuditLogStatus.SUCCESS,	"Module encerrado com sucesso");
			} catch (Exception e) {		
				ModuleException me = new ModuleException(e);

			}
			return inputModuleData;
		}

}

Agradeço a ajuda.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Apr 20, 2010 at 12:54 PM

    O problema estava na versão do meu JDK obrigado

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Boa tarde, estou tentando implementar Adapter module, mas esta apresentando erro quando coloco a instrução OutputMessage parseobj = new OutputMessage(); o que você chama de classe gerada?

      se puder me ajudar.

      Obrigado.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.