我使用OSGI并创建了Web服务。我的应用服务器是Glassfish 3. Java 1.7
@WebService(name="MyService", serviceName = "MyWebServices")
public interface IMyService
{
//some code
}
@Stateless(name = "MyService")
@HandlerChain(file = "handler-chain.xml")
@WebService(serviceName = "MyWebServices", endpointInterface="com.examlple.webservices.IMyService")
public class MyService implements IMyService
{
//some code
}
我的服务有效!我想添加Servlet过滤器。我在this topic中找到了答案,我应该将@RequestScoped注释添加到我的服务实现中。
@Stateless(name = "MyService")
@HandlerChain(file = "handler-chain.xml")
@WebService(serviceName = "MyWebServices", endpointInterface="com.examlple.webservices.IMyService")
@RequestScoped
public class MyService implements IMyService
{
//some code
}
但在那之后,我在回复中得到了错误404。我找不到这个错误的原因。
答案 0 :(得分:0)
我猜这里的ServletFilter是错误的工具,因为你没有servlet。看起来你需要的是SoapHandler。
以下是一个示例:
import java.io.IOException;
import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
public class MyServiceLogHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public Set<QName> getHeaders() {
// TODO Auto-generated method stub
return null;
}
@Override
public void close(MessageContext arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean handleFault(SOAPMessageContext arg0) {
SOAPMessage message= arg0.getMessage();
try {
message.writeTo(System.out);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
@Override
public boolean handleMessage(SOAPMessageContext arg0) {
SOAPMessage message= arg0.getMessage();
boolean isOutboundMessage= (Boolean)arg0.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if(isOutboundMessage){
System.out.println("OUTBOUND MESSAGE\n");
}else{
System.out.println("INBOUND MESSAGE\n");
}
try {
message.writeTo(System.out);
} catch (SOAPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
另见: