/** * @param $toPartner * @param $fromPartner * @param $messageContent * @throws \Exception * @throws \TechData\AS2SecureBundle\Models\AS2Exception * @throws \TechData\AS2SecureBundle\Models\Exception */ public function sendMessage($toPartner, $fromPartner, $messageContent) { // process request to build outbound AS2 message to VAR // initialize outbound AS2Message object $message = $this->messageFactory->build(false, array('partner_from' => $fromPartner, 'partner_to' => $toPartner)); // initialize AS2Adapter for public key encryption between StreamOne and the receiving VAR $adapter = $this->adapterFactory->build($fromPartner, $toPartner); // write the EDI message that will be sent to a temp file, then use the AS2 adapter to encrypt it $tmp_file = $adapter->getTempFilename(); file_put_contents($tmp_file, $messageContent); $message->addFile($tmp_file, 'application/edi-x12'); $message->encode(); // send AS2 message $result = $this->client->sendRequest($message); $messageSent = new MessageSent(); $messageSent->setMessage(print_r($result, true)); $this->eventDispatcher->dispatch(MessageSent::EVENT, $messageSent); }
/** * Save the content of the request for futur handle and/or backup * * @param content The content to save (mandatory) * @param headers The headers to save (optional) * @param type Values : raw | decrypted | payload (mandatory) * * @return String : The main filename */ protected function saveMessage($content, $headers, $type = 'raw') { $message = new MessageSent(); $message->setMessage($content); $message->setHeaders($headers); $message->setMessageType($type); $this->eventDispatcher->dispatch('messageSent', $message); }