001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.remoting.jaxws;
018
019import javax.xml.ws.BindingProvider;
020
021import org.springframework.aop.framework.ProxyFactory;
022import org.springframework.beans.factory.FactoryBean;
023import org.springframework.lang.Nullable;
024import org.springframework.util.Assert;
025
026/**
027 * {@link org.springframework.beans.factory.FactoryBean} for a specific port of a
028 * JAX-WS service. Exposes a proxy for the port, to be used for bean references.
029 * Inherits configuration properties from {@link JaxWsPortClientInterceptor}.
030 *
031 * @author Juergen Hoeller
032 * @since 2.5
033 * @see #setServiceInterface
034 * @see LocalJaxWsServiceFactoryBean
035 */
036public class JaxWsPortProxyFactoryBean extends JaxWsPortClientInterceptor implements FactoryBean<Object> {
037
038        @Nullable
039        private Object serviceProxy;
040
041
042        @Override
043        public void afterPropertiesSet() {
044                super.afterPropertiesSet();
045
046                Class<?> ifc = getServiceInterface();
047                Assert.notNull(ifc, "Property 'serviceInterface' is required");
048
049                // Build a proxy that also exposes the JAX-WS BindingProvider interface.
050                ProxyFactory pf = new ProxyFactory();
051                pf.addInterface(ifc);
052                pf.addInterface(BindingProvider.class);
053                pf.addAdvice(this);
054                this.serviceProxy = pf.getProxy(getBeanClassLoader());
055        }
056
057
058        @Override
059        @Nullable
060        public Object getObject() {
061                return this.serviceProxy;
062        }
063
064        @Override
065        public Class<?> getObjectType() {
066                return getServiceInterface();
067        }
068
069        @Override
070        public boolean isSingleton() {
071                return true;
072        }
073
074}