org.apache.camel.component.servicenow.ServiceNowParams Java Examples
The following examples show how to use
org.apache.camel.component.servicenow.ServiceNowParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceNowTableGetCustomizer.java From syndesis with Apache License 2.0 | 6 votes |
private void beforeProducer(final Exchange exchange) { exchange.getIn().setHeader(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_TABLE); exchange.getIn().setHeader(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE); exchange.getIn().setHeader(ServiceNowConstants.RESPONSE_MODEL, JsonNode.class); // set the maximum number of item that can be include in a page // // TODO: we need to discuss how to handle pagination. if (limit != null) { exchange.getIn().setHeader(ServiceNowParams.SYSPARM_LIMIT.getHeader(), limit); } // set the query used to filter out record sets, the query is // expected to be encoded. if (query != null) { try { final String key = ServiceNowParams.SYSPARM_QUERY.getHeader(); final String val = URLEncoder.encode(query, StandardCharsets.UTF_8.name()); exchange.getIn().setHeader(key, val); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } } }
Example #2
Source File: ServicenowResource.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Path("/post") @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response post(String message) throws Exception { Map<String, Object> headers = new HashMap<>(); headers.put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_TABLE); headers.put(ServiceNowConstants.API_VERSION, "v1"); headers.put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE); headers.put(ServiceNowConstants.REQUEST_MODEL, Incident.class); headers.put(ServiceNowConstants.RESPONSE_MODEL, JsonNode.class); headers.put(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), "incident"); Incident incident = new Incident(); incident.setDescription(message); incident.setImpact(1); incident.setSeverity(1); LOG.infof("Sending to servicenow: %s", message); final JsonNode response = producerTemplate.requestBodyAndHeaders( "servicenow:" + instance, incident, headers, JsonNode.class); String number = response.findPath("number").textValue(); LOG.infof("Got response from servicenow: %s", response); return Response .created(new URI("https://camel.apache.org/")) .entity(number) .build(); }
Example #3
Source File: ServiceNowIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testSearchIncidents() throws Exception { Map<String, Object> serviceNowOptions = createServiceNowOptions(); Assume.assumeTrue("[#1674] Enable ServiceNow testing in Jenkins", serviceNowOptions.size() == ServiceNowIntegrationTest.ServiceNowOption.values().length); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("servicenow:{{env:SERVICENOW_INSTANCE}}" + "?userName={{env:SERVICENOW_USERNAME}}" + "&password={{env:SERVICENOW_PASSWORD}}" + "&oauthClientId={{env:SERVICENOW_CLIENT_ID}}" + "&oauthClientSecret={{env:SERVICENOW_CLIENT_SECRET}}" + "&release={{env:SERVICENOW_RELEASE}}" + "&model.incident=org.wildfly.camel.test.servicenow.subA.Incident"); } }); camelctx.start(); try { Map<String, Object> headers = new HashMap<>(); headers.put(ServiceNowConstants.RESOURCE, "table"); headers.put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE); headers.put(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), "incident"); ProducerTemplate producer = camelctx.createProducerTemplate(); List<Incident> result = producer.requestBodyAndHeaders("direct:start", null, headers, List.class); Assert.assertNotNull(result); Assert.assertTrue(result.size() > 0); } finally { camelctx.close(); } }