Announcement Announcement Module
Collapse
No announcement yet.
new to webservices and need help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • new to webservices and need help

    Hi

    I am pretty new to web services and I stared to build an application based on the examples distributed with the spring-ws framework.

    At the moment i am stuck.
    Server side looks quite good but i'm not 100% sure if i deployed it right. anyway it shouldn't matter for what is concerning my problem.

    I wanted to use a very basic client for first testings. I used the saaj client example from the airport project and modified it for my project.

    But I must have done something wrong, because every time i end up with such an error code:

    Received SOAP Fault
    SOAP Fault Code :SOAP-ENV:Client
    SOAP Fault String :Validation error

    I assume my problem is in the way i try to create te response on client side.
    here's my code (like the one from the airpot example) and xsd:

    Code:
    ...
    private SOAPMessage createUserRequest() throws SOAPException {
    
            SOAPMessage message = messageFactory.createMessage();
            SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    
    
            Name createUserRequestName = envelope.createName("CreateUserRequest", PREFIX, NAMESPACE_URI);
            SOAPBodyElement createUserRequestElement = message.getSOAPBody().addBodyElement(createUserRequestName);
    
            Name userName = envelope.createName("user", PREFIX, NAMESPACE_URI);
            SOAPElement userElement = createUserRequestElement.addChildElement(userName);
            Name usernameName = envelope.createName("username", PREFIX, NAMESPACE_URI);
            userElement.addAttribute(usernameName, "username").setValue("username");
            Name passwordName = envelope.createName("password", PREFIX, NAMESPACE_URI);
            userElement.addAttribute(passwordName, "pw").setValue("pw");
    
            Name userToCreateName = envelope.createName("userToCreate", PREFIX, NAMESPACE_URI);
            SOAPElement userToCreateElement = createUserRequestElement.addChildElement(userToCreateName);
            Name userToCreatenameName = envelope.createName("username", PREFIX, NAMESPACE_URI);
            userElement.addAttribute(userToCreatenameName, "username").setValue("username");
            Name passwordToCreateName = envelope.createName("password", PREFIX, NAMESPACE_URI);
            userToCreateElement.addAttribute(passwordToCreateName, "pw").setValue("pw");
    
            Name userToCreateIsAdminName = envelope.createName("userToCreateIsAdmin", PREFIX, NAMESPACE_URI);
            SOAPElement userToCreateIsAdminElement = createUserRequestElement.addChildElement(userToCreateIsAdminName);
            userToCreateIsAdminElement.setValue("true");
    
    
            System.out.println(message.getSOAPBody().getTextContent());
    
    
           	return message;
            
            }
    
    	public void callWebService() throws SOAPException, IOException,
    			TransformerException {
    		//SOAPMessage request = createEchoRequest();
    		SOAPMessage request = createUserRequest();
    		SOAPConnection connection = connectionFactory.createConnection();
    		SOAPMessage response = connection.call(request, url);
    		if (!response.getSOAPBody().hasFault()) {
    			writeEchoResponse(response);
    		} else {
    			SOAPFault fault = response.getSOAPBody().getFault();
    			System.err.println("Received SOAP Fault");
    			System.err.println("SOAP Fault Code :" + fault.getFaultCode());
    			System.err.println("SOAP Fault String :" + fault.getFaultString());
    		}
    	}
    
    ...
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    	targetNamespace="de/roommate/shared/dto"
    	xmlns:rm="de/roommate/shared/dto"
    	elementFormDefault="qualified">
    
    	<!-- ++++++++++ +++++++++ Admin Services ++++++++++ +++++++++ -->
    	
    	<!-- ++++++++++ +++++++++ Create User ++++++++++ +++++++++ -->
    
    	<element name="CreateUserRequest">
    		<complexType>
    			<all>
    				<element name="user" type="rm:User" />
    				<element name="userToCreate" type="rm:User" />
    				<element name="userToCreateIsAdmin" type="boolean" />
    			</all>
    		</complexType>
    	</element>
    ...
    
    
    	<!-- ++++++++++ +++++++++ Complex Objects ++++++++++ +++++++++ -->
    
    	<!-- ++++++++++ +++++++++ User ++++++++++ +++++++++ -->
    	<complexType name="User">
    		<all>
    			<element name="name" type="string" />
    			<element name="password" type="string" />
    		</all>
    	</complexType>
    
    .....

  • #2
    solved this finally..

    now i know i did completely stupid things. if anyone intersting in the right code, let me know. but i guess that's no real questions if you know how to construct the soap msg properly (which i didn't when i posted here)

    Comment


    • #3
      Yeah, SAAJ allows you to construct invalid SOAP messages. Something I tried to fix by creating the SoapMessage wrapper.

      Comment

      Working...
      X