/** * Disconnects the URL specified on the endpoint from the specified processor. */ @Override public void disconnect(HttpConsumer consumer) throws Exception { // If the connector is not needed anymore then stop it HttpEndpoint endpoint = consumer.getEndpoint(); String connectorKey = getConnectorKey(endpoint); synchronized (CONNECTORS) { ConnectorRef connectorRef = CONNECTORS.get(connectorKey); if (connectorRef != null) { connectorRef.servlet.disconnect(consumer); if (connectorRef.decrement() == 0) { connectorRef.server.removeConnector(connectorRef.connector); connectorRef.connector.stop(); connectorRef.server.stop(); CONNECTORS.remove(connectorKey); // Camel controls the lifecycle of these entities so remove the // registered MBeans when Camel is done with the managed objects. if (mbContainer != null) { this.removeServerMBean(connectorRef.server); //mbContainer.removeBean(connectorRef.connector); } } } } }
private void enableMultipartFilter(HttpEndpoint endpoint, Server server, String connectorKey) throws Exception { ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class); CamelContext camelContext = this.getCamelContext(); FilterHolder filterHolder = new FilterHolder(); filterHolder.setInitParameter("deleteFiles", "true"); if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) { File file = new File(camelContext.getProperty(TMP_DIR)); if (!file.isDirectory()) { throw new RuntimeCamelException( "The temp file directory of camel-jetty is not exists, please recheck it with directory name :" + camelContext.getProperties().get(TMP_DIR)); } context.setAttribute("javax.servlet.context.tempdir", file); } // if a filter ref was provided, use it. Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter(); if (filter == null) { // if no filter ref was provided, use the default filter filter = new MultiPartFilter(); } filterHolder.setFilter(new CamelFilterWrapper(filter)); String pathSpec = endpoint.getPath(); if (pathSpec == null || "".equals(pathSpec)) { pathSpec = "/"; } if (endpoint.isMatchOnUriPrefix()) { pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*"; } addFilter(context, filterHolder, pathSpec); if (LOG.isDebugEnabled()) LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec); }
protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { port1 = getPort(); port2 = getNextPort(); errorHandler(noErrorHandler()); Processor serviceProc = new Processor() { public void process(Exchange exchange) throws Exception { Message in = exchange.getIn(); // put the number of attachments in a response header exchange.getOut().setHeader("numAttachments", in.getAttachments().size()); exchange.getOut().setBody(in.getHeader("body")); } }; HttpEndpoint epOut = getContext().getEndpoint("http://localhost:" + port1 + "?bridgeEndpoint=true&throwExceptionOnFailure=false", HttpEndpoint.class); epOut.setHeaderFilterStrategy(new MultipartHeaderFilterStrategy()); from("jetty:http://localhost:" + port2 + "/test/hello?enableMultipartFilter=false") .to(epOut); from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc); } }; }
private HttpEndpoint createHttpEndpoint(boolean bridgeEndpoint, String endpointURI) throws URISyntaxException { HttpEndpoint endpoint = new HttpEndpoint(); endpoint.setBridgeEndpoint(bridgeEndpoint); if (endpointURI != null) { endpoint.setHttpUri(new URI(endpointURI)); } return endpoint; }
AttachmentHttpBinding(HttpEndpoint endpoint) { super(endpoint); }
private String getConnectorKey(HttpEndpoint endpoint) { return endpoint.getProtocol() + ":" + endpoint.getHttpUri().getHost() + ":" + endpoint.getPort(); }
public JettyRestHttpBinding(HttpEndpoint ep) { super(ep); }