You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/03/22 16:56:44 UTC
[1/8] camel git commit: CAMEL-9737 - Create camel component for
ServiceNow
Repository: camel
Updated Branches:
refs/heads/camel-2.17.x 7a00489d1 -> f78935eee
refs/heads/master 1f9dc80da -> 07b489872
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java
new file mode 100644
index 0000000..f8651a1
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java
@@ -0,0 +1,286 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.List;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.servicenow.model.Incident;
+import org.junit.Test;
+
+public class ServiceNowTableTest extends ServiceNowTestSupport {
+
+ @Test
+ public void testRetrieveSome() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:servicenow");
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_LIMIT, "10")
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ Exchange exchange = mock.getExchanges().get(0);
+ List<Incident> items = exchange.getIn().getBody(List.class);
+
+ assertNotNull(items);
+ assertTrue(items.size() <= 10);
+ }
+
+ @Test
+ public void testIncidentWorkflow() throws Exception {
+
+ Incident incident = null;
+ String sysId;
+ String number;
+ MockEndpoint mock = getMockEndpoint("mock:servicenow");
+
+ // ************************
+ // Create incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ incident = new Incident();
+ incident.setDescription("my incident");
+ incident.setShortDescription("An incident");
+ incident.setSeverity(1);
+ incident.setImpact(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ incident,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ sysId = incident.getId();
+ number = incident.getNumber();
+
+ LOGGER.info("****************************************************");
+ LOGGER.info("* Incident created");
+ LOGGER.info("* sysid = {}", sysId);
+ LOGGER.info("* number = {}", number);
+ LOGGER.info("****************************************************");
+ }
+
+ // ************************
+ // Search for the incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, incidents.size());
+ assertEquals(number, incidents.get(0).getNumber());
+ assertEquals(sysId, incidents.get(0).getId());
+ }
+
+ // ************************
+ // Modify the incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ incident = new Incident();
+ incident.setDescription("my incident");
+ incident.setShortDescription("The incident");
+ incident.setSeverity(2);
+ incident.setImpact(3);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ incident,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_MODIFY)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ assertEquals(number, incident.getNumber());
+ assertEquals(2, incident.getSeverity());
+ assertEquals(3, incident.getImpact());
+ assertEquals("The incident", incident.getShortDescription());
+ }
+
+ // ************************
+ // Retrieve it via query
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, incidents.size());
+ assertEquals(number, incidents.get(0).getNumber());
+ assertEquals(sysId, incidents.get(0).getId());
+ assertEquals(2, incidents.get(0).getSeverity());
+ assertEquals(3, incidents.get(0).getImpact());
+ assertEquals("The incident", incidents.get(0).getShortDescription());
+ }
+
+ // ************************
+ // Retrieve by sys id
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ assertEquals(2, incident.getSeverity());
+ assertEquals(3, incident.getImpact());
+ assertEquals("The incident", incident.getShortDescription());
+ assertEquals(number, incident.getNumber());
+ }
+
+ // ************************
+ // Delete it
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+ }
+
+ // ************************
+ // Retrieve it via query, should fail
+ // ************************
+
+ {
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ fail("Record +" + number + " should have been deleted");
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+ // we are good
+ }
+ }
+ }
+
+ // *************************************************************************
+ //
+ // *************************************************************************
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:servicenow")
+ .to("servicenow:{{env:SERVICENOW_INSTANCE}}"
+ + "?userName={{env:SERVICENOW_USERNAME}}"
+ + "&password={{env:SERVICENOW_PASSWORD}}"
+ //+ "&oauthClientId={{env:SERVICENOW_OAUTH2_CLIENT_ID}}"
+ //+ "&oauthClientSecret={{env:SERVICENOW_OAUTH2_CLIENT_SECRET}}"
+ + "&model.incident=org.apache.camel.component.servicenow.model.Incident")
+ .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true")
+ .to("mock:servicenow");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
new file mode 100644
index 0000000..2b4730a
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
@@ -0,0 +1,112 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.UUID;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ServiceNowTest extends ServiceNowTestSupport {
+
+ @Test
+ public void testExceptions() throws Exception {
+ // 404
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString())
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+
+ ServiceNowException sne = (ServiceNowException)e.getCause();
+ assertEquals("failure", sne.getStatus());
+ assertTrue(sne.getMessage().contains("No Record found"));
+ assertTrue(sne.getDetail().contains("Records matching query not found"));
+ }
+
+ // 400
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString())
+ .put(ServiceNowConstants.TABLE, "notExistingTable")
+ .build()
+ );
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+
+ ServiceNowException sne = (ServiceNowException)e.getCause();
+ assertEquals("failure", sne.getStatus());
+ assertTrue(sne.getMessage().contains("Invalid table notExistingTable"));
+ assertNull(sne.getDetail());
+ }
+ }
+
+ @Test
+ public void testBodyMismatch() throws Exception {
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ "NotAnIncidentObject",
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ fail("Should fail as body is not compatible with model defined in route for table incident");
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ }
+ }
+
+ // *************************************************************************
+ //
+ // *************************************************************************
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:servicenow")
+ .to("servicenow:{{env:SERVICENOW_INSTANCE}}"
+ + "?userName={{env:SERVICENOW_USERNAME}}"
+ + "&password={{env:SERVICENOW_PASSWORD}}"
+ //+ "&oauthClientId={{env:SERVICENOW_OAUTH2_CLIENT_ID}}"
+ //+ "&oauthClientSecret={{env:SERVICENOW_OAUTH2_CLIENT_SECRET}}"
+ + "&model.incident=org.apache.camel.component.servicenow.model.Incident")
+ .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true")
+ .to("mock:servicenow");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java
new file mode 100644
index 0000000..706fb22
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java
@@ -0,0 +1,61 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class ServiceNowTestSupport extends CamelTestSupport {
+
+ protected static final Logger LOGGER = LoggerFactory.getLogger(ServiceNowTestSupport.class);
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ return super.createCamelContext();
+ }
+
+ protected static class KVBuilder {
+ private final Map<String, Object> headers;
+
+ public KVBuilder() {
+ this(new HashMap<String, Object>());
+ }
+
+ private KVBuilder(Map<String, Object> headers) {
+ this.headers = headers;
+ }
+
+ public KVBuilder on(Map<String, Object> headers) {
+ return new KVBuilder(headers);
+ }
+
+ public KVBuilder put(String key, Object val) {
+ headers.put(key, val);
+ return this;
+ }
+
+ public Map<String, Object> build() {
+ return Collections.unmodifiableMap(this.headers);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java
new file mode 100644
index 0000000..54c8904
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java
@@ -0,0 +1,96 @@
+/**
+ * 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.component.servicenow.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Incident {
+ @JsonProperty("sys_id")
+ private String id;
+
+ @JsonProperty("number")
+ private String number;
+
+ @JsonProperty("description")
+ private String description;
+
+ @JsonProperty("short_description")
+ private String shortDescription;
+
+ @JsonProperty("severity")
+ private int severity;
+
+ @JsonProperty("impact")
+ private int impact;
+
+
+ public Incident() {
+ }
+
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getShortDescription() {
+ return shortDescription;
+ }
+
+ public void setShortDescription(String shortDescription) {
+ this.shortDescription = shortDescription;
+ }
+
+ public int getSeverity() {
+ return severity;
+ }
+
+ public void setSeverity(int severity) {
+ this.severity = severity;
+ }
+
+ public int getImpact() {
+ return impact;
+ }
+
+ public void setImpact(int impact) {
+ this.impact = impact;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/resources/log4j.properties b/components/camel-servicenow/src/test/resources/log4j.properties
new file mode 100644
index 0000000..74c76b7
--- /dev/null
+++ b/components/camel-servicenow/src/test/resources/log4j.properties
@@ -0,0 +1,19 @@
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, file
+
+# uncomment the following line to turn on Camel debugging
+log4j.logger.org.apache.camel.component.servicenow=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d{HH:mm:ss.SSS} [%-15.15t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-servicenow-test.log
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index c55d74f..22366b2 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -211,6 +211,7 @@
<module>camel-schematron</module>
<module>camel-scr</module>
<module>camel-script</module>
+ <module>camel-servicenow</module>
<module>camel-servlet</module>
<module>camel-servletlistener</module>
<module>camel-shiro</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 4e6e388..b38a7bf 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1509,6 +1509,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-servicenow</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index ac7ab20..8eebef6 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1379,6 +1379,18 @@
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.rhino/${rhino-bundle-version}</bundle>
<bundle>mvn:org.apache.camel/camel-script/${project.version}</bundle>
</feature>
+ <feature name='camel-servicenow' version='${project.version}' resolver='(obr)' start-level='50'>
+ <feature version='${project.version}'>camel-core</feature>
+ <feature version='${cxf-version-range}'>cxf-core</feature>
+ <feature version='${cxf-version-range}'>cxf-jaxrs</feature>
+ <feature version='${cxf-version-range}'>cxf-rs-security-oauth2</feature>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-core/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/${jackson2-version}</bundle>
+ <bundle dependency='true'>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/${jackson2-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-servicenow/${project.version}</bundle>
+ </feature>
<feature name='camel-servlet' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<feature>http</feature>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelServicenowTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelServicenowTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelServicenowTest.java
new file mode 100644
index 0000000..f275161
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelServicenowTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelServicenowTest extends AbstractFeatureTest {
+
+ public static final String COMPONENT = extractName(CamelServicenowTest.class);
+
+ @Test
+ public void test() throws Exception {
+ testComponent(COMPONENT);
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ return configure(COMPONENT);
+ }
+
+}
\ No newline at end of file
[4/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b8dec7aa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b8dec7aa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b8dec7aa
Branch: refs/heads/master
Commit: b8dec7aab39dd5b0fcf8aa65473a9fea9c9e86dd
Parents: 1c76b49
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:48:36 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:48:36 2016 +0100
----------------------------------------------------------------------
.../org/apache/camel/component/servicenow/ServiceNowEndpoint.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b8dec7aa/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
index d7f4375..ebb0229 100644
--- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
@@ -33,7 +33,7 @@ import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
/**
* Represents a ServiceNow endpoint.
*/
-@UriEndpoint(scheme = "servicenow", title = "ServiceNow", syntax = "servicenow:instanceName", consumerClass = ServiceNowConsumer.class, label = "ServiceNow")
+@UriEndpoint(scheme = "servicenow", title = "ServiceNow", syntax = "servicenow:instanceName", consumerClass = ServiceNowConsumer.class, label = "api,cloud,management")
public class ServiceNowEndpoint extends DefaultEndpoint {
@UriPath(description = "The ServiceNow instance name ")
[7/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7dc24fa9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7dc24fa9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7dc24fa9
Branch: refs/heads/camel-2.17.x
Commit: 7dc24fa99c5965dd5a36ae0ac44ea9abafe568fc
Parents: 7a00489
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:48:30 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:56:22 2016 +0100
----------------------------------------------------------------------
.../component/braintree/BraintreeComponent.java | 2 ++
.../braintree/BraintreeConfiguration.java | 30 ++++++++++++++++++++
.../component/braintree/BraintreeEndpoint.java | 14 ++++-----
3 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc24fa9/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
index 5b468cc..8918771 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
@@ -49,6 +49,8 @@ public class BraintreeComponent extends AbstractApiComponent<BraintreeApiName, B
@Override
protected Endpoint createEndpoint(String uri, String methodName, BraintreeApiName apiName, BraintreeConfiguration endpointConfiguration) {
+ endpointConfiguration.setApiName(apiName);
+ endpointConfiguration.setMethodName(methodName);
return new BraintreeEndpoint(uri, this, apiName, methodName, endpointConfiguration, getGateway(endpointConfiguration));
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc24fa9/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
index e366c2c..4376a9e 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
@@ -18,9 +18,11 @@ package org.apache.camel.component.braintree;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.Environment;
+import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
import org.apache.camel.util.ObjectHelper;
/**
@@ -33,6 +35,12 @@ public class BraintreeConfiguration {
private static final String PUBLIC_KEY = "public_key";
private static final String PRIVATE_KEY = "private_key";
+ @UriPath
+ @Metadata(required = "true")
+ private BraintreeApiName apiName;
+ @UriPath @Metadata(required = "true")
+ private String methodName;
+
@UriParam
@Metadata(required = "true")
private String environment;
@@ -57,6 +65,28 @@ public class BraintreeConfiguration {
@Metadata(label = "proxy")
private Integer proxyPort;
+ public BraintreeApiName getApiName() {
+ return apiName;
+ }
+
+ /**
+ * What kind of operation to perform
+ */
+ public void setApiName(BraintreeApiName apiName) {
+ this.apiName = apiName;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ /**
+ * What sub operation to use for the selected operation
+ */
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
public String getEnvironment() {
return ObjectHelper.notNull(environment, ENVIRONMENT);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc24fa9/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
index 5df6301..0c2af85 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
@@ -29,6 +29,7 @@ import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.component.braintree.internal.BraintreeConstants;
import org.apache.camel.component.braintree.internal.BraintreePropertiesHelper;
import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.camel.util.component.AbstractApiEndpoint;
import org.apache.camel.util.component.ApiMethod;
@@ -37,21 +38,20 @@ import org.apache.camel.util.component.ApiMethodPropertiesHelper;
/**
* The braintree component is used for integrating with the Braintree Payment System.
*/
-@UriEndpoint(scheme = "braintree", title = "Braintree", syntax = "braintree:name", consumerClass = BraintreeConsumer.class, label = "Braintree")
+@UriEndpoint(scheme = "braintree", title = "Braintree", syntax = "braintree:name", consumerClass = BraintreeConsumer.class, label = "api,cloud,payment")
public class BraintreeEndpoint extends AbstractApiEndpoint<BraintreeApiName, BraintreeConfiguration> {
- @UriPath(description = "the method name")
- private final String name;
+ @UriParam
+ private final BraintreeConfiguration configuration;
private Object apiProxy;
private final BraintreeGateway gateway;
public BraintreeEndpoint(String uri, BraintreeComponent component,
- BraintreeApiName apiName, String methodName, BraintreeConfiguration endpointConfiguration, BraintreeGateway gateway) {
- super(uri, component, apiName, methodName, BraintreeApiCollection.getCollection().getHelper(apiName), endpointConfiguration);
-
+ BraintreeApiName apiName, String methodName, BraintreeConfiguration configuration, BraintreeGateway gateway) {
+ super(uri, component, apiName, methodName, BraintreeApiCollection.getCollection().getHelper(apiName), configuration);
+ this.configuration = configuration;
this.gateway = gateway;
- this.name = methodName;
}
@Override
[6/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/07b48987
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/07b48987
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/07b48987
Branch: refs/heads/master
Commit: 07b4898727281d5df21983022f5feb04cfbdc1d4
Parents: 3ef6e4d
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:55:55 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:55:55 2016 +0100
----------------------------------------------------------------------
.../servicenow/ServiceNowConfiguration.java | 20 +++++++--------
.../servicenow/ServiceNowConsumer.java | 26 --------------------
.../servicenow/ServiceNowEndpoint.java | 8 +++---
3 files changed, 15 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/07b48987/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
index 755e49f..9c0b424 100644
--- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
@@ -22,11 +22,11 @@ import java.util.Map;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.util.ObjectHelper;
-
@UriParams
public class ServiceNowConfiguration {
@@ -38,27 +38,27 @@ public class ServiceNowConfiguration {
JsonInclude.Include.NON_NULL
);
- @UriParam
+ @UriParam @Metadata(required = "true")
private String userName;
- @UriParam
+ @UriParam @Metadata(required = "true")
private String password;
- @UriParam
+ @UriParam(label = "security")
private String oauthClientId;
- @UriParam
+ @UriParam(label = "security")
private String oauthClientSecret;
- @UriParam(label = "advanced")
+ @UriParam(label = "security")
private String oauthTokenUrl;
@UriParam(label = "advanced")
private String apiUrl;
@UriParam
private String table;
- @UriParam(defaultValue = "false")
+ @UriParam
private Boolean excludeReferenceLink = false;
- @UriParam(defaultValue = "false")
+ @UriParam
private Boolean suppressAutoSysField = false;
- @UriParam(defaultValue = "false")
+ @UriParam(defaultValue = "false", enums = "false,true,all")
private String displayValue = "false";
- @UriParam(defaultValue = "false")
+ @UriParam
private Boolean inputDisplayValue = false;
@UriParam(prefix = "model.", multiValue = true, javaType = "java.lang.String")
private Map<String, Class<?>> models;
http://git-wip-us.apache.org/repos/asf/camel/blob/07b48987/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
deleted file mode 100644
index b841ba3..0000000
--- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
+++ /dev/null
@@ -1,26 +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.component.servicenow;
-
-import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
-
-public class ServiceNowConsumer extends DefaultConsumer {
- public ServiceNowConsumer(ServiceNowEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/07b48987/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
index ebb0229..2fa39a7 100644
--- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
@@ -27,19 +27,21 @@ import org.apache.camel.component.servicenow.auth.OAuthToken;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
/**
* Represents a ServiceNow endpoint.
*/
-@UriEndpoint(scheme = "servicenow", title = "ServiceNow", syntax = "servicenow:instanceName", consumerClass = ServiceNowConsumer.class, label = "api,cloud,management")
+@UriEndpoint(scheme = "servicenow", title = "ServiceNow", syntax = "servicenow:instanceName", producerOnly = true, label = "api,cloud,management")
public class ServiceNowEndpoint extends DefaultEndpoint {
@UriPath(description = "The ServiceNow instance name ")
@Metadata(required = "true")
private final String instanceName;
+ @UriParam
private final ServiceNowConfiguration configuration;
private final String apiUrl;
private final String oauthUrl;
@@ -70,12 +72,12 @@ public class ServiceNowEndpoint extends DefaultEndpoint {
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- throw new UnsupportedOperationException("Consumer interface is not supported");
+ throw new UnsupportedOperationException("Consumer is not supported");
}
@Override
public boolean isSingleton() {
- return false;
+ return true;
}
public ServiceNowConfiguration getConfiguration() {
[2/8] camel git commit: CAMEL-9737 - Create camel component for
ServiceNow
Posted by da...@apache.org.
CAMEL-9737 - Create camel component for ServiceNow
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/aa7ca432
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aa7ca432
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aa7ca432
Branch: refs/heads/master
Commit: aa7ca432d6b2f838edd5b9e4811c83a971051ed4
Parents: 1f9dc80
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 22 10:21:59 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:36:41 2016 +0100
----------------------------------------------------------------------
apache-camel/pom.xml | 4 +
.../src/main/descriptors/common-bin.xml | 1 +
components/camel-servicenow/pom.xml | 162 +++++++++++
.../servicenow/ServiceNowComponent.java | 52 ++++
.../servicenow/ServiceNowConfiguration.java | 258 +++++++++++++++++
.../servicenow/ServiceNowConstants.java | 52 ++++
.../servicenow/ServiceNowConsumer.java | 26 ++
.../servicenow/ServiceNowEndpoint.java | 100 +++++++
.../servicenow/ServiceNowException.java | 59 ++++
.../servicenow/ServiceNowExceptionMapper.java | 59 ++++
.../servicenow/ServiceNowProducer.java | 103 +++++++
.../servicenow/ServiceNowProducerProcessor.java | 139 +++++++++
.../auth/AuthenticationRequestFilter.java | 61 ++++
.../component/servicenow/auth/OAuthToken.java | 109 +++++++
.../servicenow/model/ServiceNowAggregate.java | 50 ++++
.../model/ServiceNowAggregateProcessor.java | 68 +++++
.../servicenow/model/ServiceNowImportSet.java | 48 ++++
.../model/ServiceNowImportSetProcessor.java | 79 +++++
.../servicenow/model/ServiceNowTable.java | 108 +++++++
.../model/ServiceNowTableProcessor.java | 169 +++++++++++
.../org/apache/camel/component/servicenow | 1 +
.../servicenow/ServiceNowTableTest.java | 286 +++++++++++++++++++
.../component/servicenow/ServiceNowTest.java | 112 ++++++++
.../servicenow/ServiceNowTestSupport.java | 61 ++++
.../component/servicenow/model/Incident.java | 96 +++++++
.../src/test/resources/log4j.properties | 19 ++
components/pom.xml | 1 +
parent/pom.xml | 5 +
.../features/src/main/resources/features.xml | 12 +
.../camel/itest/karaf/CamelServicenowTest.java | 40 +++
30 files changed, 2340 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index 4553726..766cbc6 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -716,6 +716,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-servicenow</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index c797dff..1439828 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -190,6 +190,7 @@
<include>org.apache.camel:camel-schematron</include>
<include>org.apache.camel:camel-scr</include>
<include>org.apache.camel:camel-script</include>
+ <include>org.apache.camel:camel-servicenow</include>
<include>org.apache.camel:camel-servlet</include>
<include>org.apache.camel:camel-servletlistener</include>
<include>org.apache.camel:camel-shiro</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/pom.xml b/components/camel-servicenow/pom.xml
new file mode 100644
index 0000000..8ea683e
--- /dev/null
+++ b/components/camel-servicenow/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.18-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-servicenow</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: ServiceNow</name>
+ <description>Camel ServiceNow support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.servicenow.*
+ </camel.osgi.export.pkg>
+ <camel.osgi.export.service>
+ org.apache.camel.spi.ComponentResolver;component=servicenow
+ </camel.osgi.export.service>
+ </properties>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <!-- CXF -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-core</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-security-oauth2</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-extension-providers</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+
+ <!-- Jackson -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>${mockito-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ <version>${hamcrest-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>servicenow-tests</id>
+ <activation>
+ <property>
+ <name>env.SERVICENOW_INSTANCE</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>false</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowComponent.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowComponent.java
new file mode 100644
index 0000000..30135c9
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowComponent.java
@@ -0,0 +1,52 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.IntrospectionSupport;
+
+/**
+ * Represents the component that manages {@link ServiceNowEndpoint}.
+ */
+public class ServiceNowComponent extends UriEndpointComponent {
+
+ public ServiceNowComponent() {
+ super(ServiceNowEndpoint.class);
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ final CamelContext context = getCamelContext();
+ final ServiceNowConfiguration configuration = new ServiceNowConfiguration();
+
+ Map<String, Object> models = IntrospectionSupport.extractProperties(parameters, "model.");
+ for (Map.Entry<String, Object> entry : models.entrySet()) {
+ configuration.addModel(
+ entry.getKey(),
+ EndpointHelper.resolveParameter(context, (String)entry.getValue(), Class.class));
+ }
+
+ setProperties(configuration, parameters);
+
+ return new ServiceNowEndpoint(uri, this, configuration, remaining);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
new file mode 100644
index 0000000..755e49f
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConfiguration.java
@@ -0,0 +1,258 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.util.ObjectHelper;
+
+
+@UriParams
+public class ServiceNowConfiguration {
+
+ private static final ObjectMapper MAPPER = new ObjectMapper()
+ .configure(
+ DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
+ false)
+ .setSerializationInclusion(
+ JsonInclude.Include.NON_NULL
+ );
+
+ @UriParam
+ private String userName;
+ @UriParam
+ private String password;
+ @UriParam
+ private String oauthClientId;
+ @UriParam
+ private String oauthClientSecret;
+ @UriParam(label = "advanced")
+ private String oauthTokenUrl;
+ @UriParam(label = "advanced")
+ private String apiUrl;
+ @UriParam
+ private String table;
+ @UriParam(defaultValue = "false")
+ private Boolean excludeReferenceLink = false;
+ @UriParam(defaultValue = "false")
+ private Boolean suppressAutoSysField = false;
+ @UriParam(defaultValue = "false")
+ private String displayValue = "false";
+ @UriParam(defaultValue = "false")
+ private Boolean inputDisplayValue = false;
+ @UriParam(prefix = "model.", multiValue = true, javaType = "java.lang.String")
+ private Map<String, Class<?>> models;
+ @UriParam(label = "advanced")
+ private ObjectMapper mapper = MAPPER;
+
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getApiUrl() {
+ return apiUrl;
+ }
+
+ /**
+ * The ServiceNow REST API url
+ */
+ public void setApiUrl(String apiUrl) {
+ this.apiUrl = apiUrl;
+ }
+
+ public boolean hasApiUrl() {
+ return apiUrl != null;
+ }
+
+ /**
+ * ServiceNow user account name, MUST be provided
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * ServiceNow account password, MUST be provided
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getOauthClientId() {
+ return oauthClientId;
+ }
+
+ /**
+ * OAuth2 ClientID
+ */
+ public void setOauthClientId(String oauthClientId) {
+ this.oauthClientId = oauthClientId;
+ }
+
+ public String getOauthClientSecret() {
+ return oauthClientSecret;
+ }
+
+ /**
+ * OAuth2 ClientSecret
+ */
+ public void setOauthClientSecret(String oauthClientSecret) {
+ this.oauthClientSecret = oauthClientSecret;
+ }
+
+ public String getOauthTokenUrl() {
+ return oauthTokenUrl;
+ }
+
+ public boolean hasOautTokenUrl() {
+ return oauthTokenUrl != null;
+ }
+
+ /**
+ * OAuth token Url
+ */
+ public void setOauthTokenUrl(String oauthTokenUrl) {
+ this.oauthTokenUrl = oauthTokenUrl;
+ }
+
+ public boolean hasBasicAuthentication() {
+ return ObjectHelper.isNotEmpty(userName)
+ && ObjectHelper.isNotEmpty(password);
+ }
+
+ public boolean hasOAuthAuthentication() {
+ return ObjectHelper.isNotEmpty(userName)
+ && ObjectHelper.isNotEmpty(password)
+ && ObjectHelper.isNotEmpty(oauthClientId)
+ && ObjectHelper.isNotEmpty(oauthClientSecret);
+ }
+
+ public String getTable() {
+ return table;
+ }
+
+ /**
+ * The default table, can be overridden by header CamelServiceNowTable
+ */
+ public void setTable(String table) {
+ this.table = table;
+ }
+
+ public Boolean getExcludeReferenceLink() {
+ return excludeReferenceLink;
+ }
+
+ /**
+ * True to exclude Table API links for reference fields (default: false)
+ */
+ public void setExcludeReferenceLink(Boolean excludeReferenceLink) {
+ this.excludeReferenceLink = excludeReferenceLink;
+ }
+
+ public Boolean getSuppressAutoSysField() {
+ return suppressAutoSysField;
+ }
+
+ /**
+ * True to suppress auto generation of system fields (default: false)
+ */
+ public void setSuppressAutoSysField(Boolean suppressAutoSysField) {
+ this.suppressAutoSysField = suppressAutoSysField;
+ }
+
+ public String getDisplayValue() {
+ return displayValue;
+ }
+
+ /**
+ * Return the display value (true), actual value (false), or both (all) for
+ * reference fields (default: false)
+ */
+ public void setDisplayValue(String displayValue) {
+ this.displayValue = displayValue;
+ }
+
+ public Boolean getInputDisplayValue() {
+ return inputDisplayValue;
+ }
+
+ /**
+ * True to set raw value of input fields (default: false)
+ */
+ public void setInputDisplayValue(Boolean inputDisplayValue) {
+ this.inputDisplayValue = inputDisplayValue;
+ }
+
+ public Map<String, Class<?>> getModels() {
+ return models;
+ }
+
+ /**
+ * Defines the default model to use for a table
+ */
+ public void setModels(Map<String, Class<?>> models) {
+ this.models = models;
+ }
+
+ public void addModel(String name, Class<?> type) {
+ if (this.models == null) {
+ this.models = new HashMap<>();
+ }
+
+ this.models.put(name, type);
+ }
+
+ public Class<?> getModel(String name) {
+ return getModel(name, null);
+ }
+
+ public Class<?> getModel(String name, Class<?> defaultType) {
+ Class<?> model = defaultType;
+
+ if (this.models != null && this.models.containsKey(name)) {
+ model = this.models.get(name);
+ }
+
+ return model;
+ }
+
+ /**
+ * Sets Jackson's ObjectMapper to use for request/reply
+ */
+ public void setMapper(ObjectMapper mapper) {
+ this.mapper = mapper;
+ }
+
+ public ObjectMapper getMapper() {
+ return mapper;
+ }
+
+ public boolean hasMapper() {
+ return mapper != null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
new file mode 100644
index 0000000..3dfb20e
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
@@ -0,0 +1,52 @@
+/**
+ * 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.component.servicenow;
+
+public interface ServiceNowConstants {
+ String RESOURCE = "CamelServiceNowResource";
+ String TABLE = "CamelServiceNowTable";
+ String ACTION = "CamelServiceNowAction";
+ String MODEL = "CamelServiceNowModel";
+
+ String RESOURCE_TABLE = "table";
+ String RESOURCE_AGGREGATE = "aggregate";
+ String RESOURCE_IMPORT = "aggregate";
+
+ String ACTION_RETRIEVE = "retrieve";
+ String ACTION_CREATE = "create";
+ String ACTION_MODIFY = "modify";
+ String ACTION_DELETE = "delete";
+ String ACTION_UPDATE = "update";
+
+ String SYSPARM_ID = "CamelServiceNowSysId";
+ String SYSPARM_QUERY = "CamelServiceNowQuery";
+ String SYSPARM_DISPLAY_VALUE = "CamelServiceNowDisplayValue";
+ String SYSPARM_INPUT_DISPLAY_VALUE = "CamelServiceNowInputDisplayValue";
+ String SYSPARM_EXCLUDE_REFERENCE_LINK = "CamelServiceNowExcludeReferenceLink";
+ String SYSPARM_FIELDS = "CamelServiceNowFields";
+ String SYSPARM_MIN_FIELDS = "CamelServiceNowMinFields";
+ String SYSPARM_MAX_FIELDS = "CamelServiceNowMaxFields";
+ String SYSPARM_SUM_FIELDS = "CamelServiceNowSumFields";
+ String SYSPARM_LIMIT = "CamelServiceNowLimit";
+ String SYSPARM_VIEW = "CamelServiceNowView";
+ String SYSPARM_SUPPRESS_AUTO_SYS_FIELD = "CamelServiceNowSuppressAutoSysField";
+ String SYSPARM_AVG_FIELDS = "CamelServiceNowAvgFields";
+ String SYSPARM_COUNT = "CamelServiceNowCount";
+ String SYSPARM_GROUP_BY = "CamelServiceGroupBy";
+ String SYSPARM_ORDER_BY = "CamelServiceOrderBy";
+ String SYSPARM_HAVING = "CamelServiceHaving";
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
new file mode 100644
index 0000000..b841ba3
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConsumer.java
@@ -0,0 +1,26 @@
+/**
+ * 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.component.servicenow;
+
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+public class ServiceNowConsumer extends DefaultConsumer {
+ public ServiceNowConsumer(ServiceNowEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
new file mode 100644
index 0000000..d7f4375
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowEndpoint.java
@@ -0,0 +1,100 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.Arrays;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.servicenow.auth.AuthenticationRequestFilter;
+import org.apache.camel.component.servicenow.auth.OAuthToken;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriPath;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+
+/**
+ * Represents a ServiceNow endpoint.
+ */
+@UriEndpoint(scheme = "servicenow", title = "ServiceNow", syntax = "servicenow:instanceName", consumerClass = ServiceNowConsumer.class, label = "ServiceNow")
+public class ServiceNowEndpoint extends DefaultEndpoint {
+
+ @UriPath(description = "The ServiceNow instance name ")
+ @Metadata(required = "true")
+ private final String instanceName;
+
+ private final ServiceNowConfiguration configuration;
+ private final String apiUrl;
+ private final String oauthUrl;
+ private final OAuthToken token;
+
+ public ServiceNowEndpoint(String uri, ServiceNowComponent component, ServiceNowConfiguration configuration, String instanceName) throws Exception {
+ super(uri, component);
+
+ this.configuration = configuration;
+ this.instanceName = component.getCamelContext().resolvePropertyPlaceholders(instanceName);
+
+ this.apiUrl = configuration.hasApiUrl()
+ ? configuration.getApiUrl()
+ : String.format("https://%s.service-now.com/api/now", instanceName);
+ this.oauthUrl = configuration.hasOautTokenUrl()
+ ? configuration.getOauthTokenUrl()
+ : String.format("https://%s.service-now.com/oauth_token.do", instanceName);
+
+ this.token = configuration.hasOAuthAuthentication()
+ ? new OAuthToken(this.oauthUrl, this.configuration)
+ : null;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new ServiceNowProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Consumer interface is not supported");
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public ServiceNowConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public String getInstanceName() {
+ return instanceName;
+ }
+
+ public <T> T createClient(Class<T> type) throws Exception {
+ return JAXRSClientFactory.create(
+ apiUrl,
+ type,
+ Arrays.asList(
+ new AuthenticationRequestFilter(configuration, token),
+ new JacksonJsonProvider(configuration.getMapper()),
+ new ServiceNowExceptionMapper(configuration.getMapper())
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowException.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowException.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowException.java
new file mode 100644
index 0000000..cb1ce8b
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowException.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.camel.CamelException;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ServiceNowException extends CamelException {
+ private final String status;
+ private final String detail;
+
+ public ServiceNowException(
+ @JsonProperty("status") String status,
+ @JsonProperty("error") Map<String, String> error) {
+ super(error.get("message"));
+ this.status = status;
+ this.detail = error.get("detail");
+ }
+
+ public ServiceNowException(Throwable cause) {
+ super(cause);
+
+ this.status = null;
+ this.detail = null;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public String getDetail() {
+ return detail;
+ }
+
+ @Override
+ public String toString() {
+ return getMessage() != null
+ ? "" + this.status + ": " + getMessage()
+ : super.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowExceptionMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowExceptionMapper.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowExceptionMapper.java
new file mode 100644
index 0000000..5b80c69
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowExceptionMapper.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.servicenow;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.annotation.Priority;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
+
+@Provider
+@Priority(Priorities.USER)
+public class ServiceNowExceptionMapper implements ResponseExceptionMapper<ServiceNowException> {
+ private final ObjectMapper mapper;
+
+ public ServiceNowExceptionMapper(ObjectMapper mapper) {
+ this.mapper = mapper;
+ }
+
+ @Override
+ public ServiceNowException fromResponse(Response r) {
+ int code = r.getStatus();
+
+ try {
+ // Only ServiceNow known error status codes are mapped
+ // See http://wiki.servicenow.com/index.php?title=REST_API#REST_Response_HTTP_Status_Codes
+ if (code == Response.Status.NOT_FOUND.getStatusCode()
+ || code == Response.Status.BAD_REQUEST.getStatusCode()
+ || code == Response.Status.UNAUTHORIZED.getStatusCode()
+ || code == Response.Status.FORBIDDEN.getStatusCode()
+ || code == Response.Status.METHOD_NOT_ALLOWED.getStatusCode()) {
+
+ return mapper.readValue((InputStream)r.getEntity(), ServiceNowException.class);
+ }
+ } catch (IOException e) {
+ return new ServiceNowException(e);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducer.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducer.java
new file mode 100644
index 0000000..cd7d4a7
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducer.java
@@ -0,0 +1,103 @@
+/**
+ * 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.component.servicenow;
+
+import java.lang.ref.WeakReference;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.servicenow.model.ServiceNowAggregateProcessor;
+import org.apache.camel.component.servicenow.model.ServiceNowImportSetProcessor;
+import org.apache.camel.component.servicenow.model.ServiceNowTableProcessor;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * The ServiceNow producer.
+ */
+public class ServiceNowProducer extends DefaultProducer {
+
+ private final ServiceNowEndpoint endpoint;
+ private final ServiceNowConfiguration configuration;
+ private final WeakThreadLocal tableCache;
+ private final WeakThreadLocal aggregateCache;
+ private final WeakThreadLocal importSetCache;
+
+ public ServiceNowProducer(ServiceNowEndpoint endpoint) {
+ super(endpoint);
+
+ this.endpoint = endpoint;
+ this.configuration = endpoint.getConfiguration();
+ this.tableCache = new WeakThreadLocal(ServiceNowTableProcessor.SUPPLIER);
+ this.aggregateCache = new WeakThreadLocal(ServiceNowAggregateProcessor.SUPPLIER);
+ this.importSetCache = new WeakThreadLocal(ServiceNowImportSetProcessor.SUPPLIER);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ final String resource = exchange.getIn().getHeader(ServiceNowConstants.RESOURCE, String.class);
+
+ if (ObjectHelper.equal(ServiceNowConstants.RESOURCE_TABLE, resource, true)) {
+ tableCache.get().process(exchange);
+ } else if (ObjectHelper.equal(ServiceNowConstants.RESOURCE_AGGREGATE, resource, true)) {
+ aggregateCache.get().process(exchange);
+ } else if (ObjectHelper.equal(ServiceNowConstants.RESOURCE_IMPORT, resource, true)) {
+ importSetCache.get().process(exchange);
+ } else {
+ throw new IllegalArgumentException("Unknown resource type: " + resource);
+ }
+ }
+
+ // *************************************************************************
+ // Thread-Local processor instances as CXF client proxies are not thread
+ // safe. To be refactored once moved to Java 8 as ServiceNowProcessorSupplier
+ // can be replaced by:
+ //
+ // java.util.function.Function<ServiceNowEndpoint, Processor>
+ //
+ // so an instance of a specific processor can be obtained by a constructor
+ // ref, i.e:
+ //
+ // ServiceNowImportSetProcessor::new
+ //
+ // *************************************************************************
+
+ private final class WeakThreadLocal {
+ private final ThreadLocal<WeakReference<Processor>> cache;
+ private final ServiceNowProducerProcessor.Supplier supplier;
+
+ public WeakThreadLocal(ServiceNowProducerProcessor.Supplier supplier) {
+ this.cache = new ThreadLocal<>();
+ this.supplier = supplier;
+ }
+
+ public Processor get() throws Exception {
+ Processor processor = null;
+ WeakReference<Processor> ref = cache.get();
+ if (ref != null) {
+ processor = ref.get();
+ }
+
+ if (processor == null) {
+ processor = supplier.get(endpoint);
+ cache.set(new WeakReference<>(processor));
+ }
+
+ return processor;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducerProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducerProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducerProcessor.java
new file mode 100644
index 0000000..83b61ce
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowProducerProcessor.java
@@ -0,0 +1,139 @@
+/**
+ * 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.component.servicenow;
+
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.util.ObjectHelper;
+
+public abstract class ServiceNowProducerProcessor<T> implements Processor {
+
+ protected final ServiceNowEndpoint endpoint;
+ protected final ServiceNowConfiguration config;
+ protected final T client;
+ protected final ObjectMapper mapper;
+
+ // Cache for JavaTypes
+ private final JavaTypeCache javaTypeCache;
+
+ protected ServiceNowProducerProcessor(ServiceNowEndpoint endpoint, Class<T> type) throws Exception {
+ this.javaTypeCache = new JavaTypeCache();
+ this.endpoint = endpoint;
+ this.config = endpoint.getConfiguration();
+ this.client = endpoint.createClient(type);
+ this.mapper = ObjectHelper.notNull(config.getMapper(), "mapper");
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ final Message in = exchange.getIn();
+ final String tableName = in.getHeader(ServiceNowConstants.TABLE, config.getTable(), String.class);
+ final Class<?> model = in.getHeader(ServiceNowConstants.MODEL, config.getModel(tableName, Map.class), Class.class);
+ final String action = in.getHeader(ServiceNowConstants.ACTION, String.class);
+ final String sysId = in.getHeader(ServiceNowConstants.SYSPARM_ID, String.class);
+
+ doProcess(
+ exchange,
+ ObjectHelper.notNull(model, "model"),
+ ObjectHelper.notNull(action, "action"),
+ ObjectHelper.notNull(tableName, "tableName"),
+ sysId);
+ }
+
+ protected abstract void doProcess(
+ Exchange exchange,
+ Class<?> model,
+ String action,
+ String tableName,
+ String sysId) throws Exception;
+
+
+ protected ServiceNowProducerProcessor<T> validateBody(Message message, Class<?> model) {
+ return validateBody(message.getBody(), model);
+ }
+
+ protected ServiceNowProducerProcessor<T> validateBody(Object body, Class<?> model) {
+ ObjectHelper.notNull(body, "body");
+
+ if (!body.getClass().isAssignableFrom(model)) {
+ throw new IllegalArgumentException(
+ "Body is not compatible with model (body=" + body.getClass() + ", model=" + model);
+ }
+
+ return this;
+ }
+
+ protected ServiceNowProducerProcessor<T> setBody(Message message, Class<?> model, JsonNode answer) throws Exception {
+ message.setBody(unwrap(answer, model));
+
+ return this;
+ }
+
+ protected Object unwrap(JsonNode answer, Class<?> model) throws Exception {
+ Object result = null;
+
+ if (answer != null) {
+ JsonNode node = answer.get("result");
+ if (node != null) {
+ if (node.isArray()) {
+ if (model.isInstance(Map.class)) {
+ // If the model is a Map, there's no need to use any
+ // specific JavaType to instruct Jackson about the
+ // expected element type
+ result = mapper.treeToValue(node, List.class);
+ } else {
+ result = mapper.readValue(node.traverse(), javaTypeCache.get(model));
+ }
+ } else {
+ result = mapper.treeToValue(node, model);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ // *************************************************************************
+ // Use ClassValue to lazy create and cache JavaType
+ // *************************************************************************
+
+ private class JavaTypeCache extends ClassValue<JavaType> {
+ @Override
+ protected JavaType computeValue(Class<?> type) {
+ return mapper.getTypeFactory().constructCollectionType(List.class, type);
+ }
+ }
+
+ // *************************************************************************
+ // To be replaced with:
+ //
+ // java.util.function.Function<ServiceNowEndpoint, Processor>
+ //
+ // Once Camel will be Java 8 ready
+ // *************************************************************************
+
+ public interface Supplier {
+ Processor get(ServiceNowEndpoint endpoint) throws Exception;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/AuthenticationRequestFilter.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/AuthenticationRequestFilter.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/AuthenticationRequestFilter.java
new file mode 100644
index 0000000..d6e3b05
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/AuthenticationRequestFilter.java
@@ -0,0 +1,61 @@
+/**
+ * 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.component.servicenow.auth;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.DatatypeConverter;
+
+import org.apache.camel.component.servicenow.ServiceNowConfiguration;
+
+
+@Provider
+@Priority(Priorities.AUTHENTICATION)
+public class AuthenticationRequestFilter implements ClientRequestFilter {
+ private final ServiceNowConfiguration configuration;
+ private final OAuthToken token;
+ private final String authString;
+
+ public AuthenticationRequestFilter(ServiceNowConfiguration configuration, OAuthToken token) throws IOException {
+ this.configuration = configuration;
+ this.token = token;
+ this.authString = buildBasicAuthString(configuration);
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ if (token != null) {
+ requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, token.getAuthString());
+ } else if (authString != null) {
+ requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, authString);
+ }
+ }
+
+ private static String buildBasicAuthString(final ServiceNowConfiguration configuration) throws IOException {
+ if (!configuration.hasBasicAuthentication()) {
+ return null;
+ }
+
+ String userAndPassword = configuration.getUserName() + ":" + configuration.getPassword();
+ return "Basic " + DatatypeConverter.printBase64Binary(userAndPassword.getBytes("UTF-8"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java
new file mode 100644
index 0000000..11c3842
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/auth/OAuthToken.java
@@ -0,0 +1,109 @@
+/**
+ * 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.component.servicenow.auth;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.component.servicenow.ServiceNowConfiguration;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.rs.security.oauth2.client.Consumer;
+import org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
+import org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerGrant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OAuthToken {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OAuthToken.class);
+
+ private final String url;
+ private final ServiceNowConfiguration configuration;
+ private ClientAccessToken token;
+ private String authString;
+ private long expireAt;
+
+ public OAuthToken(String url, ServiceNowConfiguration configuration) {
+ this.url = url;
+ this.configuration = configuration;
+ this.token = null;
+ this.authString = null;
+ this.expireAt = 0;
+ }
+
+ private synchronized void getOrRefreshAccessToken() {
+ if (token == null) {
+ LOGGER.debug("Generate OAuth token");
+
+ token = OAuthClientUtils.getAccessToken(
+ WebClient.create(url),
+ new Consumer(
+ configuration.getOauthClientId(),
+ configuration.getOauthClientSecret()),
+ new ResourceOwnerGrant(
+ configuration.getUserName(),
+ configuration.getPassword()),
+ true
+ );
+
+ LOGGER.debug("OAuth token expires in {}s", token.getExpiresIn());
+
+ // Set expiration time related info in milliseconds
+ token.setIssuedAt(System.currentTimeMillis());
+ token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
+
+ authString = token.toString();
+
+ if (token.getExpiresIn() > 0) {
+ expireAt = token.getIssuedAt() + token.getExpiresIn();
+ }
+ } else if (expireAt > 0 && System.currentTimeMillis() >= expireAt) {
+ LOGGER.debug("OAuth token is expired, refresh it");
+
+ token = OAuthClientUtils.refreshAccessToken(
+ WebClient.create(url),
+ new Consumer(
+ configuration.getOauthClientId(),
+ configuration.getOauthClientSecret()),
+ token,
+ null,
+ false
+ );
+
+ LOGGER.debug("Refreshed OAuth token expires in {}s", token.getExpiresIn());
+
+ // Set expiration time related info in milliseconds
+ token.setIssuedAt(System.currentTimeMillis());
+ token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
+
+ authString = token.toString();
+
+ if (token.getExpiresIn() > 0) {
+ expireAt = token.getIssuedAt() + token.getExpiresIn();
+ }
+ }
+ }
+
+ public ClientAccessToken getClientAccess() {
+ getOrRefreshAccessToken();
+ return token;
+ }
+
+ public String getAuthString() {
+ getOrRefreshAccessToken();
+ return authString;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java
new file mode 100644
index 0000000..b723387
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregate.java
@@ -0,0 +1,50 @@
+/**
+ * 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.component.servicenow.model;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.camel.component.servicenow.ServiceNowException;
+
+@Path("/stats")
+@Produces("application/json")
+@Consumes("application/json")
+public interface ServiceNowAggregate {
+
+ @GET
+ @Path("{tableName}")
+ JsonNode retrieveStats(
+ @PathParam("tableName") String tableName,
+ @QueryParam("sysparm_query") String query,
+ @QueryParam("sysparm_avg_fields") String avgFields,
+ @QueryParam("sysparm_count") String count,
+ @QueryParam("sysparm_min_fields") String minFields,
+ @QueryParam("sysparm_max_fields") String maxFields,
+ @QueryParam("sysparm_sum_fields") String sumFields,
+ @QueryParam("sysparm_group_by") String groupBy,
+ @QueryParam("sysparm_order_by") String orderBy,
+ @QueryParam("sysparm_having") String having,
+ @QueryParam("sysparm_display_value") String displayValue
+ ) throws ServiceNowException;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java
new file mode 100644
index 0000000..964b772
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowAggregateProcessor.java
@@ -0,0 +1,68 @@
+/**
+ * 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.component.servicenow.model;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.servicenow.ServiceNowConstants;
+import org.apache.camel.component.servicenow.ServiceNowEndpoint;
+import org.apache.camel.component.servicenow.ServiceNowProducerProcessor;
+import org.apache.camel.util.ObjectHelper;
+
+public class ServiceNowAggregateProcessor extends ServiceNowProducerProcessor<ServiceNowAggregate> {
+
+ public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() {
+ @Override
+ public Processor get(ServiceNowEndpoint endpoint) throws Exception {
+ return new ServiceNowAggregateProcessor(endpoint);
+ }
+ };
+
+ public ServiceNowAggregateProcessor(ServiceNowEndpoint endpoint) throws Exception {
+ super(endpoint, ServiceNowAggregate.class);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception {
+ if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) {
+ retrieveStats(exchange.getIn(), model, tableName);
+ } else {
+ throw new IllegalArgumentException("Unknown action " + action);
+ }
+ }
+
+ private void retrieveStats(Message in, Class<?> model, String tableName) throws Exception {
+ setBody(
+ in,
+ model,
+ client.retrieveStats(
+ tableName,
+ in.getHeader(ServiceNowConstants.SYSPARM_QUERY, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_AVG_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_COUNT, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_MIN_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_MAX_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_SUM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_GROUP_BY, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_ORDER_BY, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_HAVING, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class)
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java
new file mode 100644
index 0000000..865187e
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSet.java
@@ -0,0 +1,48 @@
+/**
+ * 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.component.servicenow.model;
+
+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 com.fasterxml.jackson.databind.JsonNode;
+import org.apache.camel.component.servicenow.ServiceNowException;
+
+@Path("/import")
+@Produces("application/json")
+@Consumes("application/json")
+public interface ServiceNowImportSet {
+
+ @GET
+ @Path("{tableName}/{sysId}")
+ JsonNode retrieveRecordById(
+ @PathParam("tableName") String tableName,
+ @PathParam("sysId") String id
+ ) throws ServiceNowException;
+
+ @POST
+ @Path("{tableName}")
+ JsonNode createRecord(
+ @PathParam("tableName") String tableName,
+ String body
+ ) throws ServiceNowException;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java
new file mode 100644
index 0000000..e76e9c1
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowImportSetProcessor.java
@@ -0,0 +1,79 @@
+/**
+ * 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.component.servicenow.model;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.servicenow.ServiceNowConstants;
+import org.apache.camel.component.servicenow.ServiceNowEndpoint;
+import org.apache.camel.component.servicenow.ServiceNowProducerProcessor;
+import org.apache.camel.util.ObjectHelper;
+
+public class ServiceNowImportSetProcessor extends ServiceNowProducerProcessor<ServiceNowImportSet> {
+
+ public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() {
+ @Override
+ public Processor get(ServiceNowEndpoint endpoint) throws Exception {
+ return new ServiceNowImportSetProcessor(endpoint);
+ }
+ };
+
+ public ServiceNowImportSetProcessor(ServiceNowEndpoint endpoint) throws Exception {
+ super(endpoint, ServiceNowImportSet.class);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception {
+ if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) {
+ retrieveRecord(exchange.getIn(), model, tableName, sysId);
+ } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) {
+ createRecord(exchange.getIn(), model, tableName);
+ } else {
+ throw new IllegalArgumentException("Unknown action " + action);
+ }
+ }
+
+ /*
+ * GET https://instance.service-now.com/api/now/import/{tableName}/{sys_id}
+ */
+ private void retrieveRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception {
+ setBody(
+ in,
+ model,
+ client.retrieveRecordById(
+ tableName,
+ ObjectHelper.notNull(sysId, "sysId"))
+ );
+ }
+
+
+ /*
+ * POST https://instance.service-now.com/api/now/import/{tableName}
+ */
+ private void createRecord(Message in, Class<?> model, String tableName) throws Exception {
+ validateBody(in, model);
+ setBody(
+ in,
+ model,
+ client.createRecord(
+ tableName,
+ mapper.writeValueAsString(in.getBody())
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java
new file mode 100644
index 0000000..366d8ee
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTable.java
@@ -0,0 +1,108 @@
+/**
+ * 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.component.servicenow.model;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.camel.component.servicenow.ServiceNowException;
+import org.apache.cxf.jaxrs.ext.PATCH;
+
+@Path("/table")
+@Produces("application/json")
+@Consumes("application/json")
+public interface ServiceNowTable {
+
+ @GET
+ @Path("{tableName}")
+ JsonNode retrieveRecord(
+ @PathParam("tableName") String tableName,
+ @QueryParam("sysparm_query") String query,
+ @QueryParam("sysparm_display_value") String displayValue,
+ @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink,
+ @QueryParam("sysparm_fields") String fields,
+ @QueryParam("sysparm_limit") Integer limit,
+ @QueryParam("sysparm_view") String view
+ ) throws ServiceNowException;
+
+ @GET
+ @Path("{tableName}/{sysId}")
+ JsonNode retrieveRecordById(
+ @PathParam("tableName") String tableName,
+ @PathParam("sysId") String id,
+ @QueryParam("sysparm_display_value") String displayValue,
+ @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink,
+ @QueryParam("sysparm_fields") String fields,
+ @QueryParam("sysparm_view") String view
+ ) throws ServiceNowException;
+
+ @POST
+ @Path("{tableName}")
+ JsonNode createRecord(
+ @PathParam("tableName") String tableName,
+ @QueryParam("sysparm_display_value") String displayValue,
+ @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink,
+ @QueryParam("sysparm_fields") String fields,
+ @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue,
+ @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField,
+ @QueryParam("sysparm_view") String view,
+ String body
+ ) throws ServiceNowException;
+
+ @PUT
+ @Path("{tableName}/{sysId}")
+ JsonNode modifyRecord(
+ @PathParam("tableName") String tableName,
+ @PathParam("sysId") String id,
+ @QueryParam("sysparm_display_value") String displayValue,
+ @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink,
+ @QueryParam("sysparm_fields") String fields,
+ @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue,
+ @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField,
+ @QueryParam("sysparm_view") String view,
+ String body
+ ) throws ServiceNowException;
+
+ @DELETE
+ @Path("{tableName}/{sysId}")
+ JsonNode deleteRecord(
+ @PathParam("tableName") String tableName,
+ @PathParam("sysId") String id
+ ) throws ServiceNowException;
+
+ @PATCH
+ @Path("{tableName}/{sysId}")
+ JsonNode updateRecord(
+ @PathParam("tableName") String tableName,
+ @PathParam("sysId") String id,
+ @QueryParam("sysparm_display_value") String displayValue,
+ @QueryParam("sysparm_exclude_reference_link") Boolean excludeReferenceLink,
+ @QueryParam("sysparm_fields") String fields,
+ @QueryParam("sysparm_input_display_value") Boolean inputDisplayValue,
+ @QueryParam("sysparm_suppress_auto_sys_field") Boolean suppressAutoSysField,
+ @QueryParam("sysparm_view") String view,
+ String body
+ ) throws ServiceNowException;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java
new file mode 100644
index 0000000..7b6504d
--- /dev/null
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/model/ServiceNowTableProcessor.java
@@ -0,0 +1,169 @@
+/**
+ * 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.component.servicenow.model;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.servicenow.ServiceNowConstants;
+import org.apache.camel.component.servicenow.ServiceNowEndpoint;
+import org.apache.camel.component.servicenow.ServiceNowProducerProcessor;
+import org.apache.camel.util.ObjectHelper;
+
+public class ServiceNowTableProcessor extends ServiceNowProducerProcessor<ServiceNowTable> {
+
+ public static final ServiceNowProducerProcessor.Supplier SUPPLIER = new ServiceNowProducerProcessor.Supplier() {
+ @Override
+ public Processor get(ServiceNowEndpoint endpoint) throws Exception {
+ return new ServiceNowTableProcessor(endpoint);
+ }
+ };
+
+ public ServiceNowTableProcessor(ServiceNowEndpoint endpoint) throws Exception {
+ super(endpoint, ServiceNowTable.class);
+ }
+
+ @Override
+ protected void doProcess(Exchange exchange, Class<?> model, String action, String tableName, String sysId) throws Exception {
+ if (ObjectHelper.equal(ServiceNowConstants.ACTION_RETRIEVE, action, true)) {
+ retrieveRecord(exchange.getIn(), model, tableName, sysId);
+ } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_CREATE, action, true)) {
+ createRecord(exchange.getIn(), model, tableName);
+ } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_MODIFY, action, true)) {
+ modifyRecord(exchange.getIn(), model, tableName, sysId);
+ } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_DELETE, action, true)) {
+ deleteRecord(exchange.getIn(), model, tableName, sysId);
+ } else if (ObjectHelper.equal(ServiceNowConstants.ACTION_UPDATE, action, true)) {
+ updateRecord(exchange.getIn(), model, tableName, sysId);
+ } else {
+ throw new IllegalArgumentException("Unknown action " + action);
+ }
+ }
+
+ /*
+ * GET https://instance.service-now.com/api/now/table/{tableName}
+ * GET https://instance.service-now.com/api/now/table/{tableName}/{sys_id}
+ */
+ private void retrieveRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception {
+ if (sysId == null) {
+ setBody(
+ in,
+ model,
+ client.retrieveRecord(
+ tableName,
+ in.getHeader(ServiceNowConstants.SYSPARM_QUERY, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_LIMIT, Integer.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class)
+ )
+ );
+ } else {
+ setBody(
+ in,
+ model,
+ client.retrieveRecordById(
+ tableName,
+ ObjectHelper.notNull(sysId, "sysId"),
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class)
+ )
+ );
+ }
+ }
+
+ /*
+ * POST https://instance.service-now.com/api/now/table/{tableName}
+ */
+ private void createRecord(Message in, Class<?> model, String tableName) throws Exception {
+ validateBody(in, model);
+ setBody(
+ in,
+ model,
+ client.createRecord(
+ tableName,
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class),
+ mapper.writeValueAsString(in.getBody())
+ )
+ );
+ }
+
+ /*
+ * PUT https://instance.service-now.com/api/now/table/{tableName}/{sys_id}
+ */
+ private void modifyRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception {
+ validateBody(in, model);
+ setBody(
+ in,
+ model,
+ client.modifyRecord(
+ tableName,
+ ObjectHelper.notNull(sysId, "sysId"),
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class),
+ mapper.writeValueAsString(in.getBody())
+ )
+ );
+ }
+
+ /*
+ * DELETE https://instance.service-now.com/api/now/table/{tableName}/{sys_id}
+ */
+ private void deleteRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception {
+ setBody(
+ in,
+ model,
+ client.deleteRecord(
+ tableName,
+ ObjectHelper.notNull(sysId, "sysId"))
+ );
+ }
+
+ /*
+ * PATCH instance://dev21005.service-now.com/api/now/table/{tableName}/{sys_id}
+ */
+ private void updateRecord(Message in, Class<?> model, String tableName, String sysId) throws Exception {
+ validateBody(in, model);
+ setBody(
+ in,
+ model,
+ client.updateRecord(
+ tableName,
+ ObjectHelper.notNull(sysId, "sysId"),
+ in.getHeader(ServiceNowConstants.SYSPARM_DISPLAY_VALUE, config.getDisplayValue(), String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_EXCLUDE_REFERENCE_LINK, config.getExcludeReferenceLink(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_FIELDS, String.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_INPUT_DISPLAY_VALUE, config.getInputDisplayValue(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, config.getSuppressAutoSysField(), Boolean.class),
+ in.getHeader(ServiceNowConstants.SYSPARM_VIEW, String.class),
+ mapper.writeValueAsString(in.getBody())
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aa7ca432/components/camel-servicenow/src/main/resources/META-INF/services/org/apache/camel/component/servicenow
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/resources/META-INF/services/org/apache/camel/component/servicenow b/components/camel-servicenow/src/main/resources/META-INF/services/org/apache/camel/component/servicenow
new file mode 100644
index 0000000..be9acb6
--- /dev/null
+++ b/components/camel-servicenow/src/main/resources/META-INF/services/org/apache/camel/component/servicenow
@@ -0,0 +1 @@
+class=org.apache.camel.component.servicenow.ServiceNowComponent
[8/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f78935ee
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f78935ee
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f78935ee
Branch: refs/heads/camel-2.17.x
Commit: f78935eee9e4bacc1f0cad10420fb118a5f481d9
Parents: 7dc24fa
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:49:57 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:56:34 2016 +0100
----------------------------------------------------------------------
.../apache/camel/component/braintree/BraintreeConfiguration.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f78935ee/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
index 4376a9e..b7a5d87 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
@@ -38,7 +38,7 @@ public class BraintreeConfiguration {
@UriPath
@Metadata(required = "true")
private BraintreeApiName apiName;
- @UriPath @Metadata(required = "true")
+ @UriPath
private String methodName;
@UriParam
[3/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1c76b491
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1c76b491
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1c76b491
Branch: refs/heads/master
Commit: 1c76b491d33488a51ad8f916fbf9dda23e9d7329
Parents: aa7ca43
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:48:30 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:48:30 2016 +0100
----------------------------------------------------------------------
.../component/braintree/BraintreeComponent.java | 2 ++
.../braintree/BraintreeConfiguration.java | 30 ++++++++++++++++++++
.../component/braintree/BraintreeEndpoint.java | 14 ++++-----
3 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1c76b491/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
index 5b468cc..8918771 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeComponent.java
@@ -49,6 +49,8 @@ public class BraintreeComponent extends AbstractApiComponent<BraintreeApiName, B
@Override
protected Endpoint createEndpoint(String uri, String methodName, BraintreeApiName apiName, BraintreeConfiguration endpointConfiguration) {
+ endpointConfiguration.setApiName(apiName);
+ endpointConfiguration.setMethodName(methodName);
return new BraintreeEndpoint(uri, this, apiName, methodName, endpointConfiguration, getGateway(endpointConfiguration));
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1c76b491/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
index e366c2c..4376a9e 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
@@ -18,9 +18,11 @@ package org.apache.camel.component.braintree;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.Environment;
+import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
import org.apache.camel.util.ObjectHelper;
/**
@@ -33,6 +35,12 @@ public class BraintreeConfiguration {
private static final String PUBLIC_KEY = "public_key";
private static final String PRIVATE_KEY = "private_key";
+ @UriPath
+ @Metadata(required = "true")
+ private BraintreeApiName apiName;
+ @UriPath @Metadata(required = "true")
+ private String methodName;
+
@UriParam
@Metadata(required = "true")
private String environment;
@@ -57,6 +65,28 @@ public class BraintreeConfiguration {
@Metadata(label = "proxy")
private Integer proxyPort;
+ public BraintreeApiName getApiName() {
+ return apiName;
+ }
+
+ /**
+ * What kind of operation to perform
+ */
+ public void setApiName(BraintreeApiName apiName) {
+ this.apiName = apiName;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ /**
+ * What sub operation to use for the selected operation
+ */
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
public String getEnvironment() {
return ObjectHelper.notNull(environment, ENVIRONMENT);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1c76b491/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
index 5df6301..0c2af85 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeEndpoint.java
@@ -29,6 +29,7 @@ import org.apache.camel.component.braintree.internal.BraintreeApiName;
import org.apache.camel.component.braintree.internal.BraintreeConstants;
import org.apache.camel.component.braintree.internal.BraintreePropertiesHelper;
import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.camel.util.component.AbstractApiEndpoint;
import org.apache.camel.util.component.ApiMethod;
@@ -37,21 +38,20 @@ import org.apache.camel.util.component.ApiMethodPropertiesHelper;
/**
* The braintree component is used for integrating with the Braintree Payment System.
*/
-@UriEndpoint(scheme = "braintree", title = "Braintree", syntax = "braintree:name", consumerClass = BraintreeConsumer.class, label = "Braintree")
+@UriEndpoint(scheme = "braintree", title = "Braintree", syntax = "braintree:name", consumerClass = BraintreeConsumer.class, label = "api,cloud,payment")
public class BraintreeEndpoint extends AbstractApiEndpoint<BraintreeApiName, BraintreeConfiguration> {
- @UriPath(description = "the method name")
- private final String name;
+ @UriParam
+ private final BraintreeConfiguration configuration;
private Object apiProxy;
private final BraintreeGateway gateway;
public BraintreeEndpoint(String uri, BraintreeComponent component,
- BraintreeApiName apiName, String methodName, BraintreeConfiguration endpointConfiguration, BraintreeGateway gateway) {
- super(uri, component, apiName, methodName, BraintreeApiCollection.getCollection().getHelper(apiName), endpointConfiguration);
-
+ BraintreeApiName apiName, String methodName, BraintreeConfiguration configuration, BraintreeGateway gateway) {
+ super(uri, component, apiName, methodName, BraintreeApiCollection.getCollection().getHelper(apiName), configuration);
+ this.configuration = configuration;
this.gateway = gateway;
- this.name = methodName;
}
@Override
[5/8] camel git commit: Fixed component docs
Posted by da...@apache.org.
Fixed component docs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3ef6e4de
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3ef6e4de
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3ef6e4de
Branch: refs/heads/master
Commit: 3ef6e4de8b84147b0f33054a9e207d5d0c5d2cfc
Parents: b8dec7a
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Mar 22 16:49:57 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 22 16:49:57 2016 +0100
----------------------------------------------------------------------
.../apache/camel/component/braintree/BraintreeConfiguration.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3ef6e4de/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
index 4376a9e..b7a5d87 100644
--- a/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
+++ b/components/camel-braintree/src/main/java/org/apache/camel/component/braintree/BraintreeConfiguration.java
@@ -38,7 +38,7 @@ public class BraintreeConfiguration {
@UriPath
@Metadata(required = "true")
private BraintreeApiName apiName;
- @UriPath @Metadata(required = "true")
+ @UriPath
private String methodName;
@UriParam