java - How to create request scoped web service port? -


i have spring mvc based web application calls web service. web service requires http based authentication every call.i hold web service proxy configuration in applicationcontext.xml:

<beans...  <bean id="paymentwebservice"       class="org.springframework.remoting.jaxws.jaxwsportproxyfactorybean">     <property name="customproperties">         <ref local="jaxwscustomproperties"/>     </property>     <property name="serviceinterface" value="com.azercell.paymentgateway.client.paymentgatewaywebservice"/>     <property name="wsdldocumenturl"               value="#{config.wsdldocumenturl}"/>     <property name="namespaceuri" value="http://webservice.paymentgateway.azercell.com/"/>     <property name="servicename" value="paymentgatewaywebserviceimplservice"/>     <property name="portname" value="paymentgatewaywebserviceimplport"/> </bean> 

i have instance field web service port in controller:

@controller public class paymentcontroller {  @resource(name = "paymentwebservice") private paymentgatewaywebservice paymentport;  @modelattribute public void ajaxattribute(webrequest request, model model) {     utilmethods.authenticationwebserviceport(paymentport);     ... } ...  @requestmapping(value = "/masspayment", method = requestmethod.post) public string masspayment(@requestparam string amount, @requestparam multipartfile file, model model, locale locale) {     ...      webserviceresponse response = paymentport.masspayment(utilmethods.getnewrequestid()              , fileuploader, utilmethods.getamountincoins(amountbigdecimal), null);      ...            return springview.mass_payment.tostring(ajaxrequest);    } } 

code of utilmethods.authenticationwebserviceport:

public static void authenticationwebserviceport(paymentgatewaywebservice paymentport) {     string username = (string) requestcontextholder.currentrequestattributes().getattribute(username_session_variable_name, requestattributes.scope_session);     string password = (string) requestcontextholder.currentrequestattributes().getattribute(password_session_variable_name, requestattributes.scope_session);     bindingprovider prov = (bindingprovider) paymentport;     prov.getrequestcontext().put(bindingprovider.username_property, username);     prov.getrequestcontext().put(bindingprovider.password_property, password); } 

as controllers singleton objects there occurring problems every time when requests overlap, if precisely 1 user mistake can use web methods username , password belong user.

to prevent tried make web service port request scoped in configuration below:

<bean id="paymentwebservice"   class="org.springframework.remoting.jaxws.jaxwsportproxyfactorybean" scope="request"> 

in case got error:

    severe: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.filterchains': cannot resolve reference bean 'org.springframework.security.web.defaultsecurityfilterchain#0' while setting bean property 'sourcelist' key [0]; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.web.defaultsecurityfilterchain#0': cannot resolve reference bean 'org.springframework.security.web.authentication.usernamepasswordauthenticationfilter#0' while setting constructor argument key [2]; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.web.authentication.usernamepasswordauthenticationfilter#0': cannot resolve reference bean 'org.springframework.security.authentication.providermanager#0' while setting bean property 'authenticationmanager'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.authentication.providermanager#0': cannot resolve reference bean 'org.springframework.security.config.authentication.authenticationmanagerfactorybean#0' while setting constructor argument; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.config.authentication.authenticationmanagerfactorybean#0': factorybean threw exception on object creation; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.security.authenticationmanager': cannot resolve reference bean 'myauthenticationprovider' while setting constructor argument key [0]; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'myauthenticationprovider': injection of resource dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'paymentwebservice': scope 'request' not active current thread; consider defining scoped proxy bean if intend refer singleton; nested exception java.lang.illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? if operating within web request , still receive message, code running outside of dispatcherservlet/dispatcherportlet: in case, use requestcontextlistener or requestcontextfilter expose current request. 

how create request scoped web service port?

try expose current http request spring. add requestcontextlistener in web.xml:

<web-app> ... <listener>   <listener-class>       org.springframework.web.context.request.requestcontextlistener   </listener-class> </listener> ... </web-app> 

see this entry official documentation more details / options.

edit. think difference in lifecycle between controller , paymentport dependency. controller same, paymentport must refreshed each new request. cann't continue inject directly. need fresh instance each request. can using javax.inject.provider interface.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -