Hi Colm, If I remove the <jaxws:client element, it still work as before, so I guess this client xml declaration is not taken into account as we're just programmatically re-doing what the spring configuration does...
As I stated earlier, I'm already in a spring context (J2EE Spring MVC application), that's why I don't understand the BusFactory need to be given the spring xml file. I've understood that while seeing that the endpoint was not taken into account (thanks to my Virtual machine that changes of IP each time I resume my mac). So I'll focus to make it work programmatically first, then figure out how to use the spring XML configurations files and finally try to use my own generated WS Client instead of generating it on the fly. For now, I'm still blocked on enabling a security policy on the client side programmatically. For instance, my password callback handler is not taken into account, as it's not called at all. (the method public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException is not called) I programmatically specify it as follow (full code at the end of the mail): *this*.workListService = service.getPort(portQName, WorkListService.*class* ); ((BindingProvider)*this*.workListService ).getRequestContext().put(BindingProvider.*ENDPOINT_ADDRESS_PROPERTY*, " http://192.168.2.213:8080/amxbpm/WorkListService"); //I've also tryed by just specificying a class name, but don't work either. PasswordCallbackHandler passwordCallbackHandler = *new*PasswordCallbackHandler( "secret"); ((BindingProvider)*this*.workListService ).getRequestContext().put(SecurityConstants.*CALLBACK_HANDLER*, passwordCallbackHandler); In the CXF samples, it's done like this: <jaxws:client name=*"{ http://www.example.org/contract/DoubleIt}DoubleItPlaintextPrincipalPort" * createdFromAPI=*"true"*> <jaxws:properties> <entry key=*"ws-security.callback-handler" * value=* "org.apache.cxf.systest.ws.wssec10.client.UTPasswordCallback"*/> </jaxws:properties> </jaxws:client> So I wonder what I miss... Thomas. package com.mansonthomas.amxbpm.customwebapp.services.amxbpm; import java.net.URL; import java.util.ArrayList; import java.util.List; import javax.xml.namespace.QName; import javax.xml.transform.Source; import javax.xml.ws.BindingProvider; import javax.xml.ws.EndpointReference; import javax.xml.ws.Service; import javax.xml.ws.WebServiceFeature; import javax.xml.ws.wsaddressing.W3CEndpointReference; import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBusFactory; import org.apache.cxf.endpoint.Client; import org.apache.cxf.ws.security.SecurityConstants; import org.springframework.beans.factory.InitializingBean; import com.mansonthomas.amxbpm.customwebapp.model.WorkItemFwk; import com.mansonthomas.amxbpm.customwebapp.model.WorkListItemQuery; import com.mansonthomas.amxbpm.customwebapp.services.amxbpm.context.ContextService; import com.mansonthomas.amxbpm.customwebapp.services.amxbpm.mapper.WorkItemMapper; import com.mansonthomas.amxbpm.customwebapp.services.amxbpm.security.PasswordCallbackHandler; import com.tibco.n2.brm.api.GetWorkListItems; import com.tibco.n2.brm.api.GetWorkListItemsResponse; import com.tibco.n2.brm.api.OrderFilterCriteria; import com.tibco.n2.brm.api.WorkItem; import com.tibco.n2.brm.services.WorkListService; import com.tibco.n2.common.organisation.api.OrganisationalEntityType; import com.tibco.n2.common.organisation.api.XmlModelEntityId; public class WorkListServiceImpl2 implements WorkListFwkService, InitializingBean { private static final Log logger = LogFactory.getLog(WorkListServiceImpl2.class); private WorkListService workListService = null; private ContextService contextService = null; public WorkListServiceImpl2( ContextService contextService) throws Exception { this.contextService = contextService; SpringBusFactory bf = new SpringBusFactory(); URL busFile = this.contextService.getResource("/WEB-INF/spring/webservices2.xml"); Bus bus = bf.createBus(busFile.toString()); SpringBusFactory.setDefaultBus(bus); SpringBusFactory.setThreadDefaultBus(bus); URL wsdl = this.contextService.getResource("/wsdl/brm.wsdl"); Service service = Service.create(wsdl, new QName(" http://services.brm.n2.tibco.com","WorkListService")); QName portQName = new QName("http://services.brm.n2.tibco.com", "WorkListService_EP"); this.workListService = service.getPort(portQName, WorkListService.class); ((BindingProvider)this.workListService).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://192.168.2.213:8080/amxbpm/WorkListService"); PasswordCallbackHandler passwordCallbackHandler = new PasswordCallbackHandler("secret"); ((BindingProvider)this.workListService).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, passwordCallbackHandler); } public List<WorkItemFwk> getWorkListItems(String username, WorkListItemQuery workListItemQuery) { XmlModelEntityId entityId = new XmlModelEntityId(); entityId.setGuid(workListItemQuery.getUserGUID()); entityId.setEntityType(OrganisationalEntityType.RESOURCE); entityId.setModelVersion(-1); GetWorkListItems getWorkListItems = new GetWorkListItems(); getWorkListItems.setGetTotalCount (true); getWorkListItems.setEntityID (entityId); getWorkListItems.setStartPosition (workListItemQuery.getStart()); getWorkListItems.setNumberOfItems (workListItemQuery.getNumberOfItems()); getWorkListItems.setOrderFilterCriteria (new OrderFilterCriteria()); GetWorkListItemsResponse getWorkListItemsResponse = null; try { ((BindingProvider)this.workListService).getRequestContext().put("thread.local.request.context", "true"); ((BindingProvider)this.workListService).getRequestContext().put(SecurityConstants.USERNAME, username); getWorkListItemsResponse = this.workListService.getWorkListItems(getWorkListItems); } catch(Exception e) { logger.error("Error while getting worklistItems for "+workListItemQuery.toString(),e); } if(getWorkListItemsResponse == null) { logger.error("recieve a null response while getting worklistItems for "+workListItemQuery.toString()); return new ArrayList<WorkItemFwk>(0); } List<WorkItem> workitems = getWorkListItemsResponse.getWorkItems(); List<WorkItemFwk> workListItemFwk = new ArrayList<WorkItemFwk>(workitems.size()); int i = 0; for (WorkItem workItem : workitems) { workListItemFwk.add(WorkItemMapper.map(workItem, i++)); } return workListItemFwk; } @Override public void afterPropertiesSet() throws Exception { WorkListItemQuery workListItemQuery = new WorkListItemQuery(); workListItemQuery.setStart(0l); workListItemQuery.setNumberOfItems(10l); workListItemQuery.setUsername("tibco-admin"); workListItemQuery.setUserGUID("tibco-admin"); this.getWorkListItems("tibc-admin", workListItemQuery); } }
