Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005-2010 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.ws.server.endpoint;
 
 
 
Endpoint that unmarshals the request payload, and marshals the response object. This endpoint needs a Marshaller and Unmarshaller, both of which can be set using properties. An abstract template method is invoked using the request object as a parameter, and allows for a response object to be returned.

 
 public abstract class AbstractMarshallingPayloadEndpoint implements MessageEndpointInitializingBean {

    
Logger available to subclasses.
 
     protected final Log logger = LogFactory.getLog(getClass());
 
     private Marshaller marshaller;
 
     private Unmarshaller unmarshaller;

    
 
     protected AbstractMarshallingPayloadEndpoint() {
     }

    
Creates a new AbstractMarshallingPayloadEndpoint with the given marshaller. The given org.springframework.oxm.Marshaller should also implements the org.springframework.oxm.Unmarshaller, since it is used for both marshalling and unmarshalling. If it is not, an exception is thrown.

Note that all org.springframework.oxm.Marshaller implementations in Spring-WS also implement the org.springframework.oxm.Unmarshaller interface, so that you can safely use this constructor.

Parameters:
marshaller object used as marshaller and unmarshaller
Throws:
java.lang.IllegalArgumentException when marshaller does not implement the org.springframework.oxm.Unmarshaller interface
See also:
AbstractMarshallingPayloadEndpoint(org.springframework.oxm.Marshaller,org.springframework.oxm.Unmarshaller)
 
     protected AbstractMarshallingPayloadEndpoint(Marshaller marshaller) {
         Assert.notNull(marshaller"marshaller must not be null");
         if (!(marshaller instanceof Unmarshaller)) {
             throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
                     "interface. Please set an Unmarshaller explicitly by using the " +
                     "AbstractMarshallingPayloadEndpoint(Marshaller, Unmarshaller) constructor.");
         }
         else {
             setMarshaller(marshaller);
             setUnmarshaller((Unmarshallermarshaller);
         }
     }

    
Creates a new AbstractMarshallingPayloadEndpoint with the given marshaller and unmarshaller.

Parameters:
marshaller the marshaller to use
unmarshaller the unmarshaller to use
 
     protected AbstractMarshallingPayloadEndpoint(Marshaller marshallerUnmarshaller unmarshaller) {
         Assert.notNull(marshaller"marshaller must not be null");
        Assert.notNull(unmarshaller"unmarshaller must not be null");
        setMarshaller(marshaller);
        setUnmarshaller(unmarshaller);
    }

    
Returns the marshaller used for transforming objects into XML.
    public Marshaller getMarshaller() {
        return ;
    }

    
Sets the marshaller used for transforming objects into XML.
    public final void setMarshaller(Marshaller marshaller) {
        this. = marshaller;
    }

    
Returns the unmarshaller used for transforming XML into objects.
    public Unmarshaller getUnmarshaller() {
        return ;
    }

    
Sets the unmarshaller used for transforming XML into objects.
    public final void setUnmarshaller(Unmarshaller unmarshaller) {
        this. = unmarshaller;
    }
    public void afterPropertiesSet() throws Exception {
        afterMarshallerSet();
    }
    public final void invoke(MessageContext messageContextthrows Exception {
        WebServiceMessage request = messageContext.getRequest();
        Object requestObject = unmarshalRequest(request);
        if (onUnmarshalRequest(messageContextrequestObject)) {
            Object responseObject = invokeInternal(requestObject);
            if (responseObject != null) {
                WebServiceMessage response = messageContext.getResponse();
                marshalResponse(responseObjectresponse);
                onMarshalResponse(messageContextrequestObjectresponseObject);
            }
        }
    }
    private Object unmarshalRequest(WebServiceMessage requestthrows IOException {
        Unmarshaller unmarshaller = getUnmarshaller();
        Assert.notNull(unmarshaller"No unmarshaller registered. Check configuration of endpoint.");
        Object requestObject = MarshallingUtils.unmarshal(unmarshallerrequest);
        if (.isDebugEnabled()) {
            .debug("Unmarshalled payload request to [" + requestObject + "]");
        }
        return requestObject;
    }

    
Callback for post-processing in terms of unmarshalling. Called on each message request, after standard unmarshalling.

Default implementation returns true.

Parameters:
messageContext the message context
requestObject the object unmarshalled from the request
Returns:
true to continue and call invokeInternal(java.lang.Object); false otherwise
    protected boolean onUnmarshalRequest(MessageContext messageContextObject requestObjectthrows Exception {
        return true;
    }
    private void marshalResponse(Object responseObjectWebServiceMessage responsethrows IOException {
        Marshaller marshaller = getMarshaller();
        Assert.notNull(marshaller"No marshaller registered. Check configuration of endpoint.");
        if (.isDebugEnabled()) {
            .debug("Marshalling [" + responseObject + "] to response payload");
        }
        MarshallingUtils.marshal(marshallerresponseObjectresponse);
    }

    
Callback for post-processing in terms of marshalling. Called on each message request, after standard marshalling of the response. Only invoked when invokeInternal(java.lang.Object) returns an object.

Default implementation is empty.

Parameters:
messageContext the message context
requestObject the object unmarshalled from the request
responseObject the object marshalled to the org.springframework.ws.context.MessageContext.getResponse() request}
    protected void onMarshalResponse(MessageContext messageContextObject requestObjectObject responseObject) {
    }

    
Template method that gets called after the marshaller and unmarshaller have been set.

The default implementation does nothing.

Deprecated:
as of Spring Web Services 1.5: afterPropertiesSet() is no longer final, so this can safely be overridden in subclasses
    @Deprecated
    public void afterMarshallerSet() throws Exception {
    }

    
Template method that subclasses must implement to process a request.

The unmarshalled request object is passed as a parameter, and the returned object is marshalled to a response. If no response is required, return null.

Parameters:
requestObject the unmarshalled message payload as an object
Returns:
the object to be marshalled as response, or null if a response is not required
    protected abstract Object invokeInternal(Object requestObjectthrows Exception;
New to GrepCode? Check out our FAQ X