Example remote Api JBPM
reky1991 Dec 11, 2015 7:26 AMHello.
I'm trying to compile the example shown in the official document JBPM version 6.2. Section "17.1.3. Runt ime REST API" and gives me error on objects and functions.
I am using the maven dependencies API KIE version 6.2 and is not working. some of the functions and objects do not exist. the code:
package Task;
import java.io.InputStream;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.transform.stream.StreamSource;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.jboss.resteasy.client.ClientExecutor; //yellow underlined and ClientExecutor is streaked
import org.jboss.resteasy.client.ClientRequest; //yellow underlined and ClientRequest is streaked
import org.jboss.resteasy.client.ClientRequestFactory; //yellow underlined and ClientRequestFactory is streaked
import org.jboss.resteasy.client.ClientResponse; //yellow underlined and ClientResponse is streaked
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.kie.api.task.model.*;
import org.kie.services.client.serialization.jaxb.impl.task.JaxbTaskResponse; // not exists
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Task {
public Task getTaskInstanceInfo(long taskId) throws Exception {
URL address = new URL(url + "/task/" + taskId);
ClientRequest restRequest = createRequest(address); //the all ClientRequest yellow underlined and streaked: The type ClientRequest //is deprecated
ClientResponse<JaxbTaskResponse> responseObj = restRequest.get(JaxbTaskResponse.class); //JaxbTaskResponse red underlined, JaxbTaskResponse cannot be resolved to a type
ClientResponse<InputStream> taskResponse = responseObj.get(InputStream.class);
JAXBContext jaxbTaskContext = JAXBContext.newInstance(JaxbTaskResponse.class);
StreamSource source = new StreamSource(taskResponse.getEntity());
return jaxbTaskContext.createUnmarshaller().unmarshal(source,JaxbTaskResponse.class).getValue(); //The method unmarshal(Source, Class<JaxbTaskResponse>) from the //type Unmarshaller refers to the missing type JaxbTaskResponse
}
private ClientRequest createRequest(URL address) {
return getClientRequestFactory().createRequest(address.toExternalForm()); //createRequest is yellow underlined and streaked: The method createRequest(String) from the type //ClientRequestFactory is deprecated
}
private ClientRequestFactory getClientRequestFactory() {
DefaultHttpClient httpClient = new DefaultHttpClient(); //The type DefaultHttpClient is deprecated and streaked
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(userId, password));
ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
return new ClientRequestFactory(clientExecutor, ResteasyProviderFactory.getInstance());
}
}
the dependencies that i use are:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.10.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.10.Final</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>6.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.kie.remote</groupId>
<artifactId>kie-remote-client</artifactId>
<version>6.2.0.Final</version>
</dependency>
The document:
Thanks