Использование веб-службы - JaxWsPortProxyFactoryBean или контроллер не настроены правильно
Java 1.7 Spring 3.1.1 с Spring-WS 2.1.1 Joda Hibernate 3.6 MySQL 5.0.57 Maven 3 Tomcat 7 Eclipse 3.7
Итак, веб-сервис SOAP запущен и работает.
И мое автономное Java-приложение может получить к нему доступ.
Сейчас я пытаюсь создать веб-клиент Spring MVC для доступа к нему. Таким образом, я могу просто заменить уровень обслуживания стандартного веб-приложения конечной точкой веб-службы.
Создание паттернов после этого http://ankeetmaini.wordpress.com/2013/03/04/jax-ws-client-consuming-the-jax-ws-webservice после переключения его соглашений об именах на более канонические.
FormsEndpointImplService
@WebServiceClient(name = "FormsEndpointImplService",
wsdlLocation = "http://localhost:8080/dept_forms_webservice/formsService?wsdl",
targetNamespace = "http://endpoint.web.forms.azdeq.gov/")
public class FormsEndpointImplService extends Service
{
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("http://endpoint.web.forms.azdeq.gov/", "FormsEndpointImplService");
public final static QName FormsEndpointImplPort = new QName("http://endpoint.web.forms.azdeq.gov/", "FormsEndpointImplPort");
static {
URL url = null;
try {
url = new URL("http://localhost:8080/dept_forms_webservice/formsService?wsdl");
} catch (MalformedURLException e) {
java.util.logging.Logger.getLogger(FormsEndpointImplService.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}", "http://localhost:8080/dept_forms_webservice/formsService?wsdl");
}
WSDL_LOCATION = url;
}
public FormsEndpointImplService(URL wsdlLocation) {
super(wsdlLocation, SERVICE);
}
public FormsEndpointImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public FormsEndpointImplService() {
super(WSDL_LOCATION, SERVICE);
}
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public FormsEndpointImplService(WebServiceFeature ... features) {
super(WSDL_LOCATION, SERVICE, features);
}
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public FormsEndpointImplService(URL wsdlLocation, WebServiceFeature ... features) {
super(wsdlLocation, SERVICE, features);
}
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
public FormsEndpointImplService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns FormsEndpoint
*/
@WebEndpoint(name = "FormsEndpointImplPort")
public FormsEndpoint getFormsEndpointImplPort() {
return super.getPort(FormsEndpointImplPort, FormsEndpoint.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns FormsEndpoint
*/
@WebEndpoint(name = "FormsEndpointImplPort")
public FormsEndpoint getFormsEndpointImplPort(WebServiceFeature... features) {
return super.getPort(FormsEndpointImplPort, FormsEndpoint.class, features);
}
}
FormsEndpoint (SEI)
@WebService(targetNamespace = "http://endpoint.web.forms.azdeq.gov/", name = "FormsEndpoint")
@XmlSeeAlso({ObjectFactory.class})
public interface FormsEndpoint
{
@RequestWrapper(localName = "insertCompletedForm", targetNamespace = "http://endpoint.web.forms.azdeq.gov/", className = "gov.azdeq.forms.web.endpoint.InsertCompletedForm")
@WebMethod
@ResponseWrapper(localName = "insertCompletedFormResponse", targetNamespace = "http://endpoint.web.forms.azdeq.gov/", className = "gov.azdeq.forms.web.endpoint.InsertCompletedFormResponse")
public void insertCompletedForm(
@WebParam(name = "arg0", targetNamespace = "")
gov.azdeq.forms.web.endpoint.CompletedForm arg0
);
....
}
и мой сервлет-context.xml
...
<bean id="formsWebServiceProxy" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="wsdlDocumentUrl" value="http://localhost:8080/dept_forms_webservice/formsService?wsdl"/>
<property name="serviceInterface" value="gov.azdeq.forms.web.endpoint.FormsEndpoint"/>
<property name="serviceName" value="FormsEndpointImplService"/>
<property name="portName" value="FormsEndpointImplPort"/>
<property name="namespaceUri" value="http://endpoint.web.forms.azdeq.gov/"/>
<!-- <property name="endpointAddress" value="http://endpoint.web.forms.azdeq.gov/" /> -->
</bean>
<bean id="baseController" class="gov.azdeq.forms.web.controller.BaseController">
<property name="service" ref="formsWebServiceProxy" />
</bean>
...
и базовый контроллер
@RequestMapping
@Controller
public class BaseController
{
private static final Logger logger = Logger.getLogger( BaseController.class);
@Resource
FormsEndpoint service; // should come in from bean
...
}
Так что все это прекрасно компилируется и развертывается в Tomcat. Но когда я нажимаю на dept_forms_webclient в localhost:8080/manager, он выдает следующее:
org.springframework.beans.NotWritablePropertyException: Invalid property 'service' of bean class [gov.azdeq.forms.web.controller.BaseController]: Bean property 'service' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Похоже, что прокси-бин вводится нормально, похоже, мне не следует устанавливать его в FormsEndpoint независимо от того, что говорят различные tuts.
Итак, больше путаницы в конфигурации, кто-нибудь может определить, что здесь не так?
ТИА,
Все еще учусь Стив
1 ответ
Я все заработал, потеряв инъекцию зависимостей в контекстный файл и используя @Autowired в контроллере, вот так:
<!-- controllers -->
<bean id="baseController" class="gov.azdeq.forms.web.controller.BaseController" />
а также
@RequestMapping
@Controller("baseController")
public class BaseController
{
@Autowired
@Resource(name="formsWebServicePortProxy")
FormsEndpoint formsWebServicePortProxy;
Не уверен, почему использование @Autowired работает, а ручное внедрение свойств - нет. Да.
Спасибо всем, кто ответил, это дало мне немного понимания.
ДЕЛО ЗАКРЫТО
Все еще учусь Стив