2010. 6. 28. 15:47
apache cxf 는 기본적으로 thread safety를 지원 하지 않는다고 한다. 뭐 그래서 어쩌구 저쩌구 하지만... 다른 방법으로 할수 있다고는 한다.
cxf.xml
Server Side - service class
Client side class
위 코드는 미친척하고 테스트용으로 만든거임.. 테스트용으로만 사용하삼. 쩌ㅃ~
cxf.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<httpj:engine-factory bus="cxf">
<httpj:engine port="9000">
<httpj:sessionSupport>true</httpj:sessionSupport>
</httpj:engine>
</httpj:engine-factory>
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
xsi:schemaLocation="
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<httpj:engine-factory bus="cxf">
<httpj:engine port="9000">
<httpj:sessionSupport>true</httpj:sessionSupport>
</httpj:engine>
</httpj:engine-factory>
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
</beans>
Server Side - service class
package bbaeggar.jaxws.simple.server.service;
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
@WebService(endpointInterface = "bbaeggar.jaxws.simple.server.service.Login",
serviceName = "Login")
public class LoginImpl implements Login {
//webServiceContext is injected by the JAXWS API
@Resource private WebServiceContext wsContext;
SessionVo sessionVo;
@Override
public boolean login(String id, String pw) {
// TODO Auto-generated method stub
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession(true);
// Get a session property "counter" from context
if (session == null)
System.out.println("session is null");
sessionVo = new SessionVo();
sessionVo.setId(id);
sessionVo.setPw(pw);
session.setAttribute("session", sessionVo);
return true;
}
@Override
public String getId() {
// TODO Auto-generated method stub
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
SessionVo vo = (SessionVo)session.getAttribute("session");
return vo.getId();
}
}
import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
@WebService(endpointInterface = "bbaeggar.jaxws.simple.server.service.Login",
serviceName = "Login")
public class LoginImpl implements Login {
//webServiceContext is injected by the JAXWS API
@Resource private WebServiceContext wsContext;
SessionVo sessionVo;
@Override
public boolean login(String id, String pw) {
// TODO Auto-generated method stub
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession(true);
// Get a session property "counter" from context
if (session == null)
System.out.println("session is null");
sessionVo = new SessionVo();
sessionVo.setId(id);
sessionVo.setPw(pw);
session.setAttribute("session", sessionVo);
return true;
}
@Override
public String getId() {
// TODO Auto-generated method stub
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
SessionVo vo = (SessionVo)session.getAttribute("session");
return vo.getId();
}
}
Client side class
package bbaeggar.jaxws.simple.client;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import bbaeggar.jaxws.simple.server.service.HelloWorld;
import bbaeggar.jaxws.simple.server.service.Login;
public class TestRunnable implements Runnable {
@Override
public void run() {
login();
}
public void login() {
Service service = Service.create(Client.SERVICE_LOGIN);
String endpointAddress = "http://localhost:9000/Login";
service.addPort(Client.PORT_LOGIN, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Login login = service.getPort(Login.class);
Map requestContext = ((BindingProvider)login).getRequestContext();
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
String id = "bbaeggar" + Thread.currentThread().getId();
boolean isLogin = login.login(id, "aaaa");
System.out.println("client : " + login.getId());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(id.equals(login.getId())) {
System.out.println("같은 세션임");
} else {
System.out.println("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
}
}
}
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import bbaeggar.jaxws.simple.server.service.HelloWorld;
import bbaeggar.jaxws.simple.server.service.Login;
public class TestRunnable implements Runnable {
@Override
public void run() {
login();
}
public void login() {
Service service = Service.create(Client.SERVICE_LOGIN);
String endpointAddress = "http://localhost:9000/Login";
service.addPort(Client.PORT_LOGIN, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Login login = service.getPort(Login.class);
Map requestContext = ((BindingProvider)login).getRequestContext();
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
String id = "bbaeggar" + Thread.currentThread().getId();
boolean isLogin = login.login(id, "aaaa");
System.out.println("client : " + login.getId());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(id.equals(login.getId())) {
System.out.println("같은 세션임");
} else {
System.out.println("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
}
}
}
위 코드는 미친척하고 테스트용으로 만든거임.. 테스트용으로만 사용하삼. 쩌ㅃ~
'framework > apache cxf' 카테고리의 다른 글
[Apache cxf] - log4j 설정하자 (0) | 2010.06.28 |
---|---|
[Apache cxf] - 톰켓에서 한글 설정하자 (0) | 2010.06.28 |
[Apache cxf] - WSDL to Java (0) | 2010.06.28 |
[Apache cxf] cxf, axis2, metro 성능 비교 (0) | 2010.06.28 |
[Apache cxf] - Spring 에서 endpoint 설정하자 (0) | 2010.06.28 |