Announcement Announcement Module
Collapse
No announcement yet.
Servlet Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Servlet Error

    First, a useless post because I can't post a thread with URL if this is my first post....

  • #2
    Hi guys, sorry for my english...

    I just decided to post here because after passing 2 days debugging, I finally admit that I need some help. I am a beginner in Java and Spring and don't find a lot of documentation/tutorial for spring-ws, the few sources I found are maven based and I got a firewall which blocks all the jar downloading need by the projects (not sure my sentence is very clear, sorry...)

    I must develop some Web services using spring-ws and I get a short example code to learn how spring-ws works (or not works actually), composed of a web service and a client. I apologize for asking such help but I really don't get it.

    Here is the code of the webservice:

    spring-ws-servlet.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/oxm
            http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
    
    
    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
    
    <bean id="messageReceiver"		class="org.springframework.ws.soap.server.SoapMessageDispatcher" />
    	
    <bean id="avecValidation"		class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    		<property name="interceptors">
    			<list>
    				<bean class="fr.bdf.modec.service.divers.MonIntercepteur" />
    				<bean
    					class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    				<bean
    					class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    					<property name="schemas"
    						value="classpath:fr/bdf/modec/service/model/util/utilisateur.xsd" />
    					<property name="validateRequest" value="true" />
    					<property name="validateResponse" value="true" />
    				</bean>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="utilisateurService" class="fr.bdf.modec.service.UtilisateurServiceImpl" />
    
    	<bean id="utilisateurEndPoint" class="fr.bdf.modec.service.web.UtilisateurEndPoint">
    		<property name="service" ref="utilisateurService"></property>
    		<property name="marshaller" ref="marshaller"></property>
    	</bean>
    
    	<bean id="utilisateurJaxbEndPoint" class="fr.bdf.modec.service.web.UtilisateurJaxbEndPoint">
    		<property name="service" ref="utilisateurService"></property>
    		<property name="marshaller" ref="marshaller"></property>
    	</bean>
    
    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <list>
                    <value>fr.bdf.modec.service.model.util.NombreUtilisateurs</value>
                    <value>fr.bdf.modec.service.model.util.NombreUtilisateursResponse</value>
                </list>
            </property>
            <property name="schema" value="classpath:org/springframework/oxm/schema.xsd"/>
        </bean><!--
    
    	<oxm:jaxb2-marshaller id="marshaller" >
    		<oxm:class-to-be-bound
    			name="fr.bdf.modec.service.model.util.UtilisateurRequest" />
    		<oxm:class-to-be-bound
    			name="fr.bdf.modec.service.model.util.UtilisateurResponse" />
    	</oxm:jaxb2-marshaller>
    	--><bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
    		<constructor-arg ref="marshaller" />
    	</bean>
    
    	<bean		class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
    		<constructor-arg ref="marshaller" />
    	</bean>
    
    	<bean id="utilisateur"		class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
    		<constructor-arg value="/WEB-INF/services/utilisateur.wsdl" />
    	</bean>
    
    	<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    		<property name="xsd" value="/WEB-INF/services/utilisateur.xsd" />
    	</bean>
    
    	<bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver">		
    		<property name="order" value="1" />
    	</bean>
    </beans>
    First, I had the
    Code:
    <oxm:jaxb2-marshaller id="marshaller" >
    		<oxm:class-to-be-bound
    			name="fr.bdf.modec.service.model.util.NombreUtilisateurs" />
    		<oxm:class-to-be-bound
    			name="fr.bdf.modec.service.model.util.NombreUtilisateursResponse" />
    	</oxm:jaxb2-marshaller>
    but I had an error:
    cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'oxm:jaxb2-marshaller'

    so I put:
    Code:
    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <list>                <value>fr.bdf.modec.service.model.util.NombreUtilisateurs</value>
                    <value>fr.bdf.modec.service.model.util.NombreUtilisateursResponse</value>
                </list>
            </property>
            <property name="schema" value="classpath:org/springframework/oxm/schema.xsd"/>
        </bean>
    instead because I didn't understand the error and thinks it was kindda similar, am I good?

    NombreUtilisateurs.xsd:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="http://fr.bdf.modec/utilisateur/"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<xsd:element name="NombreUtilisateurs">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="in" type="xsd:string" />
    			</xsd:sequence>
    		</xsd:complexType>
    
    	</xsd:element>
    	<xsd:element name="NombreUtilisateursResponse">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element name="sortie" type="xsd:int" />
    			</xsd:sequence>
    		</xsd:complexType>
    	</xsd:element>
    </xsd:schema>
    NombreUtilisateurs.wsdl:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://fr.bdf.modec/utilisateur/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="utilisateur" targetNamespace="http://fr.bdf.modec/utilisateur/">
      <wsdl:types>
    
        <xsd:schema targetNamespace="http://fr.bdf.modec/utilisateur/">
          <xsd:element name="NombreUtilisateurs">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="in" type="xsd:string"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="NombreUtilisateursResponse">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="sortie" type="xsd:int"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
      </wsdl:types>
      <wsdl:message name="NombreUtilisateursRequest">
        <wsdl:part element="tns:NombreUtilisateurs" name="parameters"/>
      </wsdl:message>
      <wsdl:message name="NombreUtilisateursResponse">
        <wsdl:part element="tns:NombreUtilisateursResponse" name="parameters"/>
      </wsdl:message>
      <wsdl:portType name="utilisateur">
        <wsdl:operation name="NombreUtilisateurs">
          <wsdl:input message="tns:NombreUtilisateursRequest"/>
          <wsdl:output message="tns:NombreUtilisateursResponse"/>
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="utilisateurSOAP" type="tns:utilisateur">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="NombreUtilisateurs">
          <soap:operation soapAction="http://fr.bdf.modec/utilisateur/NombreUtilisateurs"/>
          <wsdl:input>
            <soap:body use="literal"/>
          </wsdl:input>
          <wsdl:output>
            <soap:body use="literal"/>
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="utilisateur">
        <wsdl:port binding="tns:utilisateurSOAP" name="utilisateurSOAP">
          <soap:address location="http://localhost:8080/PetitTest/utilisateurService"/>
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>
    So config is over, Here's my Endpoint:
    Code:
    public class UtilisateurEndPoint extends AbstractJDomPayloadEndpoint{
    
    	/**
    	 *
    	 */
    	private Jaxb2Marshaller marshaller;
    
    	public Jaxb2Marshaller getMarshaller() {
    		return marshaller;
    	}
    
    	public void setMarshaller(Jaxb2Marshaller marshaller) {
    		this.marshaller = marshaller;
    	}
    
    protected Element invokeInternal(Element entree) throws Exception {
    
    return null; //just for testing
    }
    }
    For what I understood, MessageDispatcherServlet takes control when a request is coming, creates beans, and then looks for Endpoint, then the Endpoint which extends AbstractJDomPayloadEndpoint unmarshall request, treats request, buld response and send it to the client, am I good?

    Comment


    • #3
      Client code

      Here is the client code:

      Code:
      public void customSendAndReceive() {
      StreamSource source = new StreamSource(new StringReader(MESSAGE));
      StreamResult result = new StreamResult(System.out);
      WebServiceMessageCallback wsmc = new WebServiceMessageCallback() {
      
      public void doWithMessage(WebServiceMessage message)
      					throws IOException, TransformerException {
      Result res = message.getPayloadResult();
      AbstractSoapMessage abstractSoapMessage = (AbstractSoapMessage) message;
      SoapHeader entete = abstractSoapMessage
      						.getSoapHeader();
      				abstractSoapMessage.getSoapBody().addNamespaceDeclaration("tt", "http://fr.bdf.modec/utilisateur/");
      				abstractSoapMessage.setSoapAction("http://fr.bdf.modec/utilisateur/");
      				System.out.println(res);
      			}
      		};
      		try {
      			FaultMessageResolver fmr = new FaultMessageResolver(){
      	public void resolveFault(WebServiceMessage message)	throws IOException {
      DOMResult res=(DOMResult) message.getPayloadResult();
      System.out.println("Interception de la faute"+res);
      DOMBuilder db = new DOMBuilder();
      
      SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
      String test = saajSoapMessage.getFaultReason();
      Source src = message.getPayloadSource();
      System.out.println("source de l'erreur "+test+" "+src);
      				}
      			};
      
      webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/ModecWS",source, result);
      		} catch (Exception e) {
      			System.out.println("ERREUR interceptee");
      			System.out.println("## CODE ## " + e.getMessage());
      			System.out.println("## Local M ## " + e.getLocalizedMessage());
      			e.printStackTrace();
      		}
      	}
      Executing this client results in a:
      ERREUR interceptee
      ## CODE ## Erreur Interne de Servlet [500]
      ## Local M ## Erreur Interne de Servlet [500]

      If somebody find the time to help me, I'll be really grateful.

      Thanks.

      Comment

      Working...
      X