gpt4 book ai didi

java - 如何在Tomcat7中部署WS

转载 作者:行者123 更新时间:2023-11-30 06:25:53 24 4
gpt4 key购买 nike

我有一个包含类和 JSP 的 Web 应用程序,我使用 mvn clean package -Dmaven.test.skip=true 打包创建 war

我在应用程序中有这个类:

import javax.jws.WebMethod;
import javax.jws.WebService;

import javax.servlet.http.HttpSession;

import javax.xml.ws.WebServiceContext;

import javax.xml.ws.handler.MessageContext;


@WebService(serviceName="IberiaWS")
public class IberiaWS {

@Resource
private WebServiceContext wsContext;

public IberiaWS () {
}

private UserVO getSessionUserVO() {
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
return (UserVO)session.getAttribute("uservo");
}

private void setSessionUserVO(UserVO uservo) {
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
session.setAttribute("uservo", uservo);

}

@WebMethod
public boolean login(String loginName, String loginPwd) throws Exception {
this.setSessionUserVO(new UserDAO().findUser("_"+loginName, "__"+loginPwd));
return isConnected();
}

@WebMethod
public boolean isConnected() {
return (this.getSessionUserVO()!=null);
}

@WebMethod
public IberiaPerson getPerson(String id) {
return new IberiaPerson();
}

@WebMethod
public IberiaPerson findPerson(String companyNr) {
UserVO uservo = this.getSessionUserVO();
IberiaPerson ret=null;
PersonVO p= new PersonDAO().findByCompanyNr(uservo.getAdminCenterId(), uservo.getUserId(), "Iberia", companyNr);
if (p!=null) {
ret = new IberiaPerson();
ret.setPersonId(p.getPersonId());
ret.setCompanyName(p.getVehicleOwnerName());
ret.setCategoryName(p.getCategoryName());
ret.setCompanyNr(p.getCompanyNr());
ret.setFirstName(p.getFirstName());
ret.setLastName(p.getLastName());
ret.setStatusId(p.getStatusId());
ret.setGroupName(p.getGroupList());
ret.setKeyCode(p.getKeyString());
ret.setComments(p.getLmComment());
}
return ret;
}
}

我创建了 war 并将其部署在 Tomcat 中。我想访问WS的WSDL,但我不知道该怎么做。显然我没有创建应用程序,我只是获得了源代码,但我不知道如何访问 WS。由于应用程序部署在 iberiafleet 上下文中,我尝试了 http://localhost:8080/iberiafleet/IberiaWSPort?WSDL但我收到了 HTTP 404 错误

这是项目的 web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>

有没有办法用maven构建、打包和部署WS?

我已将 web.xml 更改为此,但我无法访问

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>
IberiaWSPort
</servlet-name>
<servlet-class>
com.iberia.webservice.IberiaWS
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>
IberiaWSPort
</servlet-name>
<url-pattern>
/IberiaWSPort
</url-pattern>
</servlet-mapping>
</web-app>

最佳答案

请遵循以下示例代码

请引用link

<?xml version="1.0" encoding="UTF-8"?><endpoints  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"  version="2.0">  
<endpoint name="AccountDetailsServiceEndPoint" service ="{http://gognamunish.com/accounts}AccountDetailsService" port="{http://gognamunish.com/accounts}AccountDetailsPort" implementation="com.mg.ws.impl.AccountDetailsServiceImpl" url-pattern="/details" wsdl="WEB-INF/wsdl/accounts.wsdl"/></endpoints>

关于java - 如何在Tomcat7中部署WS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com