List of usage examples for javax.xml.ws BindingProvider getRequestContext
Map<String, Object> getRequestContext();
From source file:org.openehealth.ipf.platform.camel.ihe.ws.AbstractWsProducer.java
@Override public void process(Exchange exchange) throws Exception { // prepare/*from w w w. j av a2 s . c om*/ InType body = exchange.getIn().getMandatoryBody(requestClass); Object client = getClient(); configureClient(client); BindingProvider bindingProvider = (BindingProvider) client; WrappedMessageContext requestContext = (WrappedMessageContext) bindingProvider.getRequestContext(); cleanRequestContext(requestContext); enrichRequestContext(exchange, requestContext); processUserDefinedOutgoingHeaders(requestContext, exchange.getIn(), true); // set request encoding based on Camel exchange property String requestEncoding = exchange.getProperty(Exchange.CHARSET_NAME, String.class); if (requestEncoding != null) { requestContext.put(org.apache.cxf.message.Message.ENCODING, requestEncoding); } // get and analyse WS-Addressing asynchrony configuration String replyToUri = getWsTransactionConfiguration().isAllowAsynchrony() ? exchange.getIn().getHeader(AbstractWsEndpoint.WSA_REPLYTO_HEADER_NAME, String.class) : null; if ((replyToUri != null) && replyToUri.trim().isEmpty()) { replyToUri = null; } // for asynchronous interaction: configure WSA headers and store correlation data if ((replyToUri != null) || Boolean.TRUE.equals(requestContext.get(AsynchronyCorrelator.FORCE_CORRELATION))) { String messageId = "urn:uuid:" + UUID.randomUUID().toString(); configureWSAHeaders(messageId, replyToUri, requestContext); AbstractWsEndpoint endpoint = (AbstractWsEndpoint) getEndpoint(); AsynchronyCorrelator correlator = endpoint.getCorrelator(); correlator.storeServiceEndpointUri(messageId, endpoint.getEndpointUri()); String correlationKey = exchange.getIn().getHeader(AbstractWsEndpoint.CORRELATION_KEY_HEADER_NAME, String.class); if (correlationKey != null) { correlator.storeCorrelationKey(messageId, correlationKey); } String[] alternativeKeys = getAlternativeRequestKeys(exchange); if (alternativeKeys != null) { correlator.storeAlternativeKeys(messageId, alternativeKeys); } } // invoke exchange.setPattern((replyToUri == null) ? ExchangePattern.InOut : ExchangePattern.InOnly); OutType result = null; try { // normalize response type when called via reflection or similar non-type-safe mechanisms result = responseClass.cast(callService(client, body)); } catch (SOAPFaultException fault) { // handle http://www.w3.org/TR/2006/NOTE-soap11-ror-httpbinding-20060321/ // see also: https://issues.apache.org/jira/browse/CXF-3768 if ((replyToUri == null) || (fault.getCause() == null) || !fault.getCause().getClass().getName().equals("com.ctc.wstx.exc.WstxEOFException")) { throw fault; } } // for synchronous interaction (replyToUri == null): handle response. // (async responses are handled in the service instance derived from // org.openehealth.ipf.platform.camel.ihe.ws.AbstractAsyncResponseWebService) if (replyToUri == null) { Message responseMessage = Exchanges.resultMessage(exchange); responseMessage.getHeaders().putAll(exchange.getIn().getHeaders()); WrappedMessageContext responseContext = (WrappedMessageContext) bindingProvider.getResponseContext(); processIncomingHeaders(responseContext, responseMessage); enrichResponseMessage(responseMessage, responseContext); // set Camel exchange property based on response encoding exchange.setProperty(Exchange.CHARSET_NAME, responseContext.get(org.apache.cxf.message.Message.ENCODING)); responseMessage.setBody(result, responseClass); } }
From source file:org.talend.components.netsuite.client.NetSuiteClientService.java
/** * Set a SOAP header to be sent to NetSuite in request * * @param port port/* w w w. j a v a 2 s . co m*/ * @param header header to be set */ protected void setHeader(PortT port, Header header) { BindingProvider provider = (BindingProvider) port; Map<String, Object> requestContext = provider.getRequestContext(); List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST); if (list == null) { list = new ArrayList<>(); requestContext.put(Header.HEADER_LIST, list); } removeHeader(list, header.getName()); list.add(header); }
From source file:org.talend.components.netsuite.client.NetSuiteClientService.java
/** * Remove a SOAP header from header list to be sent to NetSuite * * @param port port/* w ww.j a v a2 s . c o m*/ * @param name name identifying a header */ protected void removeHeader(PortT port, QName name) { BindingProvider provider = (BindingProvider) port; Map<String, Object> requestContext = provider.getRequestContext(); List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST); removeHeader(list, name); }
From source file:org.talend.components.netsuite.v2014_2.client.NetSuiteClientServiceImpl.java
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException { try {//from www. j a v a 2 s. co m URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2014.2/netsuite.wsdl"); NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE); List<WebServiceFeature> features = new ArrayList<>(2); if (isMessageLoggingEnabled()) { features.add(new LoggingFeature()); } NetSuitePortType port = service .getNetSuitePort(features.toArray(new WebServiceFeature[features.size()])); BindingProvider provider = (BindingProvider) port; Map<String, Object> requestContext = provider.getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl); GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest(); dataCenterRequest.setAccount(account); DataCenterUrls urls = null; GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest); if (response != null && response.getGetDataCenterUrlsResult() != null) { urls = response.getGetDataCenterUrlsResult().getDataCenterUrls(); } if (urls == null) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl)); } String wsDomain = urls.getWebservicesDomain(); String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath()); requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); return port; } catch (WebServiceException | MalformedURLException | UnexpectedErrorFault | ExceededRequestSizeFault e) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e); } }
From source file:org.talend.components.netsuite.v2016_2.client.NetSuiteClientServiceImpl.java
protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException { try {/* w w w.ja va 2 s. co m*/ URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2016.2/netsuite.wsdl"); NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE); List<WebServiceFeature> features = new ArrayList<>(2); if (isMessageLoggingEnabled()) { features.add(new LoggingFeature()); } NetSuitePortType port = service .getNetSuitePort(features.toArray(new WebServiceFeature[features.size()])); BindingProvider provider = (BindingProvider) port; Map<String, Object> requestContext = provider.getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl); GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest(); dataCenterRequest.setAccount(account); DataCenterUrls urls = null; GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest); if (response != null && response.getGetDataCenterUrlsResult() != null) { urls = response.getGetDataCenterUrlsResult().getDataCenterUrls(); } if (urls == null) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl)); } String wsDomain = urls.getWebservicesDomain(); String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath()); requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); return port; } catch (WebServiceException | MalformedURLException | InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault | UnexpectedErrorFault | ExceededRequestSizeFault e) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e); } }
From source file:test.integ.be.agiv.security.Axis2Test.java
@Test public void testSecurityFramework() { Service service = ClaimsAwareServiceFactory.getInstance(); // WS-Addressing via JAX-WS IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature()); BindingProvider bindingProvider = (BindingProvider) iservice; bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://auth.beta.agiv.be/ClaimsAwareService/Service.svc"); AGIVSecurity agivSecurity = new AGIVSecurity( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13", AGIVSecurity.BETA_REALM, this.config.getUsername(), this.config.getPassword()); agivSecurity.enable(bindingProvider, false); agivSecurity.enable(bindingProvider, false); agivSecurity.prefetchTokens("https://auth.beta.agiv.be/ClaimsAwareService/Service.svc", false); LOG.debug("calling getData"); iservice.getData(0);//from www .ja v a 2 s .c om LOG.debug("calling getData"); iservice.getData(0); LOG.debug("calling getData"); iservice.getData(0); SecurityToken secureConversationToken = agivSecurity.getSecureConversationTokens().values().iterator() .next(); agivSecurity.cancelSecureConversationTokens(); iservice.getData(0); SecurityToken secureConversationToken2 = agivSecurity.getSecureConversationTokens().values().iterator() .next(); assertFalse(secureConversationToken.getAttachedReference() .equals(secureConversationToken2.getAttachedReference())); }
From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java
@Test public void testWithoutSecurity() { Service service = new Service(); IService iservice = service.getBasicHttpBindingIService(); BindingProvider bindingProvider = (BindingProvider) iservice; bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://auth.beta.agiv.be/ClaimsAwareService/Service.svc/basic"); try {//from w w w . j a v a2s. c o m iservice.getData(0); fail(); } catch (SOAPFaultException e) { LOG.debug("expected exception: " + e.getMessage()); assertTrue(e.getMessage().contains("security")); } }
From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java
@Test public void testSecurity() { Service service = new Service(); IService iservice = service.getWS2007FederationHttpBindingIService(); BindingProvider bindingProvider = (BindingProvider) iservice; bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ClaimsAwareServiceFactory.SERVICE_LOCATION); IPSTSClient ipStsClient = new IPSTSClient( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", AGIVSecurity.BETA_REALM);/*from www .j a v a2s .co m*/ SecurityToken ipStsSecurityToken = ipStsClient.getSecurityToken(this.config.getUsername(), this.config.getPassword()); RSTSClient rStsClient = new RSTSClient( "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13"); SecurityToken rStsSecurityToken = rStsClient.getSecurityToken(ipStsSecurityToken, ClaimsAwareServiceFactory.SERVICE_REALM); Binding binding = bindingProvider.getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); WSAddressingHandler wsAddressingHandler = new WSAddressingHandler(); handlerChain.add(wsAddressingHandler); WSSecurityHandler wsSecurityHandler = new WSSecurityHandler(); handlerChain.add(wsSecurityHandler); handlerChain.add(new LoggingHandler()); binding.setHandlerChain(handlerChain); wsAddressingHandler.setAddressing("http://www.agiv.be/IService/GetData", ClaimsAwareServiceFactory.SERVICE_LOCATION); wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(), rStsSecurityToken.getToken(), true); ArrayOfClaimInfo result = iservice.getData(0); List<ClaimInfo> claims = result.getClaimInfo(); boolean myName = false; for (ClaimInfo claim : claims) { LOG.debug(claim.getName() + " = " + claim.getValue()); if (this.config.getUsername().equals(claim.getValue())) { myName = true; } } assertTrue(myName); }
From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java
@Test public void testSecuritySecondaryParameters() throws Exception { Service service = new Service(); IService iservice = service.getWS2007FederationHttpBindingIService(); BindingProvider bindingProvider = (BindingProvider) iservice; bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ClaimsAwareServiceFactory.SERVICE_LOCATION); InputStream wsdlInputStream = CrabReadTest.class.getResourceAsStream("/ClaimsAwareService.wsdl"); assertNotNull(wsdlInputStream);//from w w w . j a v a 2s .c o m DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document wsdlDocument = documentBuilder.parse(wsdlInputStream); NodeList requestSecurityTokenTemplateNodeList = wsdlDocument .getElementsByTagNameNS(WSConstants.WS_SECURITY_POLICY_NAMESPACE, "RequestSecurityTokenTemplate"); assertEquals(1, requestSecurityTokenTemplateNodeList.getLength()); Element requestSecurityTokenTemplateElement = (Element) requestSecurityTokenTemplateNodeList.item(0); NodeList secondaryParametersNodeList = requestSecurityTokenTemplateElement.getChildNodes(); IPSTSClient ipStsClient = new IPSTSClient( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", AGIVSecurity.BETA_REALM, secondaryParametersNodeList); SecurityToken ipStsSecurityToken = ipStsClient.getSecurityToken(this.config.getUsername(), this.config.getPassword()); RSTSClient rStsClient = new RSTSClient( "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13"); SecurityToken rStsSecurityToken = rStsClient.getSecurityToken(ipStsSecurityToken, ClaimsAwareServiceFactory.SERVICE_REALM); Binding binding = bindingProvider.getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); WSAddressingHandler wsAddressingHandler = new WSAddressingHandler(); handlerChain.add(wsAddressingHandler); WSSecurityHandler wsSecurityHandler = new WSSecurityHandler(); handlerChain.add(wsSecurityHandler); handlerChain.add(new LoggingHandler()); binding.setHandlerChain(handlerChain); wsAddressingHandler.setAddressing("http://www.agiv.be/IService/GetData", ClaimsAwareServiceFactory.SERVICE_LOCATION); wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(), rStsSecurityToken.getToken(), true); ArrayOfClaimInfo result = iservice.getData(0); List<ClaimInfo> claims = result.getClaimInfo(); boolean myName = false; for (ClaimInfo claim : claims) { LOG.debug(claim.getName() + " = " + claim.getValue()); if (this.config.getUsername().equals(claim.getValue())) { myName = true; } } assertTrue(myName); }
From source file:test.integ.be.agiv.security.ClaimsAwareServiceTest.java
@Test public void testSecurityFrameworkSTSListener() { // setup//from w w w .j ava2 s . c o m Service service = ClaimsAwareServiceFactory.getInstance(); IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature()); BindingProvider bindingProvider = (BindingProvider) iservice; bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ClaimsAwareServiceFactory.SERVICE_LOCATION); AGIVSecurity agivSecurity = new AGIVSecurity( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13", AGIVSecurity.BETA_REALM, this.config.getUsername(), this.config.getPassword()); agivSecurity.enable(bindingProvider, false, ClaimsAwareServiceFactory.SERVICE_REALM); STSTestListener testListener = new STSTestListener(); agivSecurity.addSTSListener(testListener); // operate iservice.getData(0); // verify assertTrue(testListener.isCalledIpSts()); assertTrue(testListener.isCalledRSts()); assertFalse(testListener.isCalledSCT()); // setup testListener.reset(); // operate iservice.getData(0); // verify assertFalse(testListener.isCalledIpSts()); assertFalse(testListener.isCalledRSts()); assertFalse(testListener.isCalledSCT()); // setup testListener.reset(); agivSecurity.cancelSecureConversationTokens(); // operate iservice.getData(0); // verify assertFalse(testListener.isCalledIpSts()); assertFalse(testListener.isCalledRSts()); assertFalse(testListener.isCalledSCT()); }