View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.httpheaders;
    14
    15  import com.eviware.soapui.impl.wsdl.WsdlRequest;
    16  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
    17  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlEditor;
    18  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlInspector;
    19  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.httpheaders.HttpHeadersInspectorModel.AbstractHeadersModel;
    20  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.registry.RequestInspectorFactory;
    21  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.registry.ResponseInspectorFactory;
    22  import com.eviware.soapui.model.ModelItem;
    23  import com.eviware.soapui.support.types.StringToStringMap;
    24
    25  public class HttpHeadersInspectorFactory implements RequestInspectorFactory, ResponseInspectorFactory
    26  {
    27  	public static final String INSPECTOR_ID = "HTTP Headers";
    28
    29  	public String getInspectorId()
    30  	{
    31  		return INSPECTOR_ID;
    32  	}
    33
    34  	public XmlInspector createRequestInspector( XmlEditor editor, ModelItem modelItem )
    35  	{
    36  		if( modelItem instanceof WsdlRequest )
    37  			return new HttpHeadersInspector( new WsdlRequestHeadersModel( (WsdlRequest)modelItem ) );
    38  		else if( modelItem instanceof WsdlMockResponse )
    39  			return new HttpHeadersInspector( new WsdlMockResponseRequestHeadersModel( ( WsdlMockResponse ) modelItem ) );
    40
    41  		return null;
    42  	}
    43
    44  	public XmlInspector createResponseInspector( XmlEditor editor, ModelItem modelItem )
    45  	{
    46  		if( modelItem instanceof WsdlRequest )
    47  			return new HttpHeadersInspector( new WsdlRequestResponseHeadersModel( ( WsdlRequest ) modelItem ) );
    48  		else if( modelItem instanceof WsdlMockResponse )
    49  			return new HttpHeadersInspector( new WsdlMockResponseHeadersModel( ( WsdlMockResponse ) modelItem ) );
    50
    51  		return null;
    52  	}
    53
    54  	private class WsdlRequestHeadersModel extends AbstractHeadersModel<WsdlRequest>
    55  	{
    56  		public WsdlRequestHeadersModel( WsdlRequest request )
    57  		{
    58  			super( false, request, WsdlRequest.REQUEST_HEADERS_PROPERTY );
    59  		}
    60
    61  		public StringToStringMap getHeaders()
    62  		{
    63  			return getModelItem().getRequestHeaders();
    64  		}
    65
    66  		public void setHeaders( StringToStringMap headers )
    67  		{
    68  			getModelItem().setRequestHeaders( headers );
    69  		}
    70  	}
    71
    72  	private class WsdlMockResponseHeadersModel extends AbstractHeadersModel<WsdlMockResponse>
    73  	{
    74  		public WsdlMockResponseHeadersModel( WsdlMockResponse request )
    75  		{
    76  			super( false, request, WsdlMockResponse.HEADERS_PROPERTY );
    77  		}
    78
    79  		public StringToStringMap getHeaders()
    80  		{
    81  			return getModelItem().getResponseHeaders();
    82  		}
    83
    84  		public void setHeaders( StringToStringMap headers )
    85  		{
    86  			getModelItem().setResponseHeaders( headers );
    87  		}
    88  	}
    89
    90  	private class WsdlRequestResponseHeadersModel extends AbstractHeadersModel<WsdlRequest>
    91  	{
    92  		public WsdlRequestResponseHeadersModel( WsdlRequest request )
    93  		{
    94  			super( true, request, WsdlRequest.RESPONSE_PROPERTY );
    95  		}
    96
    97  		public StringToStringMap getHeaders()
    98  		{
    99  			WsdlRequest request = getModelItem();
    100 			return request.getResponse() == null ? new StringToStringMap()	: request.getResponse().getResponseHeaders();
    101 		}
    102 	}
    103
    104 	private class WsdlMockResponseRequestHeadersModel extends AbstractHeadersModel<WsdlMockResponse>
    105 	{
    106 		public WsdlMockResponseRequestHeadersModel( WsdlMockResponse request )
    107 		{
    108 			super( true, request, WsdlMockResponse.MOCKRESULT_PROPERTY );
    109 		}
    110
    111 		public StringToStringMap getHeaders()
    112 		{
    113 			WsdlMockResponse request = getModelItem();
    114 			return request.getMockResult() == null ? new StringToStringMap()	: request.getMockResult().getMockRequest().getRequestHeaders();
    115 		}
    116 	}
    117 }