List of usage examples for javax.xml.ws Service setHandlerResolver
public void setHandlerResolver(HandlerResolver handlerResolver)
From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java
/** * This class authenticates with the Hiperium Platform using JAXBContext and the selects user's home and * profile to access the system functions, and finally end the session. For all this lasts functions * we use SOAP messages with dispatchers and not JAXBContext. * /*from w ww. ja v a 2 s . c om*/ * We need to recall, that for JAXBContext we could not add a handler to add header security parameters that need * to be verified in every service call in the Hiperium Platform, and for that reason, we only use JAXBContext in * the authentication process that do not need this header validation in the SOAP message header. * * @param args */ public static void main(String[] args) { try { URL authURL = new URL(AUTH_SERVICE_URL); // The NAMESPACE must be http://authentication.soap.web.hiperium.com/ and must not begin // with http://SEI.authentication.soap.web.hiperium.com. Furthermore, the service name // and service port name must end WSService and WSPort respectively in order to call the service. QName authServiceQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSService"); QName authPortQName = new QName(AUTH_NAMESPACE, "UserAuthenticationWSPort"); // The parameter class must be annotated with @XmlRootElement in order to function JAXBContext jaxbContext = JAXBContext.newInstance(UserAuthentication.class, UserAuthenticationResponse.class); Service authService = Service.create(authURL, authServiceQName); // When we use JAXBContext the dispatcher mode must be PAYLOAD and NOT MESSAGE mode Dispatch<Object> dispatch = authService.createDispatch(authPortQName, jaxbContext, Service.Mode.PAYLOAD); UserCredentialDTO credentialsDTO = new UserCredentialDTO("andres_solorzano85@hotmail.com", "andres123"); UserAuthentication authenticateRequest = new UserAuthentication(); authenticateRequest.setArg0(credentialsDTO); UserAuthenticationResponse authenticateResponse = (UserAuthenticationResponse) dispatch .invoke(authenticateRequest); String sessionId = authenticateResponse.getReturn(); LOGGER.debug("SESSION ID: " + sessionId); // Verify if session ID exists if (StringUtils.isNotBlank(sessionId)) { // Select home and profile URL selectHomeURL = new URL(HOME_SELECTION_SERVICE_URL); Service selectHomeService = Service.create(selectHomeURL, new QName(AUTH_NAMESPACE, "HomeSelectionWSService")); selectHomeService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(), CLIENT_APPLICATION_TOKEN, AuthenticationObjectFactory._SelectHome_QNAME)); Dispatch<SOAPMessage> selectHomeDispatch = selectHomeService.createDispatch( new QName(AUTH_NAMESPACE, "HomeSelectionWSPort"), SOAPMessage.class, Service.Mode.MESSAGE); CommonsUtil.addSessionHeaderParms(selectHomeDispatch, sessionId); HomeSelectionDTO homeSelectionDTO = new HomeSelectionDTO(1L, 1L); SOAPMessage response = selectHomeDispatch.invoke(createSelectHomeSOAPMessage(homeSelectionDTO)); readSOAPMessageResponse(response); // End Session URL endSessionURL = new URL(END_SESSION_SERVICE_URL); QName endSessionServiceQName = new QName(GENERAL_NAMESPACE, "MenuWSService"); QName endSessionPortQName = new QName(GENERAL_NAMESPACE, "MenuWSPort"); Service endSessionService = Service.create(endSessionURL, endSessionServiceQName); endSessionService.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(), CLIENT_APPLICATION_TOKEN, GeneralObjectFactory._EndSession_QNAME)); Dispatch<SOAPMessage> endSessionDispatch = endSessionService.createDispatch(endSessionPortQName, SOAPMessage.class, Service.Mode.MESSAGE); CommonsUtil.addSessionHeaderParms(endSessionDispatch, sessionId); response = endSessionDispatch.invoke(createEndSessionSOAPMessage()); readSOAPMessageResponse(response); } } catch (MalformedURLException e) { LOGGER.error(e.getMessage(), e); } catch (JAXBException e) { LOGGER.error(e.getMessage(), e); } }
From source file:com.moss.rpcutil.proxy.jaxws.JAXWSProxyProvider.java
public synchronized <T> T getProxy(Class<T> iface, String url) { QName type = registry.get(iface); if (type == null) { throw new RuntimeException("Service type not registered: " + iface); }// w ww . j a v a 2s .co m T proxy = (T) cache.get(url); if (proxy == null) { Service service; try { String wsdlLocation = url; if (!wsdlLocation.endsWith("?wsdl")) { wsdlLocation += "?wsdl"; } service = Service.create(new URL(wsdlLocation), type); } catch (Exception ex) { throw new RuntimeException(ex); } if (log.isDebugEnabled()) { // SOAP LOGGING STUFF service.setHandlerResolver(new HandlerResolver() { public List<Handler> getHandlerChain(PortInfo arg0) { List<Handler> handlers = new LinkedList<Handler>(); handlers.add(new SOAPLoggingHandler(log)); return handlers; } }); } proxy = service.getPort(iface); // BindingProvider bp = (BindingProvider) proxy; // // bp.getRequestContext().put( // MessageContext.HTTP_REQUEST_HEADERS, // Collections.singletonMap("Content-Type", Arrays.asList(new String[]{"application/soap+xml", "charset=utf-8"})) // ); cache.put(url, proxy); } return proxy; }