Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2005-2012 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.test.client;
 
 import java.net.URI;
 
Factory methods for ResponseCreator classes. Typically used to provide input for ResponseActions.andRespond(org.springframework.ws.test.client.ResponseCreator).

Author(s):
Arjen Poutsma
Since:
2.0
 
 public abstract class ResponseCreators {
 
     private ResponseCreators() {
     }
 
     // Payload
 
    
Respond with the given javax.xml.transform.Source XML as payload response.

Parameters:
payload the response payload
Returns:
the response callback
 
     public static ResponseCreator withPayload(Source payload) {
         Assert.notNull(payload"'payload' must not be null");
         return new WebServiceMessageCreatorAdapter(new PayloadMessageCreator(payload));
     }

    
Respond with the given org.springframework.core.io.Resource XML as payload response.

Parameters:
payload the response payload
Returns:
the response callback
 
     public static ResponseCreator withPayload(Resource payloadthrows IOException {
         Assert.notNull(payload"'payload' must not be null");
         return withPayload(new ResourceSource(payload));
     }
 
     // Error/Exception
     
    
Respond with an error.

 
     public static ResponseCreator withError(String errorMessage) {
         Assert.hasLength(errorMessage"'errorMessage' must not be empty");
         return new ErrorResponseCreator(errorMessage);
     }

    
Respond with an java.io.IOException.

Parameters:
ioException the exception to be thrown
Returns:
the response callback
 
     public static ResponseCreator withException(IOException ioException) {
         Assert.notNull(ioException"'ioException' must not be null");
         return new ExceptionResponseCreator(ioException);
     }

    
Respond with an java.lang.RuntimeException.

Parameters:
ex the runtime exception to be thrown
Returns:
the response callback
    public static ResponseCreator withException(RuntimeException ex) {
        Assert.notNull(ex"'ex' must not be null");
        return new ExceptionResponseCreator(ex);
    }
    // SOAP

    
Respond with the given javax.xml.transform.Source XML as SOAP envelope response.

Parameters:
soapEnvelope the response SOAP envelope
Returns:
the response callback
Since:
2.1.1
    public static ResponseCreator withSoapEnvelope(Source soapEnvelope) {
        Assert.notNull(soapEnvelope"'soapEnvelope' must not be null");
        return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
    }

    
Respond with the given org.springframework.core.io.Resource XML as SOAP envelope response.

Parameters:
soapEnvelope the response SOAP envelope
Returns:
the response callback
Since:
2.1.1
    public static ResponseCreator withSoapEnvelope(Resource soapEnvelopethrows IOException {
        Assert.notNull(soapEnvelope"'soapEnvelope' must not be null");
        return withSoapEnvelope(new ResourceSource(soapEnvelope));
    }


    
Respond with a MustUnderstand fault.

Parameters:
faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
locale the language of faultStringOrReason. Optional for SOAP 1.1
See also:
org.springframework.ws.soap.SoapBody.addMustUnderstandFault(java.lang.String,java.util.Locale)
    public static ResponseCreator withMustUnderstandFault(final String faultStringOrReasonfinal Locale locale) {
        Assert.hasLength(faultStringOrReason"'faultStringOrReason' must not be empty");
        return new SoapFaultResponseCreator() {
            @Override
            public void addSoapFault(SoapBody soapBody) {
                soapBody.addMustUnderstandFault(faultStringOrReasonlocale);
            }
        };
    }

    
Respond with a Client (SOAP 1.1) or Sender (SOAP 1.2) fault.

Parameters:
faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
locale the language of faultStringOrReason. Optional for SOAP 1.1
See also:
org.springframework.ws.soap.SoapBody.addClientOrSenderFault(java.lang.String,java.util.Locale)
    public static ResponseCreator withClientOrSenderFault(final String faultStringOrReasonfinal Locale locale) {
        Assert.hasLength(faultStringOrReason"'faultStringOrReason' must not be empty");
        return new SoapFaultResponseCreator() {
            @Override
            public void addSoapFault(SoapBody soapBody) {
                soapBody.addClientOrSenderFault(faultStringOrReasonlocale);
            }
        };
    }

    
Respond with a Server (SOAP 1.1) or Receiver (SOAP 1.2) fault.

Parameters:
faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
locale the language of faultStringOrReason. Optional for SOAP 1.1
See also:
org.springframework.ws.soap.SoapBody.addServerOrReceiverFault(java.lang.String,java.util.Locale)
    public static ResponseCreator withServerOrReceiverFault(final String faultStringOrReasonfinal Locale locale) {
        Assert.hasLength(faultStringOrReason"'faultStringOrReason' must not be empty");
        return new SoapFaultResponseCreator() {
            @Override
            public void addSoapFault(SoapBody soapBody) {
                soapBody.addServerOrReceiverFault(faultStringOrReasonlocale);
            }
        };
    }

    
Respond with a VersionMismatch fault.

Parameters:
faultStringOrReason the SOAP 1.1 fault string or SOAP 1.2 reason text
locale the language of faultStringOrReason. Optional for SOAP 1.1
See also:
org.springframework.ws.soap.SoapBody.addVersionMismatchFault(java.lang.String,java.util.Locale)
    public static ResponseCreator withVersionMismatchFault(final String faultStringOrReasonfinal Locale locale) {
        Assert.hasLength(faultStringOrReason"'faultStringOrReason' must not be empty");
        return new SoapFaultResponseCreator() {
            @Override
            public void addSoapFault(SoapBody soapBody) {
                soapBody.addVersionMismatchFault(faultStringOrReasonlocale);
            }
        };
    }

    
    private static class WebServiceMessageCreatorAdapter implements ResponseCreator {
        private final WebServiceMessageCreator adaptee;
        private WebServiceMessageCreatorAdapter(WebServiceMessageCreator adaptee) {
            this. = adaptee;
        }
        public WebServiceMessage createResponse(URI uri,
                                                WebServiceMessage request,
                                                WebServiceMessageFactory messageFactorythrows IOException {
            return .createMessage(messageFactory);
        }
    }
New to GrepCode? Check out our FAQ X