From f04130cd561f182e588a56538ec0f46a166ca14d Mon Sep 17 00:00:00 2001 From: Shadid Chowdhury Date: Mon, 12 May 2014 13:54:44 +0200 Subject: [PATCH] release-mock-response-fix-SOAP-2207 --- RELEASENOTES.txt | 6 + .../impl/support/AbstractMockResponse.java | 900 +++++++++--------- 2 files changed, 437 insertions(+), 469 deletions(-) diff --git a/RELEASENOTES.txt b/RELEASENOTES.txt index 93fae92d4c..24dec30dd4 100644 --- a/RELEASENOTES.txt +++ b/RELEASENOTES.txt @@ -1,3 +1,9 @@ +# SoapUI 5.0.1 +#### Released only JAR for LoadUI release, no installers: 2014-05-27 #### + +### Bugs fixed ### +* Mock Response test step fails (SOAP-2207) + # SoapUI 5.0.0 #### Released 2014-04-09 #### diff --git a/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockResponse.java b/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockResponse.java index 2930983af9..36502a92af 100644 --- a/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockResponse.java +++ b/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockResponse.java @@ -12,7 +12,8 @@ * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the Licence for the specific language governing permissions and limitations * under the Licence. -*/package com.eviware.soapui.impl.support; +*/ +package com.eviware.soapui.impl.support; import com.eviware.soapui.SoapUI; import com.eviware.soapui.config.BaseMockResponseConfig; @@ -58,472 +59,433 @@ import java.util.Map; public abstract class AbstractMockResponse - extends AbstractWsdlModelItem - implements MockResponse, MutableWsdlAttachmentContainer, PropertyExpansionContainer, TestPropertyHolder -{ - public static final String AUTO_RESPONSE_COMPRESSION = ""; - public static final String NO_RESPONSE_COMPRESSION = ""; - private MapTestPropertyHolder propertyHolder; - - private String responseContent; - private MockResult mockResult; - private ScriptEnginePool scriptEnginePool; - - - public AbstractMockResponse( MockResponseConfigType config, MockOperation operation, String icon ) - { - super( config, operation, icon ); - scriptEnginePool = new ScriptEnginePool( this ); - scriptEnginePool.setScript( getScript() ); - propertyHolder = new MapTestPropertyHolder( this ); - propertyHolder.addProperty( "Request" ); - - if( !config.isSetHttpResponseStatus() ) - { - config.setHttpResponseStatus( "" + HttpStatus.SC_OK ); - } - - } - - @Override - public void setConfig( MockResponseConfigType config ) - { - super.setConfig( config ); - - if( scriptEnginePool != null ) - scriptEnginePool.setScript( getScript() ); - } - - public String getResponseContent() - { - if( getConfig().getResponseContent() == null ) - getConfig().addNewResponseContent(); - - if( responseContent == null ) - responseContent = CompressedStringSupport.getString( getConfig().getResponseContent() ); - - return responseContent; - } - - public void setResponseContent( String responseContent ) - { - String oldContent = getResponseContent(); - if( responseContent != null && responseContent.equals( oldContent ) ) - return; - - this.responseContent = responseContent; - - setConfigResponseContent( responseContent ); - - notifyPropertyChanged( RESPONSE_CONTENT_PROPERTY, oldContent, responseContent ); - } - - private void setConfigResponseContent( String responseContent ) - { - CompressedStringConfig compressedResponseContent = CompressedStringConfig.Factory.newInstance(); - compressedResponseContent.setStringValue( responseContent ); - getConfig().setResponseContent( compressedResponseContent ); - } - - public StringToStringsMap getResponseHeaders() - { - StringToStringsMap result = new StringToStringsMap(); - List headerList = getConfig().getHeaderList(); - for( HeaderConfig header : headerList ) - { - result.add( header.getName(), header.getValue() ); - } - - return result; - } - - public void setResponseHttpStatus( int httpStatus ) - { - getConfig().setHttpResponseStatus( "" + httpStatus ); - } - - public int getResponseHttpStatus() - { - return Integer.valueOf( getConfig().getHttpResponseStatus() ); - } - - public String getResponseCompression() - { - if( getConfig().isSetCompression() ) - return getConfig().getCompression(); - else - return AUTO_RESPONSE_COMPRESSION; - } - - public void setMockResult( MockResult mockResult ) - { - MockResult oldResult = this.mockResult; - this.mockResult = mockResult; - notifyPropertyChanged( mockresultProperty(), oldResult, mockResult ); - } - - public MockResult getMockResult() - { - return mockResult; - } - - protected abstract String mockresultProperty(); - - public String getScript() - { - return getConfig().isSetScript() ? getConfig().getScript().getStringValue() : null; - } - - public void evaluateScript( MockRequest request ) throws Exception - { - String script = getScript(); - if( script == null || script.trim().length() == 0 ) - return; - - MockService mockService = getMockOperation().getMockService(); - MockRunner mockRunner = mockService.getMockRunner(); - MockRunContext context = - mockRunner == null ? new WsdlMockRunContext( mockService, null ) : mockRunner.getMockContext(); - - context.setMockResponse( this ); - - SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine(); - - try - { - scriptEngine.setVariable( "context", context ); - scriptEngine.setVariable( "requestContext", request == null ? null : request.getRequestContext() ); - scriptEngine.setVariable( "mockContext", context ); - scriptEngine.setVariable( "mockRequest", request ); - scriptEngine.setVariable( "mockResponse", this ); - scriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() ); - - scriptEngine.run(); - } - catch( RuntimeException e ) - { - throw new Exception( e.getMessage(), e ); - } - finally - { - scriptEnginePool.returnScriptEngine( scriptEngine ); - } - } - - public void setScript( String script ) - { - String oldScript = getScript(); - if( !script.equals( oldScript ) ) - { - if( !getConfig().isSetScript() ) - getConfig().addNewScript(); - getConfig().getScript().setStringValue( script ); - - scriptEnginePool.setScript( script ); - } - } - - @Override - public void release() - { - super.release(); - scriptEnginePool.release(); - } - - public MockResult execute( MockRequest request, MockResult result ) throws DispatchException - { - try - { - getProperty( "Request" ).setValue( request.getRequestContent() ); - - long delay = getResponseDelay(); - if( delay > 0 ) - Thread.sleep( delay ); - - String script = getScript(); - if( script != null && script.trim().length() > 0 ) - { - evaluateScript( request ); - } - - String responseContent = getResponseContent(); - - // create merged context - WsdlMockRunContext context = new WsdlMockRunContext( request.getContext().getMockService(), null ); - context.setMockResponse( this ); - - // casting below cause WsdlMockRunContext is both a MockRunContext AND a Map - context.putAll( (WsdlMockRunContext)request.getContext() ); - context.putAll( (WsdlMockRunContext)request.getRequestContext() ); - - StringToStringsMap responseHeaders = getResponseHeaders(); - for( Map.Entry> headerEntry : responseHeaders.entrySet() ) - { - for( String value : headerEntry.getValue() ) - result.addHeader( headerEntry.getKey(), PropertyExpander.expandProperties( context, value ) ); - } - - responseContent = PropertyExpander.expandProperties( context, responseContent, isEntitizeProperties() ); - - responseContent = executeSpecifics( request, responseContent, context ); - - if( !result.isCommitted() ) - { - responseContent = writeResponse( result, responseContent ); - } - - result.setResponseContent( responseContent ); - - setMockResult( result ); - - return result; - } - catch( Throwable e ) - { - SoapUI.logError( e ); - throw new DispatchException( e ); - } - } - - protected String writeResponse( MockResult result, String responseContent ) throws Exception - { - MimeMultipart mp = null; - - Operation operation = getMockOperation().getOperation(); - - // variables needed for both multipart sections.... - boolean isXOP = isMtomEnabled() && isForceMtom(); - StringToStringMap contentIds = new StringToStringMap(); - - // only support multipart for wsdl currently..... - if(operation instanceof WsdlMockOperation) - { - if( operation == null ) - throw new Exception( "Missing WsdlOperation for mock response" ); - - - // preprocess only if neccessary - if( isMtomEnabled() || isInlineFilesEnabled() || getAttachmentCount() > 0 ) - { - try - { - mp = new MimeMultipart(); - - WsdlOperation wsdlOperation = ( ( WsdlMockOperation )operation ).getOperation(); - MessageXmlObject requestXmlObject = new MessageXmlObject( wsdlOperation, responseContent, false ); - MessageXmlPart[] requestParts = requestXmlObject.getMessageParts(); - for( MessageXmlPart requestPart : requestParts ) - { - if( AttachmentUtils.prepareMessagePart( this, mp, requestPart, contentIds ) ) - isXOP = true; - } - responseContent = requestXmlObject.getMessageContent(); - } - catch( Exception e ) - { - SoapUI.logError( e ); - } - } - } - - responseContent = removeEmptyContent( responseContent ); - - if( isStripWhitespaces() ) - { - responseContent = XmlUtils.stripWhitespaces( responseContent ); - } - - MockRequest request = result.getMockRequest(); - request.getHttpResponse().setStatus( this.getResponseHttpStatus() ); - - ByteArrayOutputStream outData = new ByteArrayOutputStream(); - - // non-multipart request? - String responseCompression = getResponseCompression(); - if( !isXOP && ( mp == null || mp.getCount() == 0 ) && getAttachmentCount() == 0 ) - { - String encoding = getEncoding(); - if( responseContent == null ) - responseContent = ""; - - byte[] content = encoding == null ? responseContent.getBytes() : responseContent.getBytes( encoding ); - - if( !result.getResponseHeaders().containsKeyIgnoreCase( "Content-Type" ) ) - { - result.setContentType( getContentType( ) ); - } - - String acceptEncoding = result.getMockRequest().getRequestHeaders().get( "Accept-Encoding", "" ); - if( AUTO_RESPONSE_COMPRESSION.equals( responseCompression ) && acceptEncoding != null - && acceptEncoding.toUpperCase().contains( "GZIP" ) ) - { - result.addHeader( "Content-Encoding", "gzip" ); - outData.write( CompressionSupport.compress( CompressionSupport.ALG_GZIP, content ) ); - } - else if( AUTO_RESPONSE_COMPRESSION.equals( responseCompression ) && acceptEncoding != null - && acceptEncoding.toUpperCase().contains( "DEFLATE" ) ) - { - result.addHeader( "Content-Encoding", "deflate" ); - outData.write( CompressionSupport.compress( CompressionSupport.ALG_DEFLATE, content ) ); - } - else - { - outData.write( content ); - } - } - else // won't get here if rest at the moment... - { - // make sure.. - if( mp == null ) - mp = new MimeMultipart(); - - // init root part - initRootPart( responseContent, mp, isXOP ); - - // init mimeparts - AttachmentUtils.addMimeParts( this, Arrays.asList( getAttachments() ), mp, contentIds ); - - // create request message - MimeMessage message = new MimeMessage( AttachmentUtils.JAVAMAIL_SESSION ); - message.setContent( mp ); - message.saveChanges(); - MimeMessageMockResponseEntity mimeMessageRequestEntity - = new MimeMessageMockResponseEntity( message, isXOP, this ); - - result.addHeader( "Content-Type", mimeMessageRequestEntity.getContentType().getValue() ); - result.addHeader( "MIME-Version", "1.0" ); - mimeMessageRequestEntity.writeTo( outData ); - } - - if( outData.size() > 0 ) - { - byte[] data = outData.toByteArray(); - - if( responseCompression.equals( CompressionSupport.ALG_DEFLATE ) - || responseCompression.equals( CompressionSupport.ALG_GZIP ) ) - { - result.addHeader( "Content-Encoding", responseCompression ); - data = CompressionSupport.compress( responseCompression, data ); - } - - result.writeRawResponseData( data ); - } - - return responseContent; - } - - private void initRootPart( String requestContent, MimeMultipart mp, boolean isXOP ) throws MessagingException - { - MimeBodyPart rootPart = new PreencodedMimeBodyPart( "8bit" ); - rootPart.setContentID( AttachmentUtils.ROOTPART_SOAPUI_ORG ); - mp.addBodyPart( rootPart, 0 ); - - DataHandler dataHandler = new DataHandler( new MockResponseDataSource( this, requestContent, isXOP ) ); - rootPart.setDataHandler( dataHandler ); - } - - protected abstract String removeEmptyContent( String responseContent ); - - public void setResponseHeaders( StringToStringsMap headers ) - { - StringToStringsMap oldHeaders = getResponseHeaders(); - - getConfig().setHeaderArray( new HeaderConfig[0] ); - - for( Map.Entry> header : headers.entrySet() ) - { - for( String value : header.getValue() ) - { - HeaderConfig headerConfig = getConfig().addNewHeader(); - headerConfig.setName( header.getKey() ); - headerConfig.setValue( value ); - } - } - - notifyPropertyChanged( WsdlMockResponse.HEADERS_PROPERTY, oldHeaders, headers ); - } - - protected abstract String executeSpecifics( MockRequest request, String responseContent, WsdlMockRunContext context ) throws IOException, WSSecurityException; - - public boolean isEntitizeProperties() - { - return getSettings().getBoolean( CommonSettings.ENTITIZE_PROPERTIES ); - } - - public abstract long getResponseDelay(); - - public abstract boolean isForceMtom(); - - public abstract boolean isStripWhitespaces(); - - public void addTestPropertyListener( TestPropertyListener listener ) - { - propertyHolder.addTestPropertyListener( listener ); - } - - public ModelItem getModelItem() - { - return propertyHolder.getModelItem(); - } - - public Map getProperties() - { - return propertyHolder.getProperties(); - } - - public TestProperty getProperty( String name ) - { - return propertyHolder.getProperty( name ); - } - - public String[] getPropertyNames() - { - return propertyHolder.getPropertyNames(); - } - - public String getPropertyValue( String name ) - { - return propertyHolder.getPropertyValue( name ); - } - - public boolean hasProperty( String name ) - { - return propertyHolder.hasProperty( name ); - } - - public void removeTestPropertyListener( TestPropertyListener listener ) - { - propertyHolder.removeTestPropertyListener( listener ); - } - - public void setPropertyValue( String name, String value ) - { - propertyHolder.setPropertyValue( name, value ); - } - - - public TestProperty getPropertyAt( int index ) - { - return propertyHolder.getPropertyAt( index ); - } - - public int getPropertyCount() - { - return propertyHolder.getPropertyCount(); - } - - public List getPropertyList() - { - return propertyHolder.getPropertyList(); - } - - public String getEncoding() - { - return getConfig().getEncoding(); - } - - public void setEncoding( String encoding ) - { - getConfig().setEncoding( encoding ); - } + extends AbstractWsdlModelItem + implements MockResponse, MutableWsdlAttachmentContainer, PropertyExpansionContainer, TestPropertyHolder { + public static final String AUTO_RESPONSE_COMPRESSION = ""; + public static final String NO_RESPONSE_COMPRESSION = ""; + private MapTestPropertyHolder propertyHolder; + + private String responseContent; + private MockResult mockResult; + private ScriptEnginePool scriptEnginePool; + + + public AbstractMockResponse(MockResponseConfigType config, MockOperation operation, String icon) { + super(config, operation, icon); + scriptEnginePool = new ScriptEnginePool(this); + scriptEnginePool.setScript(getScript()); + propertyHolder = new MapTestPropertyHolder(this); + propertyHolder.addProperty("Request"); + + if (!config.isSetHttpResponseStatus()) { + config.setHttpResponseStatus("" + HttpStatus.SC_OK); + } + + } + + @Override + public void setConfig(MockResponseConfigType config) { + super.setConfig(config); + + if (scriptEnginePool != null) { + scriptEnginePool.setScript(getScript()); + } + } + + public String getResponseContent() { + if (getConfig().getResponseContent() == null) { + getConfig().addNewResponseContent(); + } + + if (responseContent == null) { + responseContent = CompressedStringSupport.getString(getConfig().getResponseContent()); + } + + return responseContent; + } + + public void setResponseContent(String responseContent) { + String oldContent = getResponseContent(); + if (responseContent != null && responseContent.equals(oldContent)) { + return; + } + + this.responseContent = responseContent; + + setConfigResponseContent(responseContent); + + notifyPropertyChanged(RESPONSE_CONTENT_PROPERTY, oldContent, responseContent); + } + + private void setConfigResponseContent(String responseContent) { + CompressedStringConfig compressedResponseContent = CompressedStringConfig.Factory.newInstance(); + compressedResponseContent.setStringValue(responseContent); + getConfig().setResponseContent(compressedResponseContent); + } + + public StringToStringsMap getResponseHeaders() { + StringToStringsMap result = new StringToStringsMap(); + List headerList = getConfig().getHeaderList(); + for (HeaderConfig header : headerList) { + result.add(header.getName(), header.getValue()); + } + + return result; + } + + public void setResponseHttpStatus(int httpStatus) { + getConfig().setHttpResponseStatus("" + httpStatus); + } + + public int getResponseHttpStatus() { + + if (getConfig().getHttpResponseStatus() != null) { + return Integer.valueOf(getConfig().getHttpResponseStatus()); + + } else { + return HttpStatus.SC_OK; + } + } + + public String getResponseCompression() { + if (getConfig().isSetCompression()) { + return getConfig().getCompression(); + } else { + return AUTO_RESPONSE_COMPRESSION; + } + } + + public void setMockResult(MockResult mockResult) { + MockResult oldResult = this.mockResult; + this.mockResult = mockResult; + notifyPropertyChanged(mockresultProperty(), oldResult, mockResult); + } + + public MockResult getMockResult() { + return mockResult; + } + + protected abstract String mockresultProperty(); + + public String getScript() { + return getConfig().isSetScript() ? getConfig().getScript().getStringValue() : null; + } + + public void evaluateScript(MockRequest request) throws Exception { + String script = getScript(); + if (script == null || script.trim().length() == 0) { + return; + } + + MockService mockService = getMockOperation().getMockService(); + MockRunner mockRunner = mockService.getMockRunner(); + MockRunContext context = + mockRunner == null ? new WsdlMockRunContext(mockService, null) : mockRunner.getMockContext(); + + context.setMockResponse(this); + + SoapUIScriptEngine scriptEngine = scriptEnginePool.getScriptEngine(); + + try { + scriptEngine.setVariable("context", context); + scriptEngine.setVariable("requestContext", request == null ? null : request.getRequestContext()); + scriptEngine.setVariable("mockContext", context); + scriptEngine.setVariable("mockRequest", request); + scriptEngine.setVariable("mockResponse", this); + scriptEngine.setVariable("log", SoapUI.ensureGroovyLog()); + + scriptEngine.run(); + } catch (RuntimeException e) { + throw new Exception(e.getMessage(), e); + } finally { + scriptEnginePool.returnScriptEngine(scriptEngine); + } + } + + public void setScript(String script) { + String oldScript = getScript(); + if (!script.equals(oldScript)) { + if (!getConfig().isSetScript()) { + getConfig().addNewScript(); + } + getConfig().getScript().setStringValue(script); + + scriptEnginePool.setScript(script); + } + } + + @Override + public void release() { + super.release(); + scriptEnginePool.release(); + } + + public MockResult execute(MockRequest request, MockResult result) throws DispatchException { + try { + getProperty("Request").setValue(request.getRequestContent()); + + long delay = getResponseDelay(); + if (delay > 0) { + Thread.sleep(delay); + } + + String script = getScript(); + if (script != null && script.trim().length() > 0) { + evaluateScript(request); + } + + String responseContent = getResponseContent(); + + // create merged context + WsdlMockRunContext context = new WsdlMockRunContext(request.getContext().getMockService(), null); + context.setMockResponse(this); + + // casting below cause WsdlMockRunContext is both a MockRunContext AND a Map + context.putAll((WsdlMockRunContext) request.getContext()); + context.putAll((WsdlMockRunContext) request.getRequestContext()); + + StringToStringsMap responseHeaders = getResponseHeaders(); + for (Map.Entry> headerEntry : responseHeaders.entrySet()) { + for (String value : headerEntry.getValue()) { + result.addHeader(headerEntry.getKey(), PropertyExpander.expandProperties(context, value)); + } + } + + responseContent = PropertyExpander.expandProperties(context, responseContent, isEntitizeProperties()); + + responseContent = executeSpecifics(request, responseContent, context); + + if (!result.isCommitted()) { + responseContent = writeResponse(result, responseContent); + } + + result.setResponseContent(responseContent); + + setMockResult(result); + + return result; + } catch (Throwable e) { + SoapUI.logError(e); + throw new DispatchException(e); + } + } + + public String writeResponse(MockResult result, String responseContent) throws Exception { + MimeMultipart mp = null; + + Operation operation = getMockOperation().getOperation(); + + // variables needed for both multipart sections.... + boolean isXOP = isMtomEnabled() && isForceMtom(); + StringToStringMap contentIds = new StringToStringMap(); + + // only support multipart for wsdl currently..... + if (operation instanceof WsdlOperation) { + if (operation == null) { + throw new IllegalStateException("Missing WsdlOperation for mock response"); + } + + + // preprocess only if neccessary + if (isMtomEnabled() || isInlineFilesEnabled() || getAttachmentCount() > 0) { + try { + mp = new MimeMultipart(); + + WsdlOperation wsdlOperation = ((WsdlOperation) operation); + MessageXmlObject requestXmlObject = createMessageXmlObject(responseContent, wsdlOperation); + MessageXmlPart[] requestParts = requestXmlObject.getMessageParts(); + for (MessageXmlPart requestPart : requestParts) { + if (prepareMessagePart(mp, contentIds, requestPart)) { + isXOP = true; + } + } + responseContent = requestXmlObject.getMessageContent(); + } catch (Exception e) { + SoapUI.logError(e); + } + } + + responseContent = removeEmptyContent(responseContent); + } + + if (isStripWhitespaces()) { + responseContent = XmlUtils.stripWhitespaces(responseContent); + } + + ByteArrayOutputStream outData = new ByteArrayOutputStream(); + + // non-multipart request? + String responseCompression = getResponseCompression(); + if (!isXOP && (mp == null || mp.getCount() == 0) && getAttachmentCount() == 0) { + String encoding = getEncoding(); + if (responseContent == null) { + responseContent = ""; + } + + byte[] content = encoding == null ? responseContent.getBytes() : responseContent.getBytes(encoding); + + if (!result.getResponseHeaders().containsKeyIgnoreCase("Content-Type")) { + result.setContentType(getContentType()); + } + + String acceptEncoding = result.getMockRequest().getRequestHeaders().get("Accept-Encoding", ""); + if (AUTO_RESPONSE_COMPRESSION.equals(responseCompression) && acceptEncoding != null + && acceptEncoding.toUpperCase().contains("GZIP")) { + result.addHeader("Content-Encoding", "gzip"); + outData.write(CompressionSupport.compress(CompressionSupport.ALG_GZIP, content)); + } else if (AUTO_RESPONSE_COMPRESSION.equals(responseCompression) && acceptEncoding != null + && acceptEncoding.toUpperCase().contains("DEFLATE")) { + result.addHeader("Content-Encoding", "deflate"); + outData.write(CompressionSupport.compress(CompressionSupport.ALG_DEFLATE, content)); + } else { + outData.write(content); + } + } else // won't get here if rest at the moment... + { + // make sure.. + if (mp == null) { + mp = new MimeMultipart(); + } + + // init root part + initRootPart(responseContent, mp, isXOP); + + // init mimeparts + AttachmentUtils.addMimeParts(this, Arrays.asList(getAttachments()), mp, contentIds); + + // create request message + MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION); + message.setContent(mp); + message.saveChanges(); + MimeMessageMockResponseEntity mimeMessageRequestEntity + = new MimeMessageMockResponseEntity(message, isXOP, this); + + result.addHeader("Content-Type", mimeMessageRequestEntity.getContentType().getValue()); + result.addHeader("MIME-Version", "1.0"); + mimeMessageRequestEntity.writeTo(outData); + } + + if (outData.size() > 0) { + byte[] data = outData.toByteArray(); + + if (responseCompression.equals(CompressionSupport.ALG_DEFLATE) + || responseCompression.equals(CompressionSupport.ALG_GZIP)) { + result.addHeader("Content-Encoding", responseCompression); + data = CompressionSupport.compress(responseCompression, data); + } + if(result.getResponseHeaders().get("Transfer-Encoding") == null) { + result.addHeader("Content-Length", "" + data.length); + } + result.writeRawResponseData(data); + } + + MockRequest request = result.getMockRequest(); + request.getHttpResponse().setStatus(this.getResponseHttpStatus()); + + return responseContent; + } + + public boolean prepareMessagePart(MimeMultipart mp, StringToStringMap contentIds, MessageXmlPart requestPart) throws Exception { + return AttachmentUtils.prepareMessagePart(this, mp, requestPart, contentIds); + } + + public MessageXmlObject createMessageXmlObject(String responseContent, WsdlOperation wsdlOperation) { + return new MessageXmlObject(wsdlOperation, responseContent, false); + } + + private void initRootPart(String requestContent, MimeMultipart mp, boolean isXOP) throws MessagingException { + MimeBodyPart rootPart = new PreencodedMimeBodyPart("8bit"); + rootPart.setContentID(AttachmentUtils.ROOTPART_SOAPUI_ORG); + mp.addBodyPart(rootPart, 0); + + DataHandler dataHandler = new DataHandler(new MockResponseDataSource(this, requestContent, isXOP)); + rootPart.setDataHandler(dataHandler); + } + + protected abstract String removeEmptyContent(String responseContent); + + public void setResponseHeaders(StringToStringsMap headers) { + StringToStringsMap oldHeaders = getResponseHeaders(); + + getConfig().setHeaderArray(new HeaderConfig[0]); + + for (Map.Entry> header : headers.entrySet()) { + for (String value : header.getValue()) { + HeaderConfig headerConfig = getConfig().addNewHeader(); + headerConfig.setName(header.getKey()); + headerConfig.setValue(value); + } + } + + notifyPropertyChanged(WsdlMockResponse.HEADERS_PROPERTY, oldHeaders, headers); + } + + protected abstract String executeSpecifics(MockRequest request, String responseContent, WsdlMockRunContext context) throws IOException, WSSecurityException; + + public boolean isEntitizeProperties() { + return getSettings().getBoolean(CommonSettings.ENTITIZE_PROPERTIES); + } + + public abstract long getResponseDelay(); + + public abstract boolean isForceMtom(); + + public abstract boolean isStripWhitespaces(); + + public void addTestPropertyListener(TestPropertyListener listener) { + propertyHolder.addTestPropertyListener(listener); + } + + public ModelItem getModelItem() { + return propertyHolder.getModelItem(); + } + + public Map getProperties() { + return propertyHolder.getProperties(); + } + + public TestProperty getProperty(String name) { + return propertyHolder.getProperty(name); + } + + public String[] getPropertyNames() { + return propertyHolder.getPropertyNames(); + } + + public String getPropertyValue(String name) { + return propertyHolder.getPropertyValue(name); + } + + public boolean hasProperty(String name) { + return propertyHolder.hasProperty(name); + } + + public void removeTestPropertyListener(TestPropertyListener listener) { + propertyHolder.removeTestPropertyListener(listener); + } + + public void setPropertyValue(String name, String value) { + propertyHolder.setPropertyValue(name, value); + } + + + public TestProperty getPropertyAt(int index) { + return propertyHolder.getPropertyAt(index); + } + + public int getPropertyCount() { + return propertyHolder.getPropertyCount(); + } + + public List getPropertyList() { + return propertyHolder.getPropertyList(); + } + + public String getEncoding() { + return getConfig().getEncoding(); + } + + public void setEncoding(String encoding) { + getConfig().setEncoding(encoding); + } }