PDA

View Full Version : XFIRE newbie problems



6sic6
Oct 3rd, 2006, 06:00 AM
hello
I want to use xfire for the first time. I want to expose a WebService for 'Login'

in my web.xml I've


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>

<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

my xfire-servlet.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>



<bean id="loginBean" class="com.omc.service.Login">
<description>Object that we want to expose as WebService</description>
</bean>

<bean class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="urlMap">
<map>
<entry key="/LoginService">
<ref bean="login" />
</entry>
</map>
</property>
</bean>

<!-- Declare a parent bean with all properties common to both services -->
<bean id="login" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory" />
</property>
<property name="xfire">
<ref bean="xfire" />
</property>
<property name="serviceBean">
<ref bean="loginBean" />
</property>
<property name="serviceClass">
<value>com.omc.service.ILogin</value>
</property>
</bean>

</beans>

ILogin.java

package com.omc.service;

public interface ILogin {
public Profile getProfile(String username, String password);
}

Login.java

package com.omc.service;

public class Login implements ILogin {

private Profile profile;
public Login() {
profile = new Profile();
profile.setName("John");
profile.setSurname("Burry");
profile.setUsername("ao");
profile.setPassword("ao");
}

public Profile getProfile(String username, String password) {
if (profile.getUsername()==username && profile.getPassword()==password) {
System.out.println("return Profile");
return profile;
}
return null;
}

}

Profile.java

package com.omc.service;

public class Profile {
private String name;
private String surname;
private String username;
private String password;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}



}

and this's my client class to test the WebService

package com.omc.client;

import java.net.MalformedURLException;

import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFa ctory;
import org.codehaus.xfire.client.XFireProxyFactory;

public class TestService {
public static void main(String[] args) {
Service serviceModel = new ObjectServiceFactory().create(ILogin.class);
System.out.println("Test Servizio");
try {
ILogin service = (ILogin) new XFireProxyFactory().create(serviceModel, "http://localhost:8080/OMC/services/LoginService");
Profile p = service.getProfile("ao","ao");
System.out.println(p.getName());
System.out.println(p.getSurname());
} catch (MalformedURLException e) {
e.printStackTrace();
}

}
}



The WS doesn't go. This's the log of the server I don't have errors



........
........
MIT: 2110 [main] DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Bean 'xfire.messageServiceFactory' instantiated via constructor [public org.codehaus.xfire.service.binding.ObjectServiceFa ctory(org.codehaus.xfire.transport.TransportManage r,org.codehaus.xfire.service.binding.BindingProvid er)]
MIT: 2110 [main] DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Eagerly caching bean with name 'xfire.messageServiceFactory' to allow for resolving potential circular references
MIT: 2110 [main] DEBUG org.springframework.beans.BeanWrapperImpl - About to invoke write method [public void org.codehaus.xfire.service.binding.ObjectServiceFa ctory.setStyle(java.lang.String)] on object of class [org.codehaus.xfire.service.binding.ObjectServiceFa ctory]
MIT: 2110 [main] DEBUG org.springframework.beans.BeanWrapperImpl - Invoked write method [public void org.codehaus.xfire.service.binding.ObjectServiceFa ctory.setStyle(java.lang.String)] with value of type [java.lang.String]
MIT: 2110 [main] DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Invoking BeanPostProcessors before initialization of bean 'xfire.messageServiceFactory'
MIT: 2110 [main] DEBUG org.springframework.beans.factory.support.DefaultL istableBeanFactory - Invoking BeanPostProcessors after initialization of bean 'xfire.messageServiceFactory'
MIT: 2110 [main] DEBUG org.springframework.web.context.support.XmlWebAppl icationContext - Publishing event in context [Root WebApplicationContext]: org.springframework.context.event.ContextRefreshed Event[source=org.springframework.web.context.support.Xml WebApplicationContext: display name [Root WebApplicationContext]; startup date [Tue Oct 03 12:57:40 CEST 2006]; root of context hierarchy; config locations [classpath:org/codehaus/xfire/spring/xfire.xml]]
MIT: 2110 [main] INFO org.springframework.web.context.ContextLoader - Using context class [org.springframework.web.context.support.XmlWebAppl icationContext] for root WebApplicationContext
MIT: 2110 [main] DEBUG org.springframework.web.context.ContextLoader - Published root WebApplicationContext [org.springframework.web.context.support.XmlWebAppl icationContext: display name [Root WebApplicationContext]; startup date [Tue Oct 03 12:57:40 CEST 2006]; root of context hierarchy; config locations [classpath:org/codehaus/xfire/spring/xfire.xml]] as ServletContext attribute with name [interface org.springframework.web.context.WebApplicationCont ext.ROOT]
MIT: 2110 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1813 ms
MIT: 2110 [main] DEBUG org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/OMC] - Starting filters
MIT: 2141 [main] DEBUG org.apache.jasper.compiler.JspRuntimeContext - Parent class loader is: WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@eca 36e

MIT: 2141 [main] DEBUG org.apache.jasper.servlet.JspServlet - Scratch dir for the JSP engine is: C:\AdvisoryToolDev\jakarta-tomcat-5.5.9\work\Catalina\localhost\OMC
MIT: 2141 [main] DEBUG org.apache.jasper.servlet.JspServlet - IMPORTANT: Do not modify the generated servlets
Oct 3, 2006 12:57:42 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Oct 3, 2006 12:57:42 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Oct 3, 2006 12:57:43 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 3, 2006 12:57:43 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 3, 2006 12:57:43 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/47 config=null
Oct 3, 2006 12:57:43 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Oct 3, 2006 12:57:44 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9234 ms
MIT: 62766 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] DEBUG org.apache.catalina.session.ManagerBase - Start expire sessions StandardManager at 1159873123281 sessioncount 0
MIT: 62766 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] DEBUG org.apache.catalina.session.ManagerBase - End expire sessions StandardManager processingTime 0 expired sessions: 0


when I try to start the client I've this error code

log4j:WARN No appenders could be found for logger (org.codehaus.xfire.transport.DefaultTransportMana ger).
log4j:WARN Please initialize the log4j system properly.
Test Servizio
Exception in thread "main" java.lang.NullPointerException
at com.omc.client.TestService.main(TestService.java:1 6)

If I try to go to
http://localhost:8080/OMC/services/LoginService?wsdl
I can see the correct wsdl
Someone can help me?
thanks a lot guys
martina

jpederzolli
Oct 4th, 2006, 12:15 PM
The most obvious thing I see is to change

if (profile.getUsername()==username && profile.getPassword()==password) {
System.out.println("return Profile");
return profile;
}

to

if (profile.getUsername().equals(username) && profile.getPassword().equals(password)) {
System.out.println("return Profile");
return profile;
}

- John