http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentResource.java deleted file mode 100644 index 524c54b..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentResource.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -/** - * - */ -public class ComponentResource extends CamelChildResourceSupport { - private String id; - - public ComponentResource(CamelContextResource contextResource, String id) { - super(contextResource); - this.id = id; - } - - public String getId() { - return id; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentsResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentsResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentsResource.java deleted file mode 100644 index 393b5d6..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/ComponentsResource.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -/** - * Represents the list of the currently active <a href="http://camel.apache.org/component.html">components</a> - * in the current camel context - */ -public class ComponentsResource extends CamelChildResourceSupport { - public ComponentsResource(CamelContextResource contextResource) { - super(contextResource); - } - - public List<String> getComponentIds() { - List<String> answer = new ArrayList<String>(getCamelContext().getComponentNames()); - Collections.sort(answer); - return answer; - } - - /** - * Returns a specific component - */ - @Path("{id}") - public ComponentResource getLanguage(@PathParam("id") String id) { - if (id == null) { - return null; - } - return new ComponentResource(getContextResource(), id); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/Constants.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/Constants.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/Constants.java deleted file mode 100644 index e14e567..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/Constants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -/** - * - */ -public final class Constants { - - public static final String HTML_MIME_TYPES = "text/html;qs=5"; - - public static final String DATA_MIME_TYPES = "text/xml,application/xml,application/json"; - - public static final String DOT_MIMETYPE = "text/vnd.graphviz"; - public static final String JAXB_PACKAGES = org.apache.camel.model.Constants.JAXB_CONTEXT_PACKAGES + ":org.apache.camel.web.model"; - - private Constants() { - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersFromResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersFromResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersFromResource.java deleted file mode 100644 index 0b0a579..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersFromResource.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.util.Map; -import java.util.TreeMap; - -import org.apache.camel.TypeConverter; -import org.apache.camel.impl.converter.DefaultTypeConverter; - -/** - * - */ -public class ConvertersFromResource extends CamelChildResourceSupport { - private Class<?> type; - - public ConvertersFromResource(CamelContextResource contextResource, Class<?> type) { - super(contextResource); - this.type = type; - } - - public Map<String, TypeConverter> getConverters() { - Map<String, TypeConverter> answer = new TreeMap<String, TypeConverter>(); - DefaultTypeConverter converter = getDefaultTypeConverter(); - if (converter != null) { - Map<Class<?>, TypeConverter> classes = converter.getToClassMappings(type); - for (Map.Entry<Class<?>, TypeConverter> entry : classes.entrySet()) { - Class<?> aClass = entry.getKey(); - String name = ConvertersResource.nameOf(aClass); - answer.put(name, entry.getValue()); - } - } - return answer; - } - - public Class<?> getType() { - return type; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java deleted file mode 100644 index be596d5..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/ConvertersResource.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.apache.camel.impl.converter.DefaultTypeConverter; - -/** - * - */ -public class ConvertersResource extends CamelChildResourceSupport { - public ConvertersResource(CamelContextResource contextResource) { - super(contextResource); - } - - public Map<String, Class<?>> getFromClassTypes() { - Map<String, Class<?>> answer = new TreeMap<String, Class<?>>(); - DefaultTypeConverter converter = getDefaultTypeConverter(); - if (converter != null) { - Set<Class<?>> classes = converter.getFromClassMappings(); - for (Class<?> aClass : classes) { - String name = nameOf(aClass); - answer.put(name, aClass); - } - } - return answer; - } - - - /** - * Returns type converters from the given type - */ - @Path("{type}") -/* - TODO this doesn't work in JAX-RS yet - - public ConvertersFromResource getConvertersFrom(@PathParam("type") Class type) { -*/ - - public ConvertersFromResource getConvertersFrom(@PathParam("type") String typeName) { - Class<?> type = getCamelContext().getClassResolver().resolveClass(typeName, getClass().getClassLoader()); - if (type == null) { - return null; - } - return new ConvertersFromResource(getContextResource(), type); - } - - - public static String nameOf(Class<?> aClass) { - return aClass.getCanonicalName(); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointResource.java deleted file mode 100644 index 5ffa354..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointResource.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -import com.sun.jersey.api.representation.Form; - -import org.apache.camel.Endpoint; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.spi.BrowsableEndpoint; -import org.apache.camel.util.ExchangeHelper; -import org.apache.camel.web.model.EndpointLink; - -/** - * A Camel <a href="http://camel.apache.org/endpoint.html">Endpoint</a> - */ -public class EndpointResource extends CamelChildResourceSupport { - private final String key; - private final Endpoint endpoint; - - public EndpointResource(CamelContextResource contextResource, String key, Endpoint endpoint) { - super(contextResource); - this.key = key; - this.endpoint = endpoint; - } - - public String getHref() { - return new EndpointLink(key, endpoint).getHref(); - } - - public String getKey() { - return key; - } - - public String getUri() { - return endpoint.getEndpointUri(); - } - - public Endpoint getEndpoint() { - return endpoint; - } - - public BrowsableEndpoint getBrowsableEndpoint() { - if (endpoint instanceof BrowsableEndpoint) { - return (BrowsableEndpoint) endpoint; - } - return null; - } - - /** - * Returns a single Camel <a href="http://camel.apache.org/exchange.html">message exchange</a> on this endpoint if the endpoint supports - * <a href="http://camel.apache.org/browsableendpoint.html">being browsed</a> - */ - @Path("messages/{id}") - public ExchangeResource getExchange(@PathParam("id") String exchangeId) { - if (endpoint instanceof BrowsableEndpoint) { - BrowsableEndpoint browsableEndpoint = (BrowsableEndpoint) endpoint; - Exchange exchange = ExchangeHelper.getExchangeById(browsableEndpoint.getExchanges(), exchangeId); - if (exchange != null) { - return new ExchangeResource(this, exchange); - } - } - // should return 404 - return null; - } - - /** - * Posts a <a href="http://camel.apache.org/message.html">message</a> to this Camel endpoint with the payload - * being text, XML or JSON - */ - @POST - @Consumes({MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.TEXT_XML, MediaType.APPLICATION_XML}) - public Response postMessage(@Context HttpHeaders headers, final String body) throws URISyntaxException { - Map<String, Object> messageHeaders = multivalueMapToMap(headers.getRequestHeaders()); - sendMessage(messageHeaders, body); - return Response.ok().build(); - } - - /** - * Posts a <a href="http://camel.apache.org/message.html">message</a> to this Camel endpoint taking the - * form data and extracting the <code>body</code> field as the body of the message. - */ - @POST - @Consumes("application/x-www-form-urlencoded") - public Response postMessageForm(@Context HttpHeaders headers, Form formData) throws URISyntaxException { - String body = getBodyData(formData); - - Map<String, Object> messageHeaders = multivalueMapToMap(headers.getRequestHeaders()); - messageHeaders.putAll(getHeadersData(formData)); - - sendMessage(messageHeaders, body); - return Response.seeOther(new URI(getHref())).build(); - } - - private Map<String, Object> getHeadersData(Form formData) { - Map<String, Object> headers = new HashMap<String, Object>(); - Map<String, Object> formMap = multivalueMapToMap(formData); - for (Map.Entry<String, Object> entry : formMap.entrySet()) { - if (entry.getKey().startsWith("header_")) { - headers.put((String) entry.getValue(), getHeaderValueForKey(entry.getKey(), formMap)); - } - } - return headers; - } - - private Object getHeaderValueForKey(String key, Map<String, Object> headers) { - return headers.get("value_" + key); - } - - private String getBodyData(Form formData) { - return formData.getFirst("body", String.class); - } - - private Map<String, Object> multivalueMapToMap(MultivaluedMap<String, String> multivaluedMap) { - Map<String, Object> resultMap = new HashMap<String, Object>(); - if (multivaluedMap != null) { - for (Map.Entry<String, List<String>> entry : multivaluedMap.entrySet()) { - List<String> values = entry.getValue(); - int size = values.size(); - if (size == 1) { - resultMap.put(entry.getKey(), entry.getValue().get(0)); - } else if (size > 0) { - resultMap.put(entry.getKey(), entry.getValue()); - } - } - } - return resultMap; - } - - protected void sendMessage(final Map<String, Object> headers, final String body) { - getTemplate().send(endpoint, new Processor() { - public void process(Exchange exchange) throws Exception { - Message in = exchange.getIn(); - in.setBody(body); - in.setHeaders(headers); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java deleted file mode 100644 index 0ef46b1..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/EndpointsResource.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.api.view.Viewable; -import org.apache.camel.Endpoint; -import org.apache.camel.spi.HasId; -import org.apache.camel.web.model.EndpointLink; -import org.apache.camel.web.model.Endpoints; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The active endpoints in Camel - * - */ -public class EndpointsResource extends CamelChildResourceSupport { - private static final Logger LOG = LoggerFactory.getLogger(EndpointsResource.class); - - private String error = ""; - private String newUri = "mock:someName"; - - public EndpointsResource(CamelContextResource contextResource) { - super(contextResource); - } - - /** - * Returns a list of endpoints available in this context - */ - @GET - @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Endpoints getDTO() { - return new Endpoints(getCamelContext()); - } - - - /** - * Returns the resource of an individual Camel endpoint - * - * @param id the endpoints unique URI - */ - @Path("{id}") - public EndpointResource getEndpoint(@PathParam("id") String id) { - // TODO lets assume the ID is the endpoint - Endpoint endpoint = null; - if (id != null) { - // lets remove any whitespace - id = id.trim(); - if (id.length() > 0) { - endpoint = getCamelContext().getEndpoint(id); - } - } - if (endpoint == null) { - for (Endpoint e : getCamelContext().getEndpoints()) { - if (e instanceof HasId) { - HasId hasId = (HasId) e; - String value = hasId.getId(); - if (value != null && value.equals(id)) { - endpoint = e; - break; - } - } - } - } - if (endpoint != null) { - return new EndpointResource(getContextResource(), id, endpoint); - } else { - LOG.warn("No endpoint found for id: " + id); - return null; - } - } - - - // Creating endpoints - //------------------------------------------------------------------------- - - /** - * Creates a new Endpoint for the given URI that is posted. - * - * @param uri the plain text URI of the endpoint to be created - */ - @POST - @Consumes(MediaType.TEXT_PLAIN) - public Response postUri(String uri) throws URISyntaxException { - EndpointResource endpoint = getEndpoint(uri); - if (endpoint != null) { - return Response.ok().build(); - } - return Response.noContent().build(); - } - - /** - * Creates a new Endpoint for the given URI that is posted using form encoding with the <code>uri</code> - * value in the form being used to specify the endpoints unique URI. - * - * @param formData is the form data POSTed typically from a HTML form with the <code>uri</code> field used to create - * the endpoint - */ - @POST - @Consumes("application/x-www-form-urlencoded") - public Response postUriForm(@Context UriInfo uriInfo, Form formData) throws URISyntaxException { - // TODO replace the Form class with an injected bean? - LOG.info("Received form! " + formData); - newUri = formData.getFirst("uri", String.class); - EndpointResource endpoint = getEndpoint(newUri); - if (endpoint != null) { - String href = endpoint.getHref(); - LOG.info("Created endpoint so redirecting to " + href); - return Response.seeOther(new URI(href)).build(); - } else { - error = "Could not find a component to resolve that URI"; - - LOG.info("Failed to create new endpoint!"); - - // lets re-render the form - return Response.ok(new Viewable("index", this)).build(); - } - } - - - // Properties - //------------------------------------------------------------------------- - - public List<EndpointLink> getEndpoints() { - return getDTO().getEndpoints(); - } - - public String getError() { - return error; - } - - public String getNewUri() { - return newUri; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/ExchangeResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/ExchangeResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/ExchangeResource.java deleted file mode 100644 index 5b9fe26..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/ExchangeResource.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.util.Map; -import java.util.TreeMap; - -import com.sun.jersey.api.view.ImplicitProduces; -import org.apache.camel.CamelContext; -import org.apache.camel.Endpoint; -import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; -import org.apache.camel.Message; -import org.apache.camel.spi.UnitOfWork; - -/** - * A Camel <a href="http://camel.apache.org/exchange.html">message exchange</a> - * - */ -@ImplicitProduces(Constants.HTML_MIME_TYPES) -public class ExchangeResource { - private final Exchange exchange; - - public ExchangeResource(EndpointResource endpointResource, Exchange exchange) { - this.exchange = exchange; - } - - public Exchange getExchange() { - return exchange; - } - - // Helper methods for the view - public CamelContext getCamelContext() { - return exchange.getContext(); - } - - public String getExchangeId() { - return exchange.getExchangeId(); - } - - public Throwable getException() { - return exchange.getException(); - } - - public Endpoint getFromEndpoint() { - return exchange.getFromEndpoint(); - } - - public Message getIn() { - return exchange.getIn(); - } - - public Message getOut() { - return exchange.getOut(); - } - - public boolean hasOut() { - return exchange.hasOut(); - } - - public Map<String, Object> getProperties() { - return new TreeMap<String, Object>(exchange.getProperties()); - } - - public Map<String, Object> getHeaders() { - return new TreeMap<String, Object>(exchange.getIn().getHeaders()); - } - - public ExchangePattern getPattern() { - return exchange.getPattern(); - } - - public UnitOfWork getUnitOfWork() { - return exchange.getUnitOfWork(); - } - - public boolean isFailed() { - return exchange.isFailed(); - } - - public boolean isTransacted() { - return exchange.isTransacted(); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguageResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguageResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguageResource.java deleted file mode 100644 index aad131f..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguageResource.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -/** - * - */ -public class LanguageResource extends CamelChildResourceSupport { - private String id; - - public LanguageResource(CamelContextResource contextResource, String id) { - super(contextResource); - this.id = id; - } - - public String getId() { - return id; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguagesResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguagesResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguagesResource.java deleted file mode 100644 index b174a00..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/LanguagesResource.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -/** - * Represents the list of the currently active <a href="http://camel.apache.org/languages.html">languages</a> - * in the current camel context - */ -public class LanguagesResource extends CamelChildResourceSupport { - - public LanguagesResource(CamelContextResource contextResource) { - super(contextResource); - } - - public List<String> getLanguageIds() { - List<String> answer = new ArrayList<String>(getCamelContext().getLanguageNames()); - Collections.sort(answer); - return answer; - } - - /** - * Returns a specific language - */ - @Path("{id}") - public LanguageResource getLanguage(@PathParam("id") String id) { - if (id == null) { - return null; - } - return new LanguageResource(getContextResource(), id); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java deleted file mode 100644 index 945d93e..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java +++ /dev/null @@ -1,257 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collections; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import com.sun.jersey.api.view.Viewable; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.model.ModelCamelContext; -import org.apache.camel.model.RouteDefinition; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.view.RouteDotGenerator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * A single Camel Route which is used to implement one or more - * <a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Patterns</a> - */ -public class RouteResource extends CamelChildResourceSupport { - public static final String LANGUAGE_XML = "Xml"; - private static final Logger LOG = LoggerFactory.getLogger(RouteResource.class); - - private RouteDefinition route; - private String error = ""; - private String id; - - // what language is used to define this route - private String language = LANGUAGE_XML; - - public RouteResource(RoutesResource routesResource, RouteDefinition route) { - super(routesResource.getContextResource()); - this.route = route; - this.id = route.idOrCreate(getCamelContext().getNodeIdFactory()); - } - - /** - * Returns the XML or JSON representation of this route - */ - @GET - @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public RouteDefinition getRoute() { - return route; - } - - /** - * Removes this route - */ - @GET - @Path("remove") - @Produces(MediaType.TEXT_HTML) - public Response removeRoute() { - URI routesURI = null; - try { - routesURI = new URI("/routes"); - ((ModelCamelContext)getCamelContext()).removeRouteDefinition(route); - return Response.seeOther(routesURI).build(); - } catch (Exception e) { - LOG.error("failed to remove route " + id + ", error " + e.getMessage()); - return Response.seeOther(routesURI).build(); - } - } - - /** - * Returns the XML text - */ - public String getRouteXml() throws JAXBException { - JAXBContext context = ((ModelCamelContext)getCamelContext()).getModelJAXBContextFactory().newJAXBContext(); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - // TODO fix to use "" namespace prefix - // using this - // https://jaxb.dev.java.net/nonav/2.1.10/docs/vendorProperties.html#prefixmapper - StringWriter buffer = new StringWriter(); - marshaller.marshal(route, buffer); - return buffer.toString(); - } - - /** - * Returns the content of the route definition class - */ - public String getRouteDefinition() { - if (language.equalsIgnoreCase(LANGUAGE_XML)) { - try { - return getRouteXml(); - } catch (JAXBException e) { - return "Error on marshal the route definition!"; - } - } else { - return "Unsupported language!"; - } - } - - /** - * Returns the Graphviz DOT <a - * href="http://camel.apache.org/visualisation.html">Visualisation</a> of - * this route - */ - @GET - @Produces(Constants.DOT_MIMETYPE) - public String getDot() throws IOException { - RouteDotGenerator generator = new RouteDotGenerator("/tmp/camel"); - return generator.getRoutesText(getCamelContext()); - } - - /** - * Allows a route definition to be updated - */ - @POST - @Consumes() - @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public void postRoute(RouteDefinition routeDefinition) throws Exception { - // lets preserve the ID - routeDefinition.setId(id); - - // lets install the updated route - ((ModelCamelContext)getCamelContext()).addRouteDefinitions(Collections.singletonList(routeDefinition)); - } - - /** - * Allows a routes builder to be updated - */ - public void postRoutes(RouteBuilder builder) throws Exception { - DefaultCamelContext defaultCamelContext = (DefaultCamelContext)getCamelContext(); - // stop and remove the original route - defaultCamelContext.stopRoute(id); - defaultCamelContext.removeRoute(id); - - // add the routes in a route builder - defaultCamelContext.addRoutes(builder); - - // reserve the id on the newest route - List<RouteDefinition> routeDefinitions = defaultCamelContext.getRouteDefinitions(); - RouteDefinition route = routeDefinitions.get(routeDefinitions.size() - 1); - route.setId(id); - defaultCamelContext.startRoute(route); - } - - /** - * Updates a route definition using form encoded data from a web form - * - * @param language is the edited language used on this route - * @param body is the route definition content POSTed typically from a HTML - * form with the <code>route</code> field - * @param edited is a flag to show whether the route have been edited - */ - @POST - @Consumes("application/x-www-form-urlencoded") - public Response postRouteForm(@Context UriInfo uriInfo, @FormParam("language") String language, - @FormParam("route") String body, @FormParam("edited") String edited) - throws URISyntaxException { - - if (edited.equals("false")) { - return Response.seeOther(new URI("/routes")).build(); - } - - LOG.debug("New Route is: {}", body); - - LOG.info(body); - if (body == null) { - error = "No Route submitted!"; - } else if (language.equals(LANGUAGE_XML)) { - return parseXml(body); - } - error = "Not supproted language!"; - return Response.ok(new Viewable("edit", this)).build(); - } - - /** - * process the route configuration defined in Xml - */ - private Response parseXml(String xml) { - try { - JAXBContext context = ((ModelCamelContext)getCamelContext()).getModelJAXBContextFactory().newJAXBContext(); - Unmarshaller unmarshaller = context.createUnmarshaller(); - Object value = unmarshaller.unmarshal(new StringReader(xml)); - if (value instanceof RouteDefinition) { - RouteDefinition routeDefinition = (RouteDefinition)value; - postRoute(routeDefinition); - return Response.seeOther(new URI("/routes")).build(); - } else { - error = "Posted XML is not a route but is of type " + ObjectHelper.className(value); - } - } catch (JAXBException e) { - error = "Failed to parse XML: " + e.getMessage(); - } catch (Exception e) { - error = "Failed to install route: " + e.getMessage(); - } - // lets re-render the form - return Response.ok(new Viewable("edit", this)).build(); - } - - /** - * Returns the language - */ - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = LANGUAGE_XML; - } - - /** - * Looks up an individual route - */ - @Path("status") - public RouteStatusResource getRouteStatus() { - return new RouteStatusResource(this); - } - - public String getError() { - return error; - } - - public String getId() { - return id; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java deleted file mode 100644 index 018b1af..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteStatusResource.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.net.URI; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import com.sun.jersey.api.representation.Form; -import org.apache.camel.CamelContext; -import org.apache.camel.ServiceStatus; -import org.apache.camel.model.RouteDefinition; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents the status of a single single Camel Route which is used to implement one or more - * <a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Paterns</a> - */ -public class RouteStatusResource { - - private static final Logger LOG = LoggerFactory.getLogger(RouteStatusResource.class); - private RouteResource routeResource; - - public RouteStatusResource(RouteResource routeResource) { - this.routeResource = routeResource; - } - - public RouteDefinition getRoute() { - return routeResource.getRoute(); - } - - public CamelContext getCamelContext() { - return routeResource.getCamelContext(); - } - - @GET - @Produces(MediaType.TEXT_PLAIN) - public String getStatusText() { - ServiceStatus status = getStatus(); - if (status != null) { - return status.toString(); - } - return null; - } - - public ServiceStatus getStatus() { - return getRoute().getStatus(getCamelContext()); - } - - @POST - @Consumes(MediaType.TEXT_PLAIN) - public Response setStatus(String status) throws Exception { - if (status != null) { - if (status.equalsIgnoreCase("start")) { - getCamelContext().startRoute(getRoute().getId()); - return Response.ok().build(); - } else if (status.equalsIgnoreCase("stop")) { - getCamelContext().stopRoute(getRoute().getId()); - return Response.ok().build(); - } - } - return Response.noContent().build(); - } - - - /** - * Sets the status of this route to either "start" or "stop" - * - * @param formData is the form data POSTed typically from a HTML form with the <code>status</code> field - * set to either "start" or "stop" - */ - @POST - @Consumes("application/x-www-form-urlencoded") - public Response setStatus(Form formData) throws Exception { - // TODO replace the Form class with an injected bean? - LOG.info("Received form! " + formData); - String status = formData.getFirst("status", String.class); - setStatus(status); - return Response.seeOther(new URI("/routes")).build(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java b/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java deleted file mode 100644 index 26a0e1f..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/resources/RoutesResource.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.resources; - -import java.io.IOException; -import java.io.StringReader; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - -import com.sun.jersey.api.view.Viewable; - -import org.apache.camel.CamelContext; -import org.apache.camel.model.ModelCamelContext; -import org.apache.camel.model.RouteDefinition; -import org.apache.camel.model.RoutesDefinition; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.view.RouteDotGenerator; -import org.apache.camel.web.model.Route; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The active routes in Camel which are used to implement one or more <a - * href="http://camel.apache.org/enterprise-integration-patterns.html" - * >Enterprise Integration Patterns</a> - */ -public class RoutesResource extends CamelChildResourceSupport { - private static final Logger LOG = LoggerFactory.getLogger(RoutesResource.class); - private String error = ""; - - public RoutesResource(CamelContextResource contextResource) { - super(contextResource); - } - - /** - * Returns the routes currently active within this context - */ - @GET - @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @SuppressWarnings("deprecation") - public RoutesDefinition getRouteDefinitions() { - RoutesDefinition answer = new RoutesDefinition(); - CamelContext camelContext = getCamelContext(); - if (camelContext != null) { - List<RouteDefinition> list = camelContext.getRouteDefinitions(); - answer.setRoutes(list); - } - return answer; - } - - /** - * Returns the Graphviz DOT <a - * href="http://camel.apache.org/visualisation.html">Visualisation</a> of - * the current Camel routes - */ - @GET - @Produces(Constants.DOT_MIMETYPE) - public String getDot() throws IOException { - RouteDotGenerator generator = new RouteDotGenerator("/tmp/camel"); - return generator.getRoutesText(getCamelContext()); - } - - /** - * Looks up an individual route - */ - @Path("{id}") - public RouteResource getRoute(@PathParam("id") String id) { - List<RouteDefinition> list = getRouteDefinitions().getRoutes(); - for (RouteDefinition routeType : list) { - if (routeType.getId().equals(id)) { - return new RouteResource(this, routeType); - } - } - return null; - } - - /** - * Looks up an individual route with specified language - */ - @Path("{id}/lang/{language}") - public RouteResource getRoute(@PathParam("id") String id, @PathParam("language") String language) { - RouteResource routeResource = getRoute(id); - if (routeResource != null) { - routeResource.setLanguage(language); - } - return routeResource; - } - - @Path("{id}/status") - public RouteStatusResource getRouteStatus(@PathParam("id") String id) { - RouteResource routeResource = getRoute(id); - return routeResource.getRouteStatus(); - } - - /** - * Creates a new route using form encoded data from a web form - * - * @param language is the edited language used on this route - * @param body the route definition content - */ - @POST - @Consumes("application/x-www-form-urlencoded") - public Response postRouteForm(@Context UriInfo uriInfo, @FormParam("language") String language, - @FormParam("route") String body) throws URISyntaxException { - - LOG.debug("New Route is: {}", body); - - LOG.info(body); - if (body == null) { - error = "No Route submitted!"; - } else if (language.equals(RouteResource.LANGUAGE_XML)) { - return parseXml(body); - } - - error = "Not supported language!"; - return Response.ok(new Viewable("edit", this)).build(); - } - - // Properties - // ------------------------------------------------------------------------- - - public List<Route> getRoutes() { - List<Route> answer = new ArrayList<Route>(); - for (RouteDefinition def : getRouteDefinitions().getRoutes()) { - Route route = new Route(getCamelContext(), def); - answer.add(route); - } - return answer; - } - - public String getError() { - return error; - } - - /** - * process the route configuration defined in Xml - */ - private Response parseXml(String xml) { - try { - JAXBContext context = ((ModelCamelContext)getCamelContext()).getModelJAXBContextFactory().newJAXBContext(); - Unmarshaller unmarshaller = context.createUnmarshaller(); - Object value = unmarshaller.unmarshal(new StringReader(xml)); - if (value instanceof RouteDefinition) { - RouteDefinition routeDefinition = (RouteDefinition)value; - // add the route - ((ModelCamelContext)getCamelContext()).addRouteDefinitions(Collections.singletonList(routeDefinition)); - return Response.seeOther(new URI("/routes")).build(); - } else { - error = "Posted XML is not a route but is of type " + ObjectHelper.className(value); - } - } catch (JAXBException e) { - error = "Failed to parse XML: " + e.getMessage(); - } catch (Exception e) { - error = "Failed to install route: " + e.getMessage(); - } - // lets re-render the form - return Response.ok(new Viewable("create", this)).build(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/CamelOSGIResourceConfig.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/CamelOSGIResourceConfig.java b/components/camel-web/src/main/java/org/apache/camel/web/util/CamelOSGIResourceConfig.java deleted file mode 100644 index 9f4b3e1..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/CamelOSGIResourceConfig.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import java.util.HashMap; -import java.util.Map; -import javax.ws.rs.core.MediaType; - -import com.sun.jersey.api.core.ClassNamesResourceConfig; -import org.apache.camel.web.resources.CamelContextResource; -import org.apache.camel.web.resources.ComponentResource; -import org.apache.camel.web.resources.ComponentsResource; -import org.apache.camel.web.resources.Constants; -import org.apache.camel.web.resources.ConvertersFromResource; -import org.apache.camel.web.resources.ConvertersResource; -import org.apache.camel.web.resources.EndpointResource; -import org.apache.camel.web.resources.EndpointsResource; -import org.apache.camel.web.resources.ExchangeResource; -import org.apache.camel.web.resources.LanguageResource; -import org.apache.camel.web.resources.LanguagesResource; -import org.apache.camel.web.resources.RouteResource; -import org.apache.camel.web.resources.RouteStatusResource; -import org.apache.camel.web.resources.RoutesResource; - -/** - * - */ -public class CamelOSGIResourceConfig extends ClassNamesResourceConfig { - - public CamelOSGIResourceConfig() { - super(createProperties()); - } - - protected static Map<String, Object> createProperties() { - Map<String, Object> properties = new HashMap<String, Object>(); - - String[] resources = new String[] { - CamelContextResource.class.getName(), - ComponentResource.class.getName(), - ComponentsResource.class.getName(), - ConvertersFromResource.class.getName(), - ConvertersResource.class.getName(), - EndpointResource.class.getName(), - EndpointsResource.class.getName(), - ExchangeResource.class.getName(), - LanguageResource.class.getName(), - LanguagesResource.class.getName(), - RouteResource.class.getName(), - RoutesResource.class.getName(), - RouteStatusResource.class.getName(), - JAXBContextResolverOSGI.class.getName(), - JAXBMarshallerResolver.class.getName() - }; - - properties.put(ClassNamesResourceConfig.PROPERTY_CLASSNAMES, resources); - - return properties; - - } - - public Map<String, MediaType> getMediaTypeMappings() { - Map<String, MediaType> m = new HashMap<String, MediaType>(); - m.put("html", MediaType.TEXT_HTML_TYPE); - m.put("xml", MediaType.APPLICATION_XML_TYPE); - m.put("json", MediaType.APPLICATION_JSON_TYPE); - m.put("dot", MediaType.valueOf(Constants.DOT_MIMETYPE)); - return m; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/CamelResourceConfig.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/CamelResourceConfig.java b/components/camel-web/src/main/java/org/apache/camel/web/util/CamelResourceConfig.java deleted file mode 100644 index 9d0a666..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/CamelResourceConfig.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import java.util.HashMap; -import java.util.Map; -import javax.ws.rs.core.MediaType; - -import com.sun.jersey.api.core.PackagesResourceConfig; -import org.apache.camel.web.resources.Constants; - -/** - * - */ -public class CamelResourceConfig extends PackagesResourceConfig { - - public CamelResourceConfig() { - this("org.apache.camel.web"); - } - - public CamelResourceConfig(String packages) { - super(createProperties(packages)); - } - - protected static Map<String, Object> createProperties(String packages) { - Map<String, Object> properties = new HashMap<String, Object>(); - - properties.put(PackagesResourceConfig.PROPERTY_PACKAGES, packages); - -/* - WadlGeneratorConfig config = WadlGeneratorConfig - .generator(WadlGeneratorApplicationDoc.class) - .prop("applicationDocsFile", "classpath:/application-doc.xml") - .generator(WadlGeneratorGrammarsSupport.class) - .prop("grammarsFile", "classpath:/application-grammars.xml") - .generator(WadlGeneratorResourceDocSupport.class) - .prop("resourceDocFile", "classpath:/resourcedoc.xml") - .build(); - - properties.put(ResourceConfig.PROPERTY_WADL_GENERATOR_CONFIG, config); -*/ - return properties; - } - - public Map<String, MediaType> getMediaTypeMappings() { - Map<String, MediaType> m = new HashMap<String, MediaType>(); - m.put("html", MediaType.TEXT_HTML_TYPE); - m.put("xml", MediaType.APPLICATION_XML_TYPE); - m.put("json", MediaType.APPLICATION_JSON_TYPE); - m.put("dot", MediaType.valueOf(Constants.DOT_MIMETYPE)); - return m; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolver.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolver.java b/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolver.java deleted file mode 100644 index 9d1278e..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolver.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; - -/** - * A resolver of the JAXB context primed for the Camel XML languages - * which supports JSON as well as XML encoding - */ -@Provider -public class JAXBContextResolver implements ContextResolver<JAXBContext> { - private final JAXBContext context; - private String packages; - - public JAXBContextResolver() throws Exception { - this(org.apache.camel.web.resources.Constants.JAXB_PACKAGES); - } - - public JAXBContextResolver(String packages) throws JAXBException { - this.packages = packages; - this.context = JAXBContext.newInstance(packages); - } - - public JAXBContext getContext(Class<?> objectType) { - Package aPackage = objectType.getPackage(); - if (aPackage != null) { - String name = aPackage.getName(); - if (name.length() > 0) { - if (packages.contains(name)) { - return context; - } - } - } - return null; - } - - public String getPackages() { - return packages; - } - - public JAXBContext getContext() { - return context; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolverOSGI.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolverOSGI.java b/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolverOSGI.java deleted file mode 100644 index fe1f843..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBContextResolverOSGI.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.JAXBContext; - -import com.sun.jersey.api.json.JSONConfiguration; -import com.sun.jersey.api.json.JSONJAXBContext; - -/** - * A resolver of the JAXB context OSGI primed for the Camel XML languages - * which supports JSON as well as XML encoding - */ -@Provider -public final class JAXBContextResolverOSGI implements ContextResolver<JAXBContext> { - private final JAXBContext context; - private String packages; - - public JAXBContextResolverOSGI() throws Exception { - this.packages = org.apache.camel.web.resources.Constants.JAXB_PACKAGES; - this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), this.packages); - - } - - public JAXBContext getContext(Class<?> objectType) { - Package aPackage = objectType.getPackage(); - if (aPackage != null) { - String name = aPackage.getName(); - if (name.length() > 0) { - if (packages.contains(name)) { - return context; - } - } - } - return null; - } - - public String getPackages() { - return packages; - } - - public JAXBContext getContext() { - return context; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBMarshallerResolver.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBMarshallerResolver.java b/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBMarshallerResolver.java deleted file mode 100644 index e6dd09a..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/JAXBMarshallerResolver.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; - -import com.sun.xml.bind.marshaller.NamespacePrefixMapper; - -/** - * - */ -@Provider -public class JAXBMarshallerResolver implements ContextResolver<Marshaller> { - private JAXBContextResolver contextResolver; - - public JAXBMarshallerResolver() throws Exception { - contextResolver = new JAXBContextResolver(); - } - - public Marshaller getContext(Class<?> aClass) { - try { - JAXBContext context = contextResolver.getContext(); - Marshaller marshaller = context.createMarshaller(); - NamespacePrefixMapper namespaceMapper = new NamespacePrefixMapper() { - - /** - * Returns a preferred prefix for the given namespace URI. - * - * This method is intended to be overrided by a derived class. - * - * @param namespaceUri - * The namespace URI for which the prefix needs to be found. - * Never be null. "" is used to denote the default namespace. - * @param suggestion - * When the content tree has a suggestion for the prefix - * to the given namespaceUri, that suggestion is passed as a - * parameter. Typically this value comes from QName.getPrefix() - * to show the preference of the content tree. This parameter - * may be null, and this parameter may represent an already - * occupied prefix. - * @param requirePrefix - * If this method is expected to return non-empty prefix. - * When this flag is true, it means that the given namespace URI - * cannot be set as the default namespace. - * - * @return - * null if there's no preferred prefix for the namespace URI. - * In this case, the system will generate a prefix for you. - * - * Otherwise the system will try to use the returned prefix, - * but generally there's no guarantee if the prefix will be - * actually used or not. - * - * return "" to map this namespace URI to the default namespace. - * Again, there's no guarantee that this preference will be - * honored. - * - * If this method returns "" when requirePrefix=true, the return - * value will be ignored and the system will generate one. - */ - @Override - public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) { - if (namespaceUri.equals("http://camel.apache.org/schema/web")) { - return "w"; - } else if (namespaceUri.equals("http://camel.apache.org/schema/spring")) { - if (requirePrefix) { - return "c"; - } - return ""; - } else { - return suggestion; - } - } - - }; - marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", namespaceMapper); - return marshaller; - } catch (JAXBException e) { - throw new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/JMXRouteStatistics.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/JMXRouteStatistics.java b/components/camel-web/src/main/java/org/apache/camel/web/util/JMXRouteStatistics.java deleted file mode 100644 index 08628ad..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/JMXRouteStatistics.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import java.text.DateFormat; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import javax.management.MBeanServer; -import javax.management.ObjectName; - -import org.apache.camel.CamelContext; -import org.apache.camel.management.ManagedManagementStrategy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Gathers {@link RouteStatistics} from JMX. - * <p/> - * If JMX is disabled then no statistics can be gathered, and <tt>null</tt> is returned. - */ -public class JMXRouteStatistics implements RouteStatistics { - - private static final Logger LOG = LoggerFactory.getLogger(JMXRouteStatistics.class); - - public Object getRouteStatistic(CamelContext camelContext, String routeID, String attribute) { - // only possible if JMX is enabled - if (!(camelContext.getManagementStrategy() instanceof ManagedManagementStrategy)) { - return null; - } - - try { - MBeanServer server = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer(); - String domain = camelContext.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName(); - - ObjectName objName = new ObjectName(domain + ":type=routes,*"); - List<ObjectName> cacheList = new LinkedList<ObjectName>(server.queryNames(objName, null)); - for (Iterator<ObjectName> iter = cacheList.iterator(); iter.hasNext();) { - objName = iter.next(); - String keyProps = objName.getCanonicalKeyPropertyListString(); - ObjectName objectInfoName = new ObjectName(domain + ":" + keyProps); - String currentRouteID = (String) server.getAttribute(objectInfoName, "RouteId"); - if (currentRouteID.equals(routeID)) { - Object value = server.getAttribute(objectInfoName, attribute); - if (value instanceof Date) { - DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - return df.format(value); - } else { - return value; - } - } - } - } catch (Exception e) { - LOG.warn("Error getting route statistic from JMX. This exception will be ignored.", e); - } - - return null; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/RouteStatistics.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/RouteStatistics.java b/components/camel-web/src/main/java/org/apache/camel/web/util/RouteStatistics.java deleted file mode 100644 index f3cf9cf..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/RouteStatistics.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import org.apache.camel.CamelContext; - -/** - * - */ -public interface RouteStatistics { - - /** - * Gets statistic for the given route - * - * @param camelContext the context in question - * @param routeID the routeID to retrieve stats for - * @param attribute the attribute to retrieve - * @return the statistic, or <tt>null</tt> if not possible to find or get the statistic - */ - Object getRouteStatistic(CamelContext camelContext, String routeID, String attribute); -} http://git-wip-us.apache.org/repos/asf/camel/blob/9f5e32db/components/camel-web/src/main/java/org/apache/camel/web/util/UriCharactersEncoder.java ---------------------------------------------------------------------- diff --git a/components/camel-web/src/main/java/org/apache/camel/web/util/UriCharactersEncoder.java b/components/camel-web/src/main/java/org/apache/camel/web/util/UriCharactersEncoder.java deleted file mode 100644 index 9db6b1c..0000000 --- a/components/camel-web/src/main/java/org/apache/camel/web/util/UriCharactersEncoder.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.web.util; - -import java.util.BitSet; - -public final class UriCharactersEncoder { - private static BitSet unsafeCharacters; - private static final char[] HEX_DIGITS = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - static { - unsafeCharacters = new BitSet(256); - unsafeCharacters.set(' '); - unsafeCharacters.set('"'); - unsafeCharacters.set('<'); - unsafeCharacters.set('>'); - unsafeCharacters.set('#'); - unsafeCharacters.set('%'); - unsafeCharacters.set('{'); - unsafeCharacters.set('}'); - unsafeCharacters.set('|'); - unsafeCharacters.set('\\'); - unsafeCharacters.set('^'); - unsafeCharacters.set('~'); - unsafeCharacters.set('['); - unsafeCharacters.set(']'); - unsafeCharacters.set('`'); - unsafeCharacters.set('/'); - unsafeCharacters.set('$'); - } - - private UriCharactersEncoder() { - // util class - } - - public static String encode(String s) { - int n = s.length(); - if (n == 0) { - return s; - } - - // First check whether we actually need to encode - char chars[] = s.toCharArray(); - for (int i = 0;;) { - // just deal with the ascii character - if (chars[i] > 0 && chars[i] < 128) { - if (unsafeCharacters.get(chars[i])) { - break; - } - } - if (++i >= chars.length) { - return s; - } - } - - // okay there are some unsafe characters so we do need to encode - StringBuilder sb = new StringBuilder(); - for (char ch : chars) { - if (ch > 0 && ch < 128 && unsafeCharacters.get(ch)) { - appendEscape(sb, (byte)ch); - } else { - sb.append(ch); - } - } - return sb.toString(); - } - - private static void appendEscape(StringBuilder sb, byte b) { - sb.append('%'); - sb.append(HEX_DIGITS[(b >> 4) & 0x0f]); - sb.append(HEX_DIGITS[(b >> 0) & 0x0f]); - } - -}