WebService Intercept.

Source: Internet
Author: User

When we have more permissions to intercept the WebService interface to determine if it is possible to invoke one of my demo

First we write an interception class

Import javax.xml.soap.SOAPException;

Import Org.apache.cxf.interceptor.Fault;
Import Org.apache.cxf.message.Message;
Import org.apache.cxf.message.MessageContentsList;
Import Org.apache.cxf.phase.AbstractPhaseInterceptor;
Import Org.apache.cxf.phase.Phase;
Import org.springframework.beans.factory.annotation.Autowired;

Import Com.sinotrans.eaiconsole.model.EsUserModel;
Import Com.sinotrans.eaiconsole.user.service.LoginManager;

public class Webserviceuserauthorityinterceptor extends Abstractphaseinterceptor<message> {

@Autowired
Loginmanager Loginmanager;

Public Webserviceuserauthorityinterceptor () {
Super (Phase.pre_invoke);

}

public void Handlemessage (Message message) throws Fault {//Specify CXF get client HttpServletRequest
// :
Http-request;

Messagecontentslist contents = Messagecontentslist
. getcontentslist (message);

String userName = "", pwd = "";

if (contents! = null && contents.size () > 0) {

UserName = (String) contents.get (0);

PWD = (String) contents.get (1);

Esusermodel eum = loginmanager.longinwebserviceuserauthority (
UserName, PWD);

if (null = = Eum) {

SoapException Soapexc = new SoapException ("User name password Authentication failed");
throw new Fault (SOAPEXC);
}
} else {
SoapException Soapexc = new SoapException ("parameter information not entered");
throw new Fault (SOAPEXC);
}
}

}

Then we configure the following in the CXF

Our interception class is injected into the

<bean id= "Inmessageinterceptor"
class= "Com.sinotrans.eaiconsole.Interceptor.WebServiceUserAuthorityInterceptor" >

</bean>

Inject our interception class into a method that requires interception

<jaxws:endpoint id= "Lmswebservice"
Implementor= "Com.sinotrans.eaiconsole.service.impl.LMSWebServiceImpl"
address= "/lmswebservice" >

<jaxws:inInterceptors>
<ref bean= "Inmessageinterceptor"/>
</jaxws:inInterceptors>

</jaxws:endpoint>

WebService Intercept.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.