Test de point de terminaison SOAP par JUnit lance SAXParseException (soapenv: Enveloppe)

StackOverflow https://stackoverflow.com/questions/1687762

Question

J'ai essaye de mettre en œuvre des tests d'intégration pour une application de travail (printemps, mise en veille prolongée, du savon, CxF). Je construis un SOAP-XML à la main et la poignée à mon point final. Comme ceci:

private Source createRequest(String domainName, String email, String userId, String password) {
    String content = "";
    content += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sup=\"[...]">";
    content += "    <soapenv:Header/>";
    content += "    <soapenv:Body>";
    content += "        <sup:RegisterRequest>";
    content += "            <sup:domain>" + domainName + "</sup:domain>";
    content += "            <sup:email>" + email + "</sup:email>";
    content += "            <sup:userId>" + userId + "</sup:userId>";
    content += "            <sup:password>" + password + "</sup:password>";
    content += "        </sup:RegisterRequest>";
    content += "    </soapenv:Body>";
    content += "</soapenv:Envelope>";
    return new StringSource(content);
}

Dans mon test, je manipule à mon point final comme ceci:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "../../WEB-INF/applicationContext.xml", "../../WEB-INF/test.xml" })
@Transactional
public class TestRegisterEndpoint extends AbstractTransactionalJUnit4SpringContextTests {

    @Resource
    private RegisterEndpoint registerEndpoint;

    @Test
    public void registerUserFailsForUnexistantDomain() throws Exception {
        Source result = registerEndpoint.invoke(createRequest("unexistant_domain", "test@test.de", "test@test.de", "myPassword1"));
    }
}

Mais lorsque je tente de lancer le test, je reçois une exception "Vous ne trouvez pas la déclaration de l'élément.» Soapenv: Enveloppe".

org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: null; nested exception is javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.]
    at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:75)
[...]
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
[...]
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'soapenv:Envelope'.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

Je suppose que je dois définir quelque part l'espace de noms « de soapenv » où je havn't il. Mais si oui, je ne sais pas où.

Début de la "applicationContext.xml":

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

Début de la "test.xml":

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

Comment puis-je me débarrasser de l'exception?

Était-ce utile?

La solution

Ok, je l'ai trouvé de l'aide ailleurs. La solution: parce que mon point de terminaison étendu "PayloadEndpoint"

public interface RegisterEndpoint extends PayloadEndpoint {

}

Je dois insérer que la charge utile dans le point final (semble logique;)). Si je le fais comme ceci:

private Source createRequest(String domainName, String email, String userId, String password) {
    String content = "";
    content += "<sup:RegisterRequest xmlns:sup=\"[...]\">";
    content += "    <sup:domain>" + domainName + "</sup:domain>";
    content += "    <sup:email>" + email + "</sup:email>";
    content += "    <sup:userId>" + userId + "</sup:userId>";
    content += "    <sup:password>" + password + "</sup:password>";
    content += "</sup:PreregisterRequest>";
    return new StringSource(content);
}

tout fonctionne.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top