Example 1 Project: remote File: InInterceptor.java View source code Vote up 7 votes public void handleMessage(Message message) throws Fault { HttpServletRequest request = (HttpServletRequest)message.get("HTTP.REQUEST"); HttpSession httpSession = request.getSession(); boolean newSession = false; String userName = (String)httpSession.getAttribute(USER_NAME); String password = null; if (userName != null) { password = (String)httpSession.getAttribute(PASSWORD); } else { AuthorizationPolicy policy = message.get(AuthorizationPolicy.class); if (policy != null) { userName = policy.getUserName(); password = policy.getPassword(); newSession = true; } } if (userName == null) { userName = ANONYMOUS_USER; } try { //TODO log in or throw exception if login not correct if (newSession) { httpSession.setAttribute(USER_NAME, userName); if (password != null) { httpSession.setAttribute(PASSWORD, password); } } } catch (Exception e) { Activator.log("Exception while logging in:", e); throw new Fault(e); } }
Example 2 Project: rave File: JsonResponseWrapperInterceptor.java View source code Vote up 7 votes @Override public void handleMessage(Message message) throws Fault { Object o = message.getContent(Object.class); JsonResponseWrapper wrapper = new JsonResponseWrapper(o); message.setContent(JsonResponseWrapper.class, wrapper); }
Example 3 Project: steve File: FromAddressInterceptor.java View source code Vote up 6 votes private String getChargeBoxId(Message message) { MessageContentsList lst = MessageContentsList.getContentsList(message); if (lst == null) { return null; } MessageInfo mi = (MessageInfo) message.get("org.apache.cxf.service.model.MessageInfo"); for (MessagePartInfo mpi : mi.getMessageParts()) { if (CHARGEBOX_ID_HEADER.equals(mpi.getName().getLocalPart())) { return (String) lst.get(mpi); } } return null; }
Example 4 Project: carbon-registry File: RestApiRequestAuthorizationHandler.java View source code Vote up 6 votes /** * This method handles the request received at the registry endpoint. The method decodes the extracted * JWT token and extract the enduser's username and tenantID which is appended to the original rest request * as query param and forwarded to the respective resource class. This method returns * a null value which indicates that the request to be processed. */ @Override public Response handleRequest(Message message, ClassResourceInfo resourceInfo) { if(log.isDebugEnabled()){ log.debug("request has been received at REST API handle request method"); } String requestUrl = message.get(Message.REQUEST_URL).toString(); String queryParam = (message.get(Message.QUERY_STRING) != null)?message.get(Message.QUERY_STRING).toString():""; //extracting all the headers received along with the request. String header = message.get(Message.PROTOCOL_HEADERS).toString(); String userName = getUsernameFromJwtToken(header); String tenantID = null; try { tenantID = String.valueOf(getTenantIdOFUser(userName)); } catch (UserStoreException e) { log.error(e.getMessage(),e); return Response.status(Response.Status.UNAUTHORIZED).build(); } String queryParamAppender = (queryParam.length() == 0 ? "" : "&"); queryParam += queryParamAppender + "username="+userName+"&tenantid="+tenantID; message.put(Message.REQUEST_URL, requestUrl); message.put(Message.QUERY_STRING, queryParam); return null; }
Example 5 Project: forgestore File: HeadersOutInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(Message outMessage) throws Fault { Map<String, List<String>> headers = (Map<String, List<String>>) outMessage.get(Message.PROTOCOL_HEADERS); if (headers == null) { headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); List<String> vl = new ArrayList<String>(); vl.add("1.0.0"); headers.put("X-Baker-API-Version", vl ); // vl = new ArrayList<String>(); // vl.add("*"); // headers.put("Access-Control-Allow-Origin", vl); outMessage.put(Message.PROTOCOL_HEADERS, headers); } // modify headers }
Example 6 Project: springlab File: SpringSecurityInInterceptor.java View source code Vote up 6 votes public void handleMessage(Message message) throws Fault { String userName = getUserNameFromWSS4JResult(message); HttpServletRequest request = (HttpServletRequest) message.get("HTTP.REQUEST"); UserDetails userDetails = userDetailsService.loadUserByUsername(userName); SpringSecurityUtils.saveUserDetailsToContext(userDetails, request); }
Example 7 Project: olingo-odata4 File: StaticSecurityInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(final Message message) throws Fault { final SecurityContext sc = message.get(SecurityContext.class); if (sc == null || sc.getUserPrincipal() == null) { @SuppressWarnings("unchecked") final Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS); final List<String> auth = headers.get(AUTHORIZATION_PROPERTY); if (auth == null || auth.isEmpty()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } final String encodedUserPassword = auth.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", ""); final String usernameAndPassword = new String(Base64.decode(encodedUserPassword)); // Split username and password tokens final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); final String username = tokenizer.nextToken(); final String password = tokenizer.nextToken(); if (!"odatajclient".equals(username) || !"odatajclient".equals(password)) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } final SecurityContext newSc = new SecurityContext() { @Override public Principal getUserPrincipal() { return new SimplePrincipal("odatajclient"); } @Override public boolean isUserInRole(final String role) { return false; } }; message.put(SecurityContext.class, newSc); } }
Example 8 Project: jbossws-cxf File: SOAPConnectionImpl.java View source code Vote up 6 votes @SuppressWarnings("unchecked") private MessageObserver createMessageObserver(final Conduit c) { return new MessageObserver() { public void onMessage(Message inMessage) { LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(); try { IOUtils.copy(inMessage.getContent(InputStream.class), bout); inMessage.getExchange().put(InputStream.class, bout.createInputStream()); Map<String, List<String>> inHeaders = (Map<String, List<String>>)inMessage.get(Message.PROTOCOL_HEADERS); inMessage.getExchange().put(Message.PROTOCOL_HEADERS, inHeaders); c.close(inMessage); } catch (IOException e) { //ignore } } }; }
Example 9 Project: support-examples File: ResponseTransformerInterceptor.java View source code Vote up 6 votes public void handleMessage(Message message) throws Fault { log.warn("Configuring interceptor"); Map<String, String> appendElements = new HashMap<String, String>(); appendElements.put("{http://schemas.xmlsoap.org/soap/envelope/}Body", "{http://schemas.xmlsoap.org/soap/envelope/}Header="); TransformOutInterceptor interceptor = new TransformOutInterceptor(); interceptor.setOutAppendElements(appendElements); message.getInterceptorChain().add(interceptor); Map<String, String> envMap = new HashMap<String, String>(); envMap.put( "env" , "http://schemas.xmlsoap.org/soap/envelope/"); Map<String, String> nsMap = new HashMap<String, String>(); nsMap.put( "https://www.ccr.gov" , "m" ); JAXBDataBinding dataBinding = (JAXBDataBinding)message.getExchange().getEndpoint().getService().getDataBinding(); dataBinding.setNamespaceMap(nsMap); message.put("soap.env.ns.map", envMap); }
Example 10 Project: jbossws-cxf File: SOAPConnectionImpl.java View source code Vote up 6 votes @Override public SOAPMessage get(Object addressObject) throws SOAPException { checkClosed(); String address = getAddress(addressObject); ConduitInitiator ci = getConduitInitiator(address); // create a new Message and Exchange EndpointInfo info = new EndpointInfo(); info.setAddress(address); Message outMessage = new MessageImpl(); Exchange exch = new ExchangeImpl(); outMessage.setExchange(exch); // sent GET request try { final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false)); //TODO verify bus if (c instanceof HTTPConduit) { ((HTTPConduit)c).getClient().setAutoRedirect(true); } outMessage.put(Message.HTTP_REQUEST_METHOD, "GET"); c.prepare(outMessage); c.setMessageObserver(createMessageObserver(c)); c.close(outMessage); } catch (Exception ex) { throw MESSAGES.getRequestCouldNotBeSent(ex); } // read SOAPMessage return readSoapMessage(exch); }
Example 11 Project: motown File: ReplyToHeaderInterceptorTest.java View source code Vote up 6 votes @Test public void handleMessageWithMapsVerifyReplyToHeaderAdded() { AddressingProperties properties = new AddressingPropertiesImpl(); Message message = new MessageImpl(); message.put(MAP_PROPERTY, properties); ReplyToHeaderInInterceptor headerInInterceptor = new ReplyToHeaderInInterceptor(); headerInInterceptor.handleMessage(new SoapMessage(message)); assertEquals(REPLY_TO_ANONYMOUS, properties.getReplyTo().getAddress().getValue()); }
Example 12 Project: fcrepo File: WadlGenerator.java View source code Vote up 6 votes @Override public Response handleRequest(Message message, ClassResourceInfo resource) { if (getPath(message).endsWith("/application.wadl")) { String query = (String) message.get(Message.QUERY_STRING); if (query == null) { message.put(Message.QUERY_STRING, "_wadl=&_type=xml"); } else { if (query.indexOf("_wadl=") < 0) message.put(Message.QUERY_STRING, query + "&_wadl=&_type=xml"); } } return super.handleRequest(message, resource); }
Example 13 Project: ddf-platform File: AbstractOverrideInterceptor.java View source code Vote up 6 votes /** * Adds the policy retrieved from the configured policy loader to this message as the override * policy. * * @param message */ @Override public void handleMessage(Message message) { if (policy == null) { PolicyBuilder builder = message.getExchange().getBus() .getExtension(PolicyBuilder.class); try { policy = builder.getPolicy(loader.getPolicy().getDocumentElement()); logger.trace("Read in policy, adding to policy override of message."); message.put(PolicyConstants.POLICY_OVERRIDE, policy); } catch (Exception e) { throw new Fault(e); } } else { message.put(PolicyConstants.POLICY_OVERRIDE, policy); } }
Example 14 Project: ginco File: GincoOutFaultInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(Message message) throws Fault { handleMessageCalled = true; Exception ex = message.getContent(Exception.class); if (ex == null) { throw new RuntimeException("Exception is expected"); } if (!(ex instanceof Fault)) { throw new RuntimeException("Fault is expected"); } logger.error("Uncaught exception in REST services : ", ex); HttpServletResponse response = (HttpServletResponse) message.getExchange() .getInMessage().get(AbstractHTTPDestination.HTTP_RESPONSE); response.setStatus(200); response.setContentType("text/html"); try { String msg = "{success:false, message: '" + LabelUtil.getResourceLabel("unknown-exception") + "'}"; response.getOutputStream().write(msg.getBytes()); response.getOutputStream().flush(); message.getInterceptorChain().abort(); } catch (IOException ioex) { throw new RuntimeException("Error writing the response"); } }
Example 15 Project: jbossws-cxf File: CheckInterceptor.java View source code Vote up 6 votes public void handleMessage(Message message) throws Fault { String method = (String)message.get(Message.HTTP_REQUEST_METHOD); if (!method.equals("POST")) { return; } StringBuilder sb = new StringBuilder(); InputStream is = message.getContent(InputStream.class); if (is != null) { CachedOutputStream bos = new CachedOutputStream(); try { copy(is, bos, 4096); bos.flush(); is.close(); message.setContent(InputStream.class, bos.getInputStream()); bos.writeCacheTo(sb); bos.close(); } catch (IOException e) { throw new Fault(e); } } if (!sb.toString().contains("http://www.w3.org/2005/08/addressing")) { throw new Fault("Could not find any reference to namespace 'http://www.w3.org/2005/08/addressing' in handled message.", java.util.logging.Logger.getLogger(CheckInterceptor.class.getName())); } }
Example 16 Project: jaxrs-oauth2 File: CXFMessageReader.java View source code Vote up 6 votes private Map<String, List<String>> extractFormParams(Message message) throws MessageReadException { InputStream is = message.getContent(InputStream.class); StringBuilder buf = new StringBuilder(); if (is != null) { try (CachedOutputStream bos = new CachedOutputStream(); InputStream stream = is) { IOUtils.copy(stream, bos); bos.flush(); message.setContent(InputStream.class, bos.getInputStream()); bos.writeCacheTo(buf); } catch (IOException e) { throw new MessageReadException(e); } } return JAXRSUtils.getStructuredParams(buf.toString(), "&", false, false); }
Example 17 Project: Lather File: IQBackChannelConduitTest.java View source code Vote up 6 votes @Test public void testSendingReply() { try { testInputPacket.setFrom("SoapClient"); testInputPacket.setTo("SoapServer"); testInputPacket.setPacketID("packet-id"); testInputPacket.setType(IQ.Type.GET); Message replyMsg = new MessageImpl(); IQBackChannelConduit conduit = new IQBackChannelConduit(testInputPacket, fakeXmppConnection); conduit.prepare(replyMsg); CachedOutputStream outputStream = (CachedOutputStream)replyMsg.getContent(OutputStream.class); byte[] outputMsg = REPLY_MSG.getBytes(); outputStream.write(outputMsg, 0, outputMsg.length); conduit.close(replyMsg); Assert.assertEquals("From set to SoapServer", testInputPacket.getTo(), testReplyPacket.getFrom()); Assert.assertEquals("To set to SoapClient", testInputPacket.getFrom(), testReplyPacket.getTo()); Assert.assertEquals("Packet ids are the same", testInputPacket.getPacketID(), testReplyPacket.getPacketID()); Assert.assertEquals("IQ type should be result", IQ.Type.RESULT, testReplyPacket.getType()); Assert.assertEquals("Reply content read from CachedOutputStream", REPLY_MSG, testReplyPacket.getChildElementXML()); } catch (IOException e) { Assert.fail("Could not write output message for testing: " + e.getMessage()); } }
Example 18 Project: jruby-cxf File: AegisSchemaValidationInInterceptor.java View source code Vote up 6 votes public void handleMessage(Message message) throws Fault { XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class); try { setSchemaInMessage(message, xmlReader); } catch (XMLStreamException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("SCHEMA_ERROR", LOG), e); } }
Example 19 Project: ddf-platform File: EXIOutInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(Message message) { if (isRequestor(message)) { //client sending request LOGGER.trace("Not performing any EXI compression for initial request."); } else { //server sending back response Message request = message.getExchange().getInMessage(); Map<String, List<String>> requestHeaders = CastUtils .cast((Map<?, ?>) request.get(Message.PROTOCOL_HEADERS)); if (requestHeaders != null) { String acceptEncodingHeader = StringUtils .join(requestHeaders.get(HttpHeaders.ACCEPT_ENCODING), ","); if (StringUtils.isNotBlank(acceptEncodingHeader) && acceptEncodingHeader .contains(EXI_ACCEPT_ENCODING)) { LOGGER.debug("Sending back response message using EXI-encoding."); OutputStream os = message.getContent(OutputStream.class); EXIOutputStream cached = new EXIOutputStream(os); message.setContent(OutputStream.class, cached); } else { LOGGER.debug("EXI encoding not accepted by the client, skipping EXI encoding."); } } else { LOGGER.debug( "No request headers were found in the incoming request. Cannot encode to exi."); } } }
Example 20 Project: cxf-circuit-switcher File: CircuitSwitcherTargetSelector.java View source code Vote up 6 votes private boolean performFailover(Exchange exchange, InvocationContext invocation) { Exception prevExchangeFault = (Exception) exchange.remove(Exception.class.getName()); Message outMessage = exchange.getOutMessage(); Exception prevMessageFault = outMessage.getContent(Exception.class); outMessage.setContent(Exception.class, null); overrideAddressProperty(invocation.getContext()); Retryable retry = exchange.get(Retryable.class); exchange.clear(); boolean failover = false; if (retry != null) { try { failover = true; long delay = getDelayBetweenRetries(); if (delay > 0) { Thread.sleep(delay); } Map<String, Object> context = invocation.getContext(); retry.invoke(invocation.getBindingOperationInfo(), invocation.getParams(), context, exchange); } catch (Exception e) { if (exchange.get(Exception.class) != null) { exchange.put(Exception.class, prevExchangeFault); } if (outMessage.getContent(Exception.class) != null) { outMessage.setContent(Exception.class, prevMessageFault); } } } return failover; }
Example 21 Project: fuchsia File: ExchangeUtils.java View source code Vote up 6 votes protected static Exception getException(Message message) { Exception ex = null; if (message != null) { ex = message.getContent(Exception.class); } return ex; }
Example 22 Project: jbossws-cxf File: UDPConduit.java View source code Vote up 6 votes private void dataReceived(Message message, byte bytes[], boolean async) { final Message inMessage = new MessageImpl(); inMessage.setExchange(message.getExchange()); message.getExchange().setInMessage(inMessage); inMessage.setContent(InputStream.class, new ByteArrayInputStream(bytes)); incomingObserver.onMessage(inMessage); if (!message.getExchange().isSynchronous()) { message.getExchange().setInMessage(null); } }
Example 23 Project: Lather File: IQClientConduit.java View source code Vote up 6 votes /** * Triggered when a response is received. Note this conduit can call many services. Responses will need to * be correlated with their requests. */ @Override public void processPacket(Packet xmppResponse) { Message responseMsg = new MessageImpl(); SoapPacket soapMsg = (SoapPacket)xmppResponse; responseMsg.setContent(InputStream.class, new ByteArrayInputStream(soapMsg.getChildElementXML() .getBytes())); // TODO Fix this to handle error replies from XMPP server. // TODO Fix this to handle exchanges that don't exist. Exchange msgExchange = exchangeCorrelationTable.remove(xmppResponse.getPacketID()); msgExchange.setInMessage(responseMsg); // TODO Fix this so the response is processed by a different thread. getMessageObserver().onMessage(responseMsg); }
Example 24 Project: cxf-circuit-switcher File: CircuitSwitcherTargetSelectorTest.java View source code Vote up 6 votes private Message messageTo(String requestBaseURL, String requestPath) { Message message = new SoapMessage(Soap11.getInstance()); String requestURL = requestBaseURL + requestPath; message.put(Message.ENDPOINT_ADDRESS, requestURL); message.put(Message.BASE_PATH, requestBaseURL); message.put(Message.REQUEST_URI, requestURL); HashMap<String, Object> ctx = new HashMap<String, Object>(); ctx.put(Client.REQUEST_CONTEXT, new HashMap<String, Object>()); message.put(Message.INVOCATION_CONTEXT, ctx); CXFBusImpl bus = new CXFBusImpl(); BindingFactoryManagerImpl bindingFactoryManager = new BindingFactoryManagerImpl(); bindingFactoryManager.registerBindingFactory("abc", new JAXRSBindingFactory()); bus.setExtension(bindingFactoryManager, BindingFactoryManager.class); Map<String, ConduitInitiator> conduitInitiators = new HashMap<String, ConduitInitiator>(); ConduitInitiator ci = new HTTPTransportFactory(bus); conduitInitiators.put(ENDPOINT_TRANSPORT_ID, ci); ConduitInitiatorManagerImpl cim = new ConduitInitiatorManagerImpl(conduitInitiators); bus.setExtension(cim, ConduitInitiatorManager.class); Exchange exchange = exchange(message); exchange.put(Bus.class, bus); EndpointInfo ei = new EndpointInfo(); ei.setAddress("http://abc123"); BindingInfo b = new BindingInfo(null, "abc"); ei.setBinding(b); Endpoint endpointMock = mock(Endpoint.class); when(endpointMock.getEndpointInfo()).thenReturn(ei); exchange.put(Endpoint.class, endpointMock); message.setExchange(exchange); message.setContent(List.class, new ArrayList<String>()); circuitBreakerTargetSelector.prepare(message); InvocationKey key = new InvocationKey(exchange); InvocationContext invocation = circuitBreakerTargetSelector.getInvocation(key); invocation.getContext().put(Message.ENDPOINT_ADDRESS, requestPath); invocation.getContext().put("org.apache.cxf.request.uri", requestPath); return message; }
Example 25 Project: fuchsia File: ProtobufMessageInInterceptor.java View source code Vote up 6 votes /** */ public void handleMessage(Message message) throws Fault { Endpoint endpoint = message.getExchange().get(Endpoint.class); @SuppressWarnings(value = "unchecked") Class<? extends com.google.protobuf.Message> messageClass = (Class) message.getExchange().get(IN_MESSAGE_CLASS); if (messageClass == null) { messageClass = (Class) endpoint .get(IN_MESSAGE_CLASS); } InputStream in = message.getContent(InputStream.class); try { com.google.protobuf.Message m = (com.google.protobuf.Message) messageClass.getMethod("parseFrom", InputStream.class).invoke(null, in); message.setContent(com.google.protobuf.Message.class, m); } catch (Exception e) { log.error("Failed to invoke message method from protobuffer.",e); throw new RuntimeException(e); } }
Example 26 Project: tesb-rt-se File: MessageToEventMapperTest.java View source code Vote up 6 votes private Message getTestMessage() throws IOException, EndpointException { Message message = new MessageImpl(); ExchangeImpl exchange = new ExchangeImpl(); ServiceInfo serviceInfo = new ServiceInfo(); InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, new QName("interfaceNs", "interfaceName")); serviceInfo.setInterface(interfaceInfo ); SoapBindingInfo bInfo = new SoapBindingInfo(serviceInfo , WSDLConstants.NS_SOAP12); bInfo.setTransportURI(TransportType); OperationInfo opInfo = new OperationInfo(); opInfo.setName(new QName("namespace", "opName")); BindingOperationInfo bindingOpInfo = new BindingOperationInfo(bInfo, opInfo); exchange.put(BindingOperationInfo.class, bindingOpInfo); SoapBinding binding = new SoapBinding(bInfo); exchange.put(Binding.class, binding); String ns = "ns"; EndpointInfo ei = new EndpointInfo(serviceInfo, ns ); ei.setAddress(Address); Service service = new ServiceImpl(); Bus bus = BusFactory.getThreadDefaultBus(); Endpoint endpoint = new EndpointImpl(bus, service, ei); exchange.put(Endpoint.class, endpoint ); message.setExchange(exchange); FlowIdHelper.setFlowId(message,FlowID); Principal principal = new X500Principal(PrincipalString); SecurityContext sc = new DefaultSecurityContext(principal, new Subject()); message.put(SecurityContext.class, sc); CachedOutputStream cos = new CachedOutputStream(); InputStream is = new ByteArrayInputStream(TESTCONTENT.getBytes("UTF-8")); IOUtils.copy(is, cos); message.setContent(CachedOutputStream.class, cos); CustomInfo customInfo = CustomInfo.getOrCreateCustomInfo(message); customInfo.put("key1", "value1"); return message; }
Example 27 Project: jbossws-cxf File: HandlerChainSortInterceptor.java View source code Vote up 6 votes @Override @SuppressWarnings("rawtypes") public void handleMessage(Message message) throws Fault { if (binding != null) { Exchange ex = message.getExchange(); if (ex.get(HandlerChainInvoker.class) == null) { List<Handler> hc = binding.getHandlerChain(); if (hc.size() > 1) { //no need to sort etc if the chain is empty or has one handler only Collections.sort(hc, comparator); //install a new HandlerChainInvoker using the sorted handler chain; //the AbstractJAXWSHandlerInterceptor will be using this invoker //instead of creating a new one ex.put(HandlerChainInvoker.class, new HandlerChainInvoker(hc, isOutbound(message, ex))); } } } }
Example 28 Project: ddf-platform File: MetricsInInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(Message message) throws Fault { Exchange ex = message.getExchange(); if (null == ex) { return; } if (isClient(message)) { if (!ex.isOneWay()) { endHandlingMessage(ex); } } else { beginHandlingMessage(ex); } }
Example 29 Project: linshare-core File: WebserviceBase.java View source code Vote up 6 votes protected Long getTransfertDuration() { Long uploadStartTime = null; Message currentMessage = PhaseInterceptorChain.getCurrentMessage(); Exchange exchange = currentMessage.getExchange(); if (exchange.containsKey("org.linagora.linshare.webservice.interceptor.start_time")) { uploadStartTime = (Long) exchange.get("org.linagora.linshare.webservice.interceptor.start_time"); logger.debug("Upload start time : " + uploadStartTime); } Long transfertDuration = null; if (uploadStartTime != null) { Date endDate = new Date(); transfertDuration = endDate.getTime() - uploadStartTime; if (logger.isDebugEnabled()) { Date beginDate = new Date(uploadStartTime); logger.debug("Upload was begining at : " + beginDate); logger.debug("Upload was ending at : " + endDate); } logger.info("statistics:upload time:" + transfertDuration + "ms."); } return transfertDuration; }
Example 30 Project: cxf-circuit-switcher File: CircuitSwitcherTargetSelector.java View source code Vote up 6 votes /** * Called when a Conduit is actually required. * * @param message * @return the Conduit to use for mediation of the message */ public synchronized Conduit selectConduit(Message message) { Conduit c = message.get(Conduit.class); if (c == null) { Exchange exchange = message.getExchange(); InvocationKey key = new InvocationKey(exchange); InvocationContext invocation = getInvocation(key); if ((invocation != null) && !invocation.getContext().containsKey(IS_SELECTED)) { Endpoint target = getAvailableTarget(); if (target != null && targetChanged(message, target)) { setEndpoint(target); message.put(Message.ENDPOINT_ADDRESS, target.getEndpointInfo().getAddress()); overrideAddressProperty(invocation.getContext()); invocation.getContext().put(IS_SELECTED, ""); } else if (target == null) { throw new Fault(new IOException("No available targets")); } } message.put(CONDUIT_COMPARE_FULL_URL, Boolean.TRUE); c = getSelectedConduit(message); } if (receiveTimeout != null) { HTTPClientPolicy httpClientPolicy = ((HTTPConduit) c).getClient(); httpClientPolicy.setReceiveTimeout(receiveTimeout); } return c; }
Example 31 Project: geofence File: AuthenticationHandler.java View source code Vote up 6 votes /** * @param inMessage * @return Message */ private Message getOutMessage(Message inMessage) { Exchange exchange = inMessage.getExchange(); Message outMessage = exchange.getOutMessage(); if (outMessage == null) { Endpoint endpoint = exchange.get(Endpoint.class); outMessage = endpoint.getBinding().createMessage(); exchange.setOutMessage(outMessage); } outMessage.putAll(inMessage); return outMessage; }
Example 32 Project: soi-toolkit-mule File: FixEncoding.java View source code Vote up 6 votes private String getEncoding(Message message) { Exchange ex = message.getExchange(); String encoding = (String)message.get(Message.ENCODING); if (encoding == null && ex.getInMessage() != null) { encoding = (String) ex.getInMessage().get(Message.ENCODING); message.put(Message.ENCODING, encoding); } if (encoding == null) { encoding = "UTF-8"; message.put(Message.ENCODING, encoding); } return encoding; }
Example 33 Project: tesb-rt-se File: XPathProcessor.java View source code Vote up 6 votes private String getEncoding(Message message) { Exchange ex = message.getExchange(); String encoding = (String) message.get(Message.ENCODING); if (encoding == null && ex.getInMessage() != null) { encoding = (String) ex.getInMessage().get(Message.ENCODING); message.put(Message.ENCODING, encoding); } if (encoding == null) { encoding = "UTF-8"; message.put(Message.ENCODING, encoding); } return encoding; }
Example 34 Project: cxf File: AbstractClient.java View source code Vote up 6 votes protected Object[] preProcessResult(Message message) throws Exception { Exchange exchange = message.getExchange(); Exception ex = message.getContent(Exception.class); if (ex != null || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY)) && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY))) { getConfiguration().getConduitSelector().complete(exchange); } if (ex != null) { checkClientException(message, ex); } checkClientException(message, exchange.get(Exception.class)); List<?> result = exchange.get(List.class); return result != null ? result.toArray() : null; }
Example 35 Project: Lather File: IQDestination.java View source code Vote up 6 votes @Override public void processPacket(Packet msg) { SoapPacket soapMsg = (SoapPacket)msg; Message cxfMsg = new MessageImpl(); cxfMsg.setContent(InputStream.class, new ByteArrayInputStream(soapMsg.getChildElementXML().getBytes())); Exchange msgExchange = new ExchangeImpl(); msgExchange.setConduit(new IQBackChannelConduit(soapMsg, getXmppConnection())); cxfMsg.setExchange(msgExchange); // TODO Fix this so a different thread is used. getMessageObserver().onMessage(cxfMsg); }
Example 36 Project: Lather File: PubSubDestination.java View source code Vote up 6 votes @Override public void handlePublishedItems(ItemPublishEvent<PayloadItem<SimplePayload>> events) { for (PayloadItem<SimplePayload> pi : events.getItems()) { SimplePayload soapMsg = pi.getPayload(); Message cxfMsg = new MessageImpl(); cxfMsg.setContent(InputStream.class, new ByteArrayInputStream(soapMsg.toXML().getBytes())); Exchange msgExchange = new ExchangeImpl(); msgExchange.setOneWay(true); msgExchange.setDestination(this); cxfMsg.setExchange(msgExchange); // TODO Fix this so a different thread is used. getMessageObserver().onMessage(cxfMsg); } }
Example 37 Project: ddf-platform File: PolicyWSDLGetInterceptor.java View source code Vote up 6 votes @Override public void handleMessage(Message message) throws Fault { String method = (String) message.get(Message.HTTP_REQUEST_METHOD); String query = (String) message.get(Message.QUERY_STRING); if (!"GET".equals(method) || StringUtils.isEmpty(query)) { return; } String baseUri = (String) message.get(Message.REQUEST_URL); String ctx = (String) message.get(Message.PATH_INFO); Map<String, String> map = UrlUtils.parseQueryString(query); if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) { Document doc = getDocument(message, baseUri, map, ctx); // DDF- start ADDED code if (map.containsKey("wsdl")) { doc = addPolicyToWSDL(doc, loader.getPolicy()); } // DDF- end of ADDED code Endpoint e = message.getExchange().get(Endpoint.class); Message mout = new MessageImpl(); mout.setExchange(message.getExchange()); mout = e.getBinding().createMessage(mout); mout.setInterceptorChain( OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange())); message.getExchange().setOutMessage(mout); mout.put(DOCUMENT_HOLDER, doc); mout.put(Message.CONTENT_TYPE, "text/xml"); // just remove the interceptor which should not be used cleanUpOutInterceptors(mout); // notice this is being added after the purge above, don't swap the order! mout.getInterceptorChain().add(WSDLGetOutInterceptor.INSTANCE); // DDF- CHANGED TRANSFORM_SKIP to transform.skip because private field message.getExchange().put("transform.skip", Boolean.TRUE); // skip the service executor and goto the end of the chain. message.getInterceptorChain() .doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName()); } }
Example 38 Project: tesb-rt-se File: FlowIdProducerTest.java View source code Vote up 6 votes @Test public void flowIdProducerInTest() { FlowIdProducerIn<Message> flowIdProducerIn = new FlowIdProducerIn<Message>(); Message message = new MessageImpl(); Exchange exchange = new ExchangeImpl(); message.setExchange(exchange); String flowId = FlowIdHelper.getFlowId(message); Assert.assertNull("FlowId should be null before FlowIdProducerIn handleMessage()", flowId); flowIdProducerIn.handleMessage(message); flowId = FlowIdHelper.getFlowId(message); Assert.assertNotNull("FlowId should not be null after FlowIdProducerIn handleMessage()", flowId); }
Example 39 Project: tesb-rt-se File: FlowIdProducerTest.java View source code Vote up 6 votes @Test public void flowIdProducerOutTest() { FlowIdProducerOut<Message> flowIdProducerOut = new FlowIdProducerOut<Message>(); Message message = new MessageImpl(); Exchange exchange = new ExchangeImpl(); Message inMessage = new MessageImpl(); exchange.setInMessage(inMessage); message.setExchange(exchange); String flowId = FlowIdHelper.getFlowId(message); Assert.assertNull("FlowId should be null before FlowIdProducerOut handleMessage()", flowId); flowIdProducerOut.handleMessage(message); flowId = FlowIdHelper.getFlowId(message); Assert.assertNotNull("FlowId should not be null after FlowIdProducerOut handleMessage()", flowId); }
Example 40 Project: cxf File: AbstractClient.java View source code Vote up 6 votes protected String convertParamValue(Object pValue, Annotation[] anns) { if (pValue == null) { return null; } ProviderFactory pf = ClientProviderFactory.getInstance(cfg.getEndpoint()); if (pf != null) { Message m = null; if (pf.isParamConverterContextsAvailable()) { m = new MessageImpl(); m.put(Message.REQUESTOR_ROLE, Boolean.TRUE); m.setExchange(new ExchangeImpl()); m.getExchange().setOutMessage(m); m.getExchange().put(Endpoint.class, cfg.getEndpoint()); } Class<?> pClass = pValue.getClass(); @SuppressWarnings("unchecked") ParamConverter<Object> prov = (ParamConverter<Object>)pf.createParameterHandler(pClass, pClass, anns, m); if (prov != null) { try { return prov.toString(pValue); } finally { if (m != null) { pf.clearThreadLocalProxies(); } } } } return pValue.toString(); }
Example 41 Project: cxf File: AbstractClient.java View source code Vote up 6 votes protected Exchange createExchange(Message m, Exchange exchange) { if (exchange == null) { exchange = new ExchangeImpl(); } exchange.setSynchronous(true); exchange.setOutMessage(m); exchange.put(Bus.class, cfg.getBus()); exchange.put(MessageObserver.class, new ClientMessageObserver(cfg)); exchange.put(Endpoint.class, cfg.getConduitSelector().getEndpoint()); exchange.put("org.apache.cxf.transport.no_io_exceptions", true); //REVISIT - when response handling is actually put onto the in chain, this will likely not be needed exchange.put(StaxInEndingInterceptor.STAX_IN_NOCLOSE, Boolean.TRUE); m.setExchange(exchange); return exchange; }
Example 42 Project: ddf-spatial File: EndpointOperationInfoResourceComparator.java View source code Vote up 5 votes @Override public int compare(OperationResourceInfo oper1, OperationResourceInfo oper2, Message message) { if (null == oper1 || null == oper2 || null == message) { LOGGER.warn("Found NULL parameters in the compare method."); return 0; } String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD); LOGGER.debug("HTTP METHOD = {}", httpMethod); String requestName = null; String requestedService = null; if (HTTP_GET.equalsIgnoreCase(httpMethod)) { String queryString = (String) message.get(Message.QUERY_STRING); if (StringUtils.isNotEmpty(queryString)) { MultivaluedMap<String, String> allQueryParams = JAXRSUtils .getStructuredParams(queryString, QUERY_PARAM_DELIMITER, false, false); // Loop through the keys and do a case insensitive check for (Entry<String, List<String>> queryParam : allQueryParams.entrySet()) { if ((REQUEST_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam .getValue().isEmpty()) && requestName == null) { // We should never have more than one "request" query // param so ignore them if we do requestName = queryParam.getValue().get(0); LOGGER.debug("Request Query Param = {}", requestName); } if ((SERVICE_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam .getValue().isEmpty()) && requestedService == null) { // We should never have more than one "service" query // param so ignore them if we do requestedService = queryParam.getValue().get(0); LOGGER.debug("Service Query Param = {}", requestedService); } } } } else if (HTTP_POST.equalsIgnoreCase(httpMethod)) { // Get the payload try (InputStream is = message.getContent(InputStream.class)) { if (is != null) { CachedOutputStream bos = new CachedOutputStream(); // We need to make a copy and put it back for later // processing IOUtils.copy(is, bos); bos.flush(); is.close(); message.setContent(InputStream.class, bos.getInputStream()); XMLSource xml = new XMLSource(bos.getInputStream()); xml.setBuffering(); // The request name will be the root node name requestName = xml.getValue("local-name(/*)"); requestedService = xml.getValue("/*/@service"); LOGGER.debug("ROOT NODE = {}", requestName); LOGGER.debug("Service Name = {}", requestedService); bos.close(); } } catch (IOException ioe) { LOGGER.warn("Unable to read message contents", ioe); } } else { LOGGER.warn("Got unknown HTTP Method {}", httpMethod); return 0; } if (StringUtils.isEmpty(requestName)) { LOGGER.warn("Unable to determine the request name"); return 0; } int op1Rank = getOperationRank(oper1, requestName, requestedService); int op2Rank = getOperationRank(oper2, requestName, requestedService); return (op1Rank == op2Rank) ? 0 : (op1Rank < op2Rank) ? 1 : -1; }
Example 43 Project: ddf-catalog File: EndpointOperationInfoResourceComparator.java View source code Vote up 5 votes @Override public int compare(OperationResourceInfo oper1, OperationResourceInfo oper2, Message message) { if (null == oper1 || null == oper2 || null == message) { LOGGER.warn("Found NULL parameters in the compare method."); return 0; } String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD); LOGGER.debug("HTTP METHOD = {}", httpMethod); String requestName = null; String requestedService = null; if (HTTP_GET.equalsIgnoreCase(httpMethod)) { String queryString = (String) message.get(Message.QUERY_STRING); if (StringUtils.isNotEmpty(queryString)) { MultivaluedMap<String, String> allQueryParams = JAXRSUtils .getStructuredParams(queryString, QUERY_PARAM_DELIMITER, false, false); // Loop through the keys and do a case insensitive check for (Entry<String, List<String>> queryParam : allQueryParams.entrySet()) { if ((REQUEST_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam .getValue().isEmpty()) && requestName == null) { // We should never have more than one "request" query // param so ignore them if we do requestName = queryParam.getValue().get(0); LOGGER.debug("Request Query Param = {}", requestName); } if ((SERVICE_PARAM.equalsIgnoreCase(queryParam.getKey())) && (!queryParam .getValue().isEmpty()) && requestedService == null) { // We should never have more than one "service" query // param so ignore them if we do requestedService = queryParam.getValue().get(0); LOGGER.debug("Service Query Param = {}", requestedService); } } } } else if (HTTP_POST.equalsIgnoreCase(httpMethod)) { // Get the payload try (InputStream is = message.getContent(InputStream.class)) { if (is != null) { CachedOutputStream bos = new CachedOutputStream(); // We need to make a copy and put it back for later // processing IOUtils.copy(is, bos); bos.flush(); is.close(); message.setContent(InputStream.class, bos.getInputStream()); XMLSource xml = new XMLSource(bos.getInputStream()); xml.setBuffering(); // The request name will be the root node name requestName = xml.getValue("local-name(/*)"); requestedService = xml.getValue("/*/@service"); LOGGER.debug("ROOT NODE = {}", requestName); LOGGER.debug("Service Name = {}", requestedService); bos.close(); } } catch (IOException ioe) { LOGGER.warn("Unable to read message contents", ioe); } } else { LOGGER.warn("Got unknown HTTP Method {}", httpMethod); return 0; } if (StringUtils.isEmpty(requestName)) { LOGGER.warn("Unable to determine the request name"); return 0; } int op1Rank = getOperationRank(oper1, requestName, requestedService); int op2Rank = getOperationRank(oper2, requestName, requestedService); return (op1Rank == op2Rank) ? 0 : (op1Rank < op2Rank) ? 1 : -1; }