This paper addresses the design of adaptive middleware to support autonomic computing in pervasive computing environments. The particular problem we address here is how to support self-optimization to changing network connection capabilities as a mobile user interacts with heterogeneous elements in a wireless network infrastructure. The goal is to enable self-optimization to such changes transparently with respect to the core application code. We propose a solution based on the use of the generic proxy, which is a specific CORBA object that can intercept and process any CORBA request using rules and actions that can be introduced to the knowledge base of the proxy during execution. To explore its design and operation, we have incorporated the generic proxy into ACT, an adaptive middleware framework we designed previously to support adaptation in CORBA applications. Details of the generic proxy are presented. A case study is described in which a generic proxy is used to support self-optimization in an existing image retrieval application, when executed in a heterogeneous wireless environment.