<commit_before>package com.dreamoval.motech.omp.manager.orserve;

import com.dreamoval.motech.core.model.GatewayRequest;
import com.dreamoval.motech.core.model.GatewayResponse;
import com.dreamoval.motech.core.model.MStatus;
import com.dreamoval.motech.core.service.MotechContext;
import com.dreamoval.motech.core.util.MotechException;
import com.dreamoval.motech.omp.manager.GatewayManager;
import com.dreamoval.motech.omp.manager.GatewayMessageHandler;
import com.outreachcity.orserve.messaging.SMSMessenger;
import com.outreachcity.orserve.messaging.SMSMessengerSoap;
import java.net.URL;
import java.util.Set;
import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.util.Date;
import org.apache.log4j.Logger;

/**
 * Handles all interactions with the OutReach Server message gateway
 *
 * @author <NAME> (<EMAIL>)
 * @date Jul 15, 2009
 */
public class ORServeGatewayManagerImpl implements GatewayManager {
    private String productCode;
    private String senderId;
    private GatewayMessageHandler messageHandler;
    private static Logger logger = Logger.getLogger(ORServeGatewayManagerImpl.class);

    /**
     *
     * @see GatewayManager.send
     */
    public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails, MotechContext context) {
        String gatewayResponse;

        if(messageDetails == null)
            return null;

        logger.info("Building ORServe message gateway webservice proxy class");
        URL wsdlURL = null;
        try {
          wsdlURL = new URL("http://www.outreachcity.com/orserve/messaging/smsmessenger.asmx?WSDL");
        } catch ( MalformedURLException e ) {
          logger.error("Error creating web service client", e);
          throw new MotechException(e.getMessage());
        }
        SMSMessenger messenger = new SMSMessenger(wsdlURL, new QName("http://www.outreachcity.com/ORServe/Messaging/", "SMSMessenger"));
        SMSMessengerSoap soap = messenger.getSMSMessengerSoap();
        
        logger.info("Calling sendMessage method of ORServe message gateway");
        logger.debug(messageDetails);
        try{
            gatewayResponse = soap.sendMessage(messageDetails.getMessage(), messageDetails.getRecipientsNumber(), getSenderId(), getProductCode(), String.valueOf(messageDetails.getGatewayRequestDetails().getNumberOfPages()));
        }
        catch(Exception ex){
            logger.error("Error sending message", ex);
            throw new MotechException(ex.getMessage());
        }
        messageDetails.setDateSent(new Date());
        
        logger.info("Parsing gateway response");
        return messageHandler.parseMessageResponse(messageDetails, gatewayResponse, context);
    }

    /**
     *
     * @see GatewayManager.getMessageStatus
     */
    public String getMessageStatus(GatewayResponse response) {
        String gatewayResponse;<commit_msg>Handled errors during creation or ORServe ateway webservice client<commit_after>package com.dreamoval.motech.omp.manager.orserve;

import com.dreamoval.motech.core.model.GatewayRequest;
import com.dreamoval.motech.core.model.GatewayResponse;
import com.dreamoval.motech.core.model.MStatus;
import com.dreamoval.motech.core.service.MotechContext;
import com.dreamoval.motech.core.util.MotechException;
import com.dreamoval.motech.omp.manager.GatewayManager;
import com.dreamoval.motech.omp.manager.GatewayMessageHandler;
import com.outreachcity.orserve.messaging.SMSMessenger;
import com.outreachcity.orserve.messaging.SMSMessengerSoap;
import java.net.URL;
import java.util.Set;
import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.util.Date;
import org.apache.log4j.Logger;

/**
 * Handles all interactions with the OutReach Server message gateway
 *
 * @author <NAME> (<EMAIL>)
 * @date Jul 15, 2009
 */
public class ORServeGatewayManagerImpl implements GatewayManager {
    private String productCode;
    private String senderId;
    private GatewayMessageHandler messageHandler;
    private static Logger logger = Logger.getLogger(ORServeGatewayManagerImpl.class);

    /**
     *
     * @see GatewayManager.send
     */
    public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails, MotechContext context) {
        String gatewayResponse;

        if(messageDetails == null)
            return null;

        logger.info("Building ORServe message gateway webservice proxy class");
        URL wsdlURL = null;
        try {
          wsdlURL = new URL("http://www.outreachcity.com/orserve/messaging/smsmessenger.asmx?WSDL");
        } catch ( MalformedURLException e ) {
          logger.error("Error creating web service client", e);
          throw new MotechException(e.getMessage());
        }
        
        logger.info("Calling sendMessage method of ORServe message gateway");
        logger.debug(messageDetails);
        try{
            SMSMessenger messenger = new SMSMessenger(wsdlURL, new QName("http://www.outreachcity.com/ORServe/Messaging/", "SMSMessenger"));
            SMSMessengerSoap soap = messenger.getSMSMessengerSoap();
            gatewayResponse = soap.sendMessage(messageDetails.getMessage(), messageDetails.getRecipientsNumber(), getSenderId(), getProductCode(), String.valueOf(messageDetails.getGatewayRequestDetails().getNumberOfPages()));
        }
        catch(Exception ex){
            logger.error("Error sending message", ex);
            throw new MotechException(ex.getMessage());
        }
        messageDetails.setDateSent(new Date());
        
        logger.info("Parsing gateway response");
        return messageHandler.parseMessageResponse(messageDetails, gatewayResponse, context);
    }

    /**
     *
     * @see GatewayManager.getMessageStatus
     */
    public String getMessageStatus(GatewayResponse response) {
        String gatewayResponse;
{'fraction_non_alphanumeric': 0.09830450419592396, 'fraction_numerical': 0.002397670834046926, 'mean_word_length': 3.653386454183267, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1095261', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1591, 'n_words': 323}