/** * Copyright (c) 2009-2011 VMware, Inc. All Rights Reserved. * * 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 com.springsource.insight.plugin.apache.http.hc3; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.StatusLine; import com.springsource.insight.util.ArrayUtil; /** * Placeholder {@link HttpMethod} implementation used in the <code>around</code> * advice in case a <code>null</code> value was passed in order to generate a * valid operation / frame anyway. <B>Note:</B> the actual method call is allowed * to proceed using the original (<code>null</code>) argument, and (hopefully) an * exception will be generated by the code (but not by our aspect) and will be * caught in the <code>exitAbnormal</code> collector method. */ final class HttpPlaceholderMethod extends HttpMethodBase { /** * The default (shared) placeholder instance used if a <code>null</code> * {@link HttpMethod} instance is intercepted by the <code>around</code> * advice */ static final HttpMethod PLACEHOLDER = new HttpPlaceholderMethod(); static final StatusLine PLACEHOLDER_STATUS; static { try { PLACEHOLDER_STATUS = new StatusLine("HTTP/1.1 500 Placeholder method used"); } catch (HttpException e) { // unexpected throw new RuntimeException(e); } } private HttpPlaceholderMethod() { super(HttpClientDefinitions.PLACEHOLDER_URI_VALUE); } @Override public String getName() { return HttpClientDefinitions.PLACEHOLDER_METHOD_NAME; } @Override public int getStatusCode() { StatusLine st = getStatusLine(); return st.getStatusCode(); } @Override public String getStatusText() { StatusLine st = getStatusLine(); return st.getReasonPhrase(); } @Override public StatusLine getStatusLine() { return PLACEHOLDER_STATUS; } static HttpMethod resolveHttpMethod(Object... args) { if (ArrayUtil.length(args) <= 0) { return PLACEHOLDER; } for (Object argVal : args) { if (argVal instanceof HttpMethod) { return (HttpMethod) argVal; } } // no match was found return PLACEHOLDER; } }