List of usage examples for javax.xml.ws.handler MessageContext get
V get(Object key);
From source file:org.apache.juddi.xlt.util.LoggingHandler.java
private void unregisterMessage(MessageContext context) { RequestData reqData = (RequestData) context.get(XLT_REQUEST_DATA); if (reqData != null) { reqData.setRunTime();/*w ww. ja va 2 s . co m*/ reqData.setFailed(isFaultReceived(context)); reqData.setBytesReceived(0); reqData.setResponseCode(getResponseCode(context)); reqData.setUrl(getServiceUrl(context)); reqData.setContentType(getContentType(context)); Session.getCurrent().getDataManager().logDataRecord(reqData); } }
From source file:org.easyrec.soap.music.impl.MusicShopRecommenderWSImpl.java
private Integer authenticate(String tenant) throws MusicShopRecommenderException { try {//from w ww . j a v a 2s. co m MessageContext mc = wsContext.getMessageContext(); HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST); Integer tenantId = authenticationDispatcher.authenticateTenant(tenant, serviceName, req); if (tenantId == null) { throw new MusicShopRecommenderException("Unauthorized access!"); } return tenantId; } catch (Exception e) { throw new MusicShopRecommenderException(e.getMessage()); } }
From source file:org.easyrec.soap.nodomain.impl.EasyRecSoap.java
private Integer authenticate(String tenant) throws EasyRecSoapException { try {/*from w w w . j a va 2s .co m*/ MessageContext mc = wsContext.getMessageContext(); HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST); //logger.info("Request from: " + getRequestIP() + "/" + getRequestHost()); Integer tenantId = authenticationDispatcher.authenticateTenant(tenant, serviceName, req); if (tenantId == null) { throw new EasyRecSoapException("Unauthorized access!"); } return tenantId; } catch (Exception e) { throw new EasyRecSoapException(e.getMessage()); } }
From source file:org.ejbca.core.protocol.ws.EjbcaWS.java
private void logAdminName(final AuthenticationToken admin, final IPatternLogger logger) { // Log certificate info final X509Certificate cert = ((X509CertificateAuthenticationToken) admin).getCertificate(); logger.paramPut(TransactionTags.ADMIN_DN.toString(), cert.getSubjectDN().toString()); logger.paramPut(TransactionTags.ADMIN_ISSUER_DN.toString(), cert.getIssuerDN().toString()); // Log IP address MessageContext msgctx = wsContext.getMessageContext(); HttpServletRequest request = (HttpServletRequest) msgctx.get(MessageContext.SERVLET_REQUEST); logger.paramPut(TransactionTags.ADMIN_REMOTE_IP.toString(), request.getRemoteAddr()); String addr = request.getHeader("X-Forwarded-For"); if (addr != null) addr = addr.replaceAll("[^a-zA-Z0-9.:-_]", "?"); logger.paramPut(TransactionTags.ADMIN_FORWARDED_IP.toString(), addr); }
From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAuthHandler.java
@Override public void close(MessageContext context) { LoginContext loginContext = (LoginContext) context.get(NUXEO_LOGIN_CONTEXT); if (loginContext != null) { try {/*from w ww . jav a 2 s . c o m*/ loginContext.logout(); } catch (LoginException e) { log.error("Cannot logout", e); } } super.close(context); }
From source file:org.openehealth.ipf.platform.camel.ihe.hl7v3.AbstractHl7v3WebService.java
protected Hl7v3AuditDataset startAtnaAuditing(String requestString, Hl7v3AuditStrategy auditStrategy) { Hl7v3AuditDataset auditDataset = null; if (auditStrategy != null) { try {//from w w w . ja v a2 s.c om auditDataset = auditStrategy.createAuditDataset(); MessageContext messageContext = new WebServiceContextImpl().getMessageContext(); HttpServletRequest servletRequest = (HttpServletRequest) messageContext .get(AbstractHTTPDestination.HTTP_REQUEST); if (servletRequest != null) { auditDataset.setClientIpAddress(servletRequest.getRemoteAddr()); } auditDataset.setServiceEndpointUrl((String) messageContext.get(Message.REQUEST_URL)); AddressingProperties apropos = (AddressingProperties) messageContext .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND); if ((apropos != null) && (apropos.getReplyTo() != null) && (apropos.getReplyTo().getAddress() != null)) { auditDataset.setUserId(apropos.getReplyTo().getAddress().getValue()); } if (wsTransactionConfiguration.isAuditRequestPayload()) { auditDataset.setRequestPayload(requestString); } auditStrategy.enrichDatasetFromRequest(requestString, auditDataset); } catch (Exception e) { log.error("Phase 1 of server-side ATNA auditing failed", e); } } return auditDataset; }
From source file:org.openehealth.ipf.platform.camel.ihe.ws.AbstractAsyncResponseWebService.java
/** * Before calling the base method, determines correlation key * and stores it into message headers. /*from www. j a v a 2 s .c om*/ */ @SuppressWarnings("unchecked") @Override protected Exchange process(Object body, Map<String, Object> headers, ExchangePattern exchangePattern) { final AsynchronyCorrelator correlator = ((AbstractWsEndpoint) getConsumer().getEndpoint()).getCorrelator(); MessageContext messageContext = new WebServiceContextImpl().getMessageContext(); AddressingPropertiesImpl apropos = (AddressingPropertiesImpl) messageContext .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND); String messageId = ((apropos != null) && (apropos.getRelatesTo() != null)) ? apropos.getRelatesTo().getValue() : null; // when no ReplyTo header found -- try alternative keys if (messageId == null) { String[] alternativeKeys = getAlternativeResponseKeys(body); if (alternativeKeys != null) { for (String key : alternativeKeys) { messageId = correlator.getMessageId(key); if (messageId != null) { break; } } } } if (messageId != null) { // expose user-defined correlation key as message header String correlationKey = correlator.getCorrelationKey(messageId); if (correlationKey != null) { if (headers == null) { // NB: it shouldn't be a non-modifiable singleton map... headers = new HashMap<String, Object>(); } headers.put(AbstractWsEndpoint.CORRELATION_KEY_HEADER_NAME, correlationKey); } // drop correlation data when appropriate if (canDropCorrelation(body)) { correlator.delete(messageId); } } else { LOG.error("Cannot retrieve WSA RelatesTo header, message correlation not possible"); } return super.process(body, headers, exchangePattern); }
From source file:org.openehealth.ipf.platform.camel.ihe.ws.AbstractWebService.java
/** * Calls the consumer for processing via Camel. * * @param body//from w w w . j a va 2s .c o m * contents of the in-message body to be processed. * @param additionalHeaders * additional in-message headers (can be <code>null</code>). * @param exchangePattern * pattern of the exchange put into the route. * @return the resulting exchange. */ protected Exchange process(Object body, Map<String, Object> additionalHeaders, ExchangePattern exchangePattern) { Validate.notNull(consumer); MessageContext messageContext = new WebServiceContextImpl().getMessageContext(); Exchange exchange = consumer.getEndpoint().createExchange(exchangePattern); // prepare input message & headers Message inputMessage = exchange.getIn(); inputMessage.setBody(body); processIncomingHeaders(messageContext, inputMessage); if (additionalHeaders != null) { inputMessage.getHeaders().putAll(additionalHeaders); } // set Camel exchange property based on request encoding exchange.setProperty(Exchange.CHARSET_NAME, messageContext.get(org.apache.cxf.message.Message.ENCODING)); // process consumer.process(exchange); // handle resulting message and headers Message resultMessage = Exchanges.resultMessage(exchange); processUserDefinedOutgoingHeaders(messageContext, resultMessage, false); // set response encoding based on Camel exchange property String responseEncoding = exchange.getProperty(Exchange.CHARSET_NAME, String.class); if (responseEncoding != null) { messageContext.put(org.apache.cxf.message.Message.ENCODING, responseEncoding); } return exchange; }
From source file:org.soaplab.services.protocol.jaxws.AnalysisService.java
/************************************************************************** * Return a name under which this service was called. This * name is "hidden" in the URL invoking this web service. <p> * * @throw SoaplabException if the service name cannot be * obtained; or if the web service context is not known. The * latter may happen if this class is not used within a * servlet container (such as Tomcat) properly - because it is * the conainer who injects code into otherwise empty web * service context instance./* ww w . j ava 2s . com*/ * *************************************************************************/ @WebMethod(exclude = true) public String getServiceName() throws SoaplabException { // do we have a Web Service Context? if (wsc == null) throw new SoaplabException("Internal error: Undefined Web Service Context."); MessageContext mcx = null; try { mcx = wsc.getMessageContext(); if (mcx == null) throw new SoaplabException("Internal error: Undefined Message Context."); } catch (java.lang.IllegalStateException e) { throw new SoaplabException("Internal error: The method is called while no request is being serviced"); } HttpServletRequest req = (HttpServletRequest) mcx.get(MessageContext.SERVLET_REQUEST); if (req == null) throw new SoaplabException("Internal error: Undefined HttpServletRequest."); String requestURI = req.getRequestURI(); String serviceName = StringUtils.substringAfterLast(requestURI, "/"); if (StringUtils.isBlank(serviceName)) { if (StringUtils.isNotBlank(requestURI)) { // request URI does not have any slash (is it possible?) return requestURI; } else { throw new SoaplabException("Internal error: Cannot recognize what service was called."); } } return serviceName; }
From source file:org.soaplab.services.protocol.jaxws.AnalysisService.java
@WebMethod(exclude = true) public void getClientInfo(SoaplabMap map) throws SoaplabException { // do we have a Web Service Context? if (wsc == null) throw new SoaplabException("Internal error: Undefined Web Service Context."); MessageContext mcx = null; try {/*from ww w .ja v a2 s . c o m*/ mcx = wsc.getMessageContext(); if (mcx == null) throw new SoaplabException("Internal error: Undefined Message Context."); } catch (java.lang.IllegalStateException e) { throw new SoaplabException("Internal error: The method is called while no request is being serviced"); } HttpServletRequest httpReq = (HttpServletRequest) mcx.get(MessageContext.SERVLET_REQUEST); if (httpReq == null) throw new SoaplabException("Internal error: Undefined HttpServletRequest."); // Client IP address... String remoteIP = null; if (httpReq.getRemoteAddr() != null) remoteIP = httpReq.getRemoteAddr(); // Handle proxy or load balancer client IP. if (httpReq.getHeader("X-Cluster-Client-Ip") != null) { remoteIP = httpReq.getHeader("X-Cluster-Client-Ip"); } // Default value in case of problems if (remoteIP == null) remoteIP = "unknown"; map.put(SoaplabConstants.REMOTE_IP, remoteIP); map.put(SoaplabConstants.INTERFACE, "jaxws"); return; }