private void sendErrorResponse(Message message, int responseCode) { Message outMessage = getOutMessage(message); outMessage.put(Message.RESPONSE_CODE, responseCode); // Set the response headers Map responseHeaders = (Map) message.get(Message.PROTOCOL_HEADERS); if (responseHeaders != null) { responseHeaders.put("WWW-Authenticate", Arrays.asList("Basic realm=\"" + realm + "\"")); responseHeaders.put("Content-Length", Arrays.asList("0")); } message.getInterceptorChain().abort(); try { // getConduit(message).prepare(outMessage); message.getExchange().getConduit(message).prepare(outMessage); // TEST ME OutputStream os = outMessage.getContent(OutputStream.class); String errmsg = "Error " + responseCode + ": "; os.write(errmsg.getBytes()); LOGGER.info("Sending error " + responseCode); close(outMessage); } catch (IOException e) { LOGGER.warn(e.getMessage(), e); } }
private void sendErrorResponse(Message message, int responseCode) { Message outMessage = getOutMessage(message); outMessage.put(Message.RESPONSE_CODE, responseCode); // Set the response headers @SuppressWarnings("unchecked") Map<String, List<String>> responseHeaders = (Map)message.get(Message.PROTOCOL_HEADERS); if (responseHeaders != null) { responseHeaders.put("WWW-Authenticate", Collections.singletonList("Basic realm=" + authentication.getRealm())); responseHeaders.put("Content-length", Collections.singletonList("0")); } message.getInterceptorChain().abort(); try { getConduit(message).prepare(outMessage); close(outMessage); } catch (IOException e) { log.warn(e.getMessage(), e); } }
try message.getExchange().getConduit(message).prepare(outMessage); // TEST ME
public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); os.write(message); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); os.close(); return obs.getResponseStream().toByteArray(); }
public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); os.write(message); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); os.close(); return obs.getResponseStream().toByteArray(); }
public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei, getBus()); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); os.write(message); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); os.close(); return obs.getResponseStream().toByteArray(); }
public void handleMessage(Message message) { try { getConduit(message).prepare(message); } catch (IOException ex) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_SEND", BUNDLE), ex); } // Add a final interceptor to close the conduit message.getInterceptorChain().add(ending); }
public void handleMessage(Message message) { try { getConduit(message).prepare(message); } catch (IOException ex) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_SEND", BUNDLE), ex); } // Add a final interceptor to close the conduit message.getInterceptorChain().add(ending); }
public void handleMessage(Message message) { try { getConduit(message).prepare(message); } catch (IOException ex) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_SEND", BUNDLE), ex); } // Add a final interceptor to close the conduit message.getInterceptorChain().add(ending); }
public void handleMessage(Message message) { try { getConduit(message).prepare(message); } catch (IOException ex) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_SEND", BUNDLE), ex); } // Add a final interceptor to close the conduit message.getInterceptorChain().add(ending); }
public byte[] invokeBytes(String address, String transport, String message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); InputStream is = getResourceAsStream(message); if (is == null) { throw new RuntimeException("Could not find resource " + message); } IOUtils.copy(is, os); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); is.close(); os.close(); byte[] bs = obs.getResponseStream().toByteArray(); return bs; } public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
public byte[] invokeBytes(String address, String transport, String message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); InputStream is = getResourceAsStream(message); if (is == null) { throw new RuntimeException("Could not find resource " + message); } IOUtils.copy(is, os); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); is.close(); os.close(); byte[] bs = obs.getResponseStream().toByteArray(); return bs; } public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
public byte[] invokeBytes(String address, String transport, String message) throws Exception { EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http"); ei.setAddress(address); ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class); ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport); Conduit conduit = conduitInit.getConduit(ei, getBus()); TestMessageObserver obs = new TestMessageObserver(); conduit.setMessageObserver(obs); Message m = new MessageImpl(); conduit.prepare(m); OutputStream os = m.getContent(OutputStream.class); InputStream is = getResourceAsStream(message); if (is == null) { throw new RuntimeException("Could not find resource " + message); } IOUtils.copy(is, os); // TODO: shouldn't have to do this. IO caching needs cleaning // up or possibly removal... os.flush(); is.close(); os.close(); return obs.getResponseStream().toByteArray(); }
public void onMessage(Message message) { try { // HTTP seems to need this right now... ExchangeImpl ex = new ExchangeImpl(); ex.setInMessage(message); Conduit backChannel = message.getDestination().getBackChannel(message); MessageImpl res = new MessageImpl(); ex.setOutMessage(res); res.put(Message.CONTENT_TYPE, "text/xml"); backChannel.prepare(res); OutputStream out = res.getContent(OutputStream.class); InputStream is = resource.openStream(); IOUtils.copy(is, out, 2048); out.flush(); out.close(); is.close(); backChannel.close(res); } catch (Exception e) { e.printStackTrace(); } }
/** * This function issues a 401 response back down the conduit. * If the realm is not null, a WWW-Authenticate: Basic realm= * header is sent. The interceptor chain is aborted stopping * the Message from going to the servant. */ private void replyUnauthorized(Message message, String realm) { Message outMessage = getOutMessage(message); outMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_UNAUTHORIZED); if (realm != null) { setHeader(outMessage, "WWW-Authenticate", "Basic realm=" + realm); } message.getInterceptorChain().abort(); try { getConduit(message).prepare(outMessage); close(outMessage); } catch (IOException e) { //System.out.println("Prepare of message not working." + e); e.printStackTrace(); } }
conduit.prepare(m);
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); URI uri = null; try { uri = URI.create(baseUri); } catch (IllegalArgumentException iae) { //invalid URI, ignore and continue return; } Map<String, String> map = UrlUtils.parseQueryString(query); if (isRecognizedQuery(map, uri, message.getExchange().getEndpoint().getEndpointInfo())) { try { Conduit c = message.getExchange().getDestination().getBackChannel(message); Message mout = new MessageImpl(); mout.setExchange(message.getExchange()); message.getExchange().setOutMessage(mout); mout.put(Message.CONTENT_TYPE, "application/javascript;charset=UTF-8"); c.prepare(mout); OutputStream os = mout.getContent(OutputStream.class); writeResponse(uri, map, os, message.getExchange().getEndpoint()); } catch (IOException ioe) { throw new Fault(ioe); } } }
conduit.prepare(m);
conduit.prepare(m);
c.prepare(outMessage);