web services - Enable Police in CXF 3.0 and Spring with Contract-First -


i'm trying implement ws-policy in services cxf 3.1.0 , spring 4.1.6

most of examples found cxf 2 , structures cxf-extension-policy.xml , cxf-extension-ws-security.xml changed in cxf new version.

i tried like:

package spring;  import java.util.linkedlist; import java.util.list;  import javax.xml.ws.endpoint;  import org.apache.cxf.bus; import org.apache.cxf.feature.abstractfeature; import org.apache.cxf.jaxws.endpointimpl; import org.apache.cxf.ws.policy.wspolicyfeature; import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.importresource;  import com.student.studentservice; import com.student.service.studentserviceimpl;  @configuration @importresource({"classpath:meta-inf/cxf/cxf.xml"}) public class cxfconfig {  @autowired private bus cxfbus;  @bean public studentservice service(){     return new studentserviceimpl(); }  @autowired @bean public endpoint serviceimpl(         final studentservice service){      endpointimpl endpoint = new endpointimpl(this.cxfbus, service);     endpoint.setaddress("/studentservice");     endpoint.publish();      return endpoint; } } 

my wsdl have policies , wsdl this tutorial

i generate java classes using contract-first.

when run project policies don't appears.

i tried

final map<string, object> properties = new hashmap<>(); properties.put(wshandlerconstants.action, wshandlerconstants.username_token); properties.put(wshandlerconstants.password_type, wsconstants.pw_text); properties.put(wshandlerconstants.pw_callback_ref, serverpasswordcallback.class.getname());  endpointimpl endpoint = new endpointimpl(this.cxfbus, porttype); endpoint.setproperties(properties); endpoint.setaddress("/studentservice"); endpoint.publish();  return endpoint; 

i tryed

final map<string, object> properties = new hashmap<>(); properties.put(wshandlerconstants.action, wshandlerconstants.username_token); properties.put(wshandlerconstants.password_type, wsconstants.pw_text); properties.put(wshandlerconstants.pw_callback_ref, serverpasswordcallback.class.getname());  cxfbus.getfeatures().add(new wspolicyfeature()); cxfbus.getininterceptors().add(new wss4jininterceptor(properties));  endpointimpl endpoint = new endpointimpl(this.cxfbus, porttype); endpoint.setaddress("/studentservice"); endpoint.publish();  return endpoint; 

and

wspolicyfeature wspolicyfeature = new wspolicyfeature(); wspolicyfeature.initialize(this.cxfbus); 

none of works.

does knows how configure spring annotations?

after while, discover wss4j uses idea of interceptor instead of policies in contract.

i changed spring implementation to

    endpointimpl endpoint = new endpointimpl(this.cxfbus, flightservice);     endpoint.setaddress("/flightservice");     endpoint.setwsdllocation("src/main/resources/wsdls/flightservice_v1r1.wsdl");     endpoint.getproperties().put("ws-security.callback-handler", new serverpasswordcallback());     endpoint.publish(); 

however, configuration when deployed contract showed 2 wsdl:binding , 2 wsdl:service...

i found way solve problem , less couple first one, externalize policies in xml file , anotated service with

@policies({   @policy(uri="classpath:policies/usernametoken.xml", includeinwsdl=true) }) 

my spring configuration reduced to

endpointimpl endpoint = new endpointimpl(this.cxfbus, new flightserviceimpl()); endpoint.setaddress("/flightservice"); endpoint.getproperties().put("ws-security.callback-handler", new serverpasswordcallback()); endpoint.publish(); 

when deploy me project, see

<wsdl:service name="flightserviceimplservice">   <wsdl:port binding="tns:flightserviceimplservicesoapbinding" name="flightserviceimplport">     <soap:address location="http://localhost:8080/ws-security/flightservice"/>   </wsdl:port>   <wsp:policyreference uri="#authenticationpolicy"/> </wsdl:service> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -