-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to scalaxb for SOAP WSDL parsing
As noted in #327, it looks like`salesforce-message-handler` needs to drop sbt-cxf to work with versions of Java newer than Java 8 (the JAXB library is no longer a core part of Java). `scalaxb` (https://github.com/eed3si9n/scalaxb) looks like a good replacement for `sbt-cxf`/[`wsdl2java`](https://cxf.apache.org/docs/wsdl-to-java.html), it's maintained and has Scala-specific support: https://index.scala-lang.org/eed3si9n/scalaxb/artifacts/scalaxb The generated classes created by `scalaxb` are pretty similar to the ones generated by `wsdl2java`, there was just a small wrinkle with nillable id fields, which was not too hard to cope with.
- Loading branch information
Showing
10 changed files
with
98 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=1.5.8 | ||
sbt.version=1.9.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") | ||
|
||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3") | ||
|
||
addSbtPlugin("io.dapas" % "sbt-cxf" % "0.2.0") | ||
addSbtPlugin("org.scalaxb" % "sbt-scalaxb" % "1.12.0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/scala/com/gu/salesforce/messageHandler/QueueMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.gu.salesforce.messageHandler | ||
|
||
import play.api.libs.json.{Format, Json} | ||
|
||
case class QueueMessage(contactId: String) | ||
|
||
object QueueMessage { | ||
implicit val messageFormat: Format[QueueMessage] = Json.format[QueueMessage] | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/scala/com/gu/salesforce/messageHandler/SOAPNotificationsParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.gu.salesforce.messageHandler | ||
|
||
import salesforce.soap.Notifications | ||
import scalaxb._ | ||
import soapenvelope11.Envelope | ||
|
||
import scala.xml.{Elem, XML} | ||
|
||
object SOAPNotificationsParser { | ||
|
||
/** | ||
* Given a 'notifications' request from Salesforce (which comes embedded in a SOAP Envelope), extract the | ||
* 'Notifications' object. | ||
* | ||
* https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_om_outboundmessaging_wsdl.htm | ||
*/ | ||
def parseMessage(soapRequestEnvelope: String): Notifications = { | ||
val envelope: Envelope = fromXML[soapenvelope11.Envelope](XML.loadString(soapRequestEnvelope)) | ||
|
||
val notificationsXml = envelope.Body.any.collect({ | ||
case DataRecord(_, _, x: Elem) if x.label != "Fault" => x | ||
}).head | ||
|
||
fromXML[Notifications](notificationsXml) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<soapenv:Body> | ||
<notifications xmlns="http://soap.sforce.com/2005/09/outbound"> | ||
<OrganizationId>someOrganizationId</OrganizationId> | ||
<ActionId>SomeActionId</ActionId> | ||
<SessionId xsi:nil="true"/> | ||
<EnterpriseUrl>someEnterpriseUrl</EnterpriseUrl> | ||
<PartnerUrl>somePartnerUrl</PartnerUrl> | ||
<Notification> | ||
<Id>notificationID</Id> | ||
<sObject xsi:type="sf:Contact" xmlns:sf="urn:sobject.enterprise.soap.sforce.com"> | ||
<sf:Id>aContactId</sf:Id> | ||
</sObject> | ||
</Notification> | ||
</notifications> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |
18 changes: 18 additions & 0 deletions
18
src/test/scala/com/gu/salesforce/messageHandler/SOAPNotificationsParserTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.gu.salesforce.messageHandler | ||
|
||
import com.amazonaws.util.IOUtils | ||
import salesforce.soap.Notifications | ||
import org.specs2.mutable.Specification | ||
|
||
class SOAPNotificationsParserTest extends Specification { | ||
def getTestString(fileName: String) = IOUtils.toString(getClass.getResourceAsStream(s"/$fileName")) | ||
|
||
"Parser" should { | ||
"parse a SOAP message" in { | ||
val notifications: Notifications = | ||
SOAPNotificationsParser.parseMessage(getTestString("soapNotificationsRequest.xml")) | ||
|
||
notifications.Notification.head.sObject.Id must beSome("aContactId") | ||
} | ||
} | ||
} |