public void multipleDifferentRuntimeExamples(String deploymentId, URL deploymentUrl, boolean useFormBasedAuth) throws Exception { RemoteRestRuntimeEngineBuilder runtimeEngineBuilder = RemoteRuntimeEngineFactory.newRestBuilder() .addDeploymentId(deploymentId) .addUrl(deploymentUrl); RuntimeEngine krisRemoteEngine = runtimeEngineBuilder .addUserName(KRIS_USER) .addPassword(KRIS_PASSWORD) .build(); RuntimeEngine maryRemoteEngine = runtimeEngineBuilder .addUserName(MARY_USER) .addPassword(MARY_PASSWORD) .build(); RuntimeEngine johnRemoteEngine = runtimeEngineBuilder .addUserName(JOHN_USER) .addPassword(JOHN_PASSWORD) .build(); }
.addUrl(new URL("http://localhost:8080/kie-wb")) .addTimeout(3) .build(); fail( "A user name should always be required!"); } catch(InsufficientInfoToBuildException e) { .addUrl(new URL("http://localhost:8080/kie-wb")) .addTimeout(3) .build(); fail( "A password should always be required!"); } catch(InsufficientInfoToBuildException e) { .addPassword("suiker") .addTimeout(3) .build(); fail( "A URL should always be required!"); } catch(InsufficientInfoToBuildException e) { .addPassword("stroop") .addUrl(new URL("http://localhost:8080/kie-wb")) .build();
private RemoteConfiguration buildRemoteConfiguration(RemoteModel remoteModel) { RuntimeEngine engine = null; if (remoteModel instanceof RemoteJmsModel) { RemoteJmsRuntimeEngineBuilder builder = RemoteRuntimeEngineFactory.newJmsBuilder(); InitialContext ctx = configRemoteJms(builder, (RemoteJmsModel)remoteModel); try { engine = builder.build(); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception e) { e.getMessage(); // ignore but keep checkstyle happy } } } } else if (remoteModel instanceof RemoteRestModel) { RemoteRestRuntimeEngineBuilder builder = RemoteRuntimeEngineFactory.newRestBuilder(); configRemoteRest(builder, (RemoteRestModel)remoteModel); engine = builder.build(); } RemoteConfiguration config = null; if (engine instanceof RemoteRuntimeEngine) { Access<RemoteConfiguration> configAccess = new FieldAccess<RemoteConfiguration>(RemoteRuntimeEngine.class, "config"); config = configAccess.isReadable() ? configAccess.read(engine) : null; } return config; }
private RemoteConfiguration buildRemoteConfiguration(RemoteModel remoteModel) { RuntimeEngine engine = null; if (remoteModel instanceof RemoteJmsModel) { RemoteJmsRuntimeEngineBuilder builder = RemoteRuntimeEngineFactory.newJmsBuilder(); InitialContext ctx = configRemoteJms(builder, (RemoteJmsModel)remoteModel); try { engine = builder.build(); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception e) { e.getMessage(); // ignore but keep checkstyle happy } } } } else if (remoteModel instanceof RemoteRestModel) { RemoteRestRuntimeEngineBuilder builder = RemoteRuntimeEngineFactory.newRestBuilder(); configRemoteRest(builder, (RemoteRestModel)remoteModel); engine = builder.build(); } RemoteConfiguration config = null; if (engine instanceof RemoteRuntimeEngine) { Access<RemoteConfiguration> configAccess = new FieldAccess<RemoteConfiguration>(RemoteRuntimeEngine.class, "config"); config = configAccess.isReadable() ? configAccess.read(engine) : null; } return config; }
/** * With the introduction of the fluent/builder API in 6.0.x, we could do this: * * RemoteRestRuntimeEngineFactory factory = * RemoteRestRuntimeEngineFactory.newBuilder() * .addUserName("user") * .addPassword("pass") * .addUrl(new URL("http://localhost:8080/business-central")) * .build(); * * RuntimeEngine runtimeEngine = factory.newRuntimeEngine(); * * With the 6.0.x code, we built a factory, that we then used to create the runtime.. * * Why not just build the runtime immediately? :) */ public void createRestRuntimeEngineWithBuilder() throws MalformedURLException { // unfortunately, this breaks backward compatibility, but the improvement and clarity in the API is worth the risk RuntimeEngine runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addUserName("user") .addPassword("pass") .addUrl(new URL("http://localhost:8080/business-central")) .build(); } }
protected KieSession initKieSession() throws CoreException { RuntimeEngine restSessionFactory; try { restSessionFactory = RemoteRuntimeEngineFactory.newRestBuilder() .addDeploymentId(bpmConfig.getDeploymentId()) .addUrl(new URL(bpmConfig.getBpmInstanceUrl())) .addUserName(bpmConfig.getUsername()) .addPassword(bpmConfig.getPassword()) .addTimeout(AUTHENTICATION_TIMEOUT_S) .build(); } catch (Exception e) { throw new CoreException("Could not initialize connection to BPM server at '" + bpmConfig.getBpmInstanceUrl() + "' check that the URL is correct.", e); } return restSessionFactory.getKieSession(); }
public void minimumRestBuilderExample() throws Exception { RuntimeEngine runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addUserName("user") .addPassword("pass") .addUrl(new URL("http://localhost:8080/business-central")) .build(); runtimeEngine.getTaskService().claim(23l, "user"); // This will throw a MissingRequiredInfoException because the deployment id is required here runtimeEngine.getKieSession().startProcess("org.test.process"); }
.addUserName(userId) .addPassword(password) .build();
.addUserName(user) .addPassword(password) .build();
@Test public void setHeaderFields() throws Exception { RuntimeEngine runtimeEngine = RemoteRuntimeEngineFactory.newRestBuilder() .addUserName("user") .addPassword("pass") .addUrl(new URL("http://localhost:8080/business-central")) .addHeader("HEADER-NAME", "header-value") .clearHeaderFields() .addCorrelationProperties() .addDeploymentId("dep-id") .build(); try { runtimeEngine.getTaskService().claim(23l, "user"); fail( "This should have failed because there's no server running... "); } catch( org.kie.remote.client.api.exception.RemoteCommunicationException rce ) { // expected } } }
.addUserName(user) .addPassword(password) .build();
.addPassword("pass") .addUrl(new URL("http://localhost:8080/business-central")) .build();