Pregunta

He tratar de aplicar las pruebas de integración para una aplicación de trabajo (Spring, Hibernate, jabón, cxf). Construyo un jabón en XML a mano y manejarlo a mi punto final. De esta manera:

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);
}

En mi prueba de lo manejo a mi punto final como esto:

@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"));
    }
}

Pero cuando trato de ejecutar la prueba consigo una excepción "No se puede encontrar la declaración de elemento. 'Soapenv: Sobre'".

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)

Me supongo que tengo que definir el espacio de nombres "soapenv" en algún lugar en el que se havn't. Pero si es así, no sé dónde.

Inicio del "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">

Inicio del "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">

¿Cómo puedo eliminar de la excepción?

¿Fue útil?

Solución

Ok, he encontrado ayuda en otros lugares. La solución: porque mi punto final extendido "PayloadEndpoint"

public interface RegisterEndpoint extends PayloadEndpoint {

}

I tiene que insertar solamente la carga útil en el punto final (suena lógico;)). Si lo hago de esta manera:

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);
}

todo está funcionando.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top