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

  • saaj

    Hello,
    Could you give me some short example of endpoint and ws-servlet where are you using saaj. I have some problems with it.

    Thank you very much.

    Regards.

  • #2
    Vege,
    It is always best to describe what you are trying to do, what the problem you're having is and what workarounds you've tried.

    Saying, "I am having problems with it" doesn't give us much to go on

    So...
    What are you trying to do?
    What problems are you having?

    If I can help I will

    Comment


    • #3
      I need to develop web service which will post some data and get back some data as attachment. I don't know how to make servlet.xml and correctly implement endpoint.

      My spring-ws-servlet.xml

      Code:
      <?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-2.0.xsd">
      
          <bean id="payloadMapping" class="org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping">
              <property name="defaultEndpoint" ref="cardLoginEndpoint"/>
              <property name="interceptors">
                  <list>
                      <ref local="validatingInterceptor"/>
                      <ref local="loggingInterceptor"/>
                  </list>
              </property>
          </bean>
      
          <bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor">
              <description>
                  This interceptor logs the message payload.
              </description>
          </bean>
      
          <bean id="cardLoginEndpoint" class="sth.ws.CardLoginEndpoint">
              <description>
                  This endpoint handles login requests.
              </description>
              <property name="cardLoginService" ref="cardLoginService"/>
          </bean>
      
          <bean id="cardLoginService" class="sth.service.CardLoginService">
              <description>
                  This bean is our "business" service.
              </description>
              <property name="userService" ref="userService" />
          </bean>
      
      </beans>
      My Endpoint:

      Code:
      public class CardLoginEndpoint implements MessageEndpoint {
      	
      	private CardLoginService cardLoginService;
      	
      	private SaajSoapMessageFactory messageFactory;
      	
      	public void setCardLoginService(CardLoginService cardLoginService) {
      		this.cardLoginService = cardLoginService;
      	}
      	
      	public void setSaajSoapMessageFactory(SaajSoapMessageFactory messageFactory) {
      		this.messageFactory = messageFactory;
      	}
      	
          public static final String NAMESPACE_URI = "http://www.sth.eu/schemas";
      
          public static final String PREFIX = "sth";
          
      	@SuppressWarnings("unchecked")
      	public void invoke(MessageContext messageContext) throws Exception {
      		
      		WebServiceMessage msg = messageContext.getRequest();	
      		SaajSoapMessage saaj = (SaajSoapMessage) msg;
      		
      		SOAPMessage soapMsg = saaj.getSaajMessage();
      
      		soapMsg.writeTo(new FileOutputStream("C://soapMsg.txt"));
      		 
      		SOAPPart reqsp = soapMsg.getSOAPPart();
      	    SOAPEnvelope reqse = reqsp.getEnvelope();
      	    SOAPBody reqsb = reqse.getBody();
      
              String login = null;
              
              Iterator<SOAPElement> it = reqsb.getChildElements(reqse.createName("GetChallengeRequest", PREFIX, NAMESPACE_URI));
              if(it.hasNext()){
              	SOAPElement bodyElem = it.next();
              	Iterator<SOAPElement> it1 = bodyElem.getChildElements(reqse.createName("login", PREFIX, NAMESPACE_URI));
      
              	if(it1.hasNext()) {
              		SOAPElement bodyElem1 = it1.next();
              		login = bodyElem1.getTextContent();
              	}
              }
              System.out.println("login: " + login);
      
      // do something and send back
      
      	}
      }
      I get login correctly. After that i need to send back some data as attachment. But i don't know how because invoke is void. Any idea ?

      Comment


      • #4
        I finally did it
        So the only thing to do is to create a response:

        Code:
        WebServiceMessage msgResponse = messageContext.getResponse();
                SaajSoapMessage saajResponse = (SaajSoapMessage) msgResponse;
                
                SOAPMessage soapMsgResponse = saajResponse.getSaajMessage();
        
                SOAPPart soapPart = soapMsgResponse.getSOAPPart();
                SOAPEnvelope envelope = soapPart.getEnvelope();
                SOAPBody body = envelope.getBody();
                
                SOAPElement bodyElement = body.addChildElement(envelope.createName("Server_response"));
                bodyElement.addChildElement(envelope.createName("ID")).addTextNode("sth");
               
                ByteArrayOutputStream baos = cardLoginService.makeSth(bla);
        
                AttachmentPart ap = soapMsgResponse.createAttachmentPart();
                
                ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); 
                
                ap.setRawContent(bais,"multipart/related");
                
                soapMsgResponse.addAttachmentPart(ap);
                
                soapMsgResponse.saveChanges();
        In client app you will see this message here:

        Code:
        SOAPMessage sOAPMessage = connection.call(message, destination);
        
        		SOAPPart reqsp = sOAPMessage.getSOAPPart();
        		SOAPEnvelope reqse = reqsp.getEnvelope();
        		SOAPBody reqsb = reqse.getBody();
        ........
        If you you are using spring framework in your application you need to implement spring-ws in addition to send attachment TO app. I don't know why. Maybe some additional headers ?

        Comment

        Working...
        X