[jboss-user] [jBPM] - Re: Problem with Rest Interface in JBPM 5.2

Sachin Chandra do-not-reply at jboss.com
Sun Jun 3 14:22:00 EDT 2012


Sachin Chandra [https://community.jboss.org/people/chandrasachin16] created the discussion

"Re: Problem with Rest Interface in JBPM 5.2"

To view the discussion, visit: https://community.jboss.org/message/739546#739546

--------------------------------------------------------------
Hi Dirk ,

I tried with the solution given in the link as suggested by you. I tried with Http Client 4.2. I created a web service in which I wrote two methods (authenticate and requestPostService).The code is written as follows

public class RestInt {

    public static String KEY_USERNAME="j_username";
    public static String KEY_PASSWORD="j_password";
    private static HttpClient httpclient = new DefaultHttpClient();
    private static final String PROCESS_INSTANCE=" http://localhost:8080/gwt-console-server/rs/process/definition/ http://localhost:8080/gwt-console-server/rs/process/definition/{com.sample.evaluation}/new_instance";
    public String MyService(String name) throws ClientProtocolException, IOException{
        String response=authenticate("krisv","krisv");
        System.out.println("Authentication------------------------"+response);
        response=requestPostService(PROCESS_INSTANCE,null,false);
        System.out.println("Process Instance------------------------"+response);
        return  response;
        }

    public static String authenticate(String username,String password){
        String responseString="";
        List<NameValuePair> formsParam=new ArrayList<NameValuePair>();
        formsParam.add(new BasicNameValuePair(KEY_USERNAME, username));
        formsParam.add(new BasicNameValuePair(KEY_PASSWORD, password));
        HttpPost httpPost=new HttpPost(" http://localhost:8080/gwt-console-server/rs/process/j_security_check http://localhost:8080/gwt-console-server/rs/process/j_security_check");
        InputStreamReader inputStreamReader=null;
        BufferedReader bufferedReader=null;
        try{

            UrlEncodedFormEntity entity=new UrlEncodedFormEntity(formsParam, "UTF-8");
            httpPost.setEntity(entity);
            HttpResponse response=httpclient.execute(httpPost);
            InputStream inputStream=response.getEntity().getContent();
            inputStreamReader=new InputStreamReader(inputStream);
            bufferedReader=new BufferedReader(inputStreamReader);
            StringBuilder builder =new StringBuilder();
            String line=bufferedReader.readLine();
            while(line!=null){
                builder.append(line);
                System.out.println("line--------------------------------"+line);
                line=bufferedReader.readLine();
            }
            responseString=builder.toString();
        }catch(Exception ex){
            throw new RuntimeException(ex);
        }finally{
            if(inputStreamReader!=null){
                try{
                    inputStreamReader.close();
                }catch(Exception ex){
                    throw new RuntimeException(ex);
                }
            }if(bufferedReader!=null){
                try{
                    bufferedReader.close();
                }catch(Exception ex){
                    throw new RuntimeException(ex);
                }
            }
        }
        return responseString;
    }
    public static String requestPostService(String url,Map<String,Object> parameters,boolean multipart) throws ClientProtocolException, IOException{
        String responseString="";
        MultipartEntity multiPartEntity=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        List<NameValuePair> formsParam=new ArrayList<NameValuePair>();
        if(parameters==null){
            parameters=new HashMap<String, Object>();
        }
        Set<String> keys =parameters.keySet();
        for(Iterator<String> keysIterator=keys.iterator();keysIterator.hasNext();){
            String keyString=keysIterator.next();
            String value=parameters.get(keyString).toString();
            formsParam.add(new BasicNameValuePair(keyString, value));
            if(multipart){
                try{
                  StringBody body=new StringBody(value,"text/plain",Charset.forName("UTF-8"));
                  multiPartEntity.addPart(keyString, (ContentBody)body);
                }catch(Exception ex){
                    throw new RuntimeException(ex);
                }

            }
        }
        HttpPost httpPost=new HttpPost(url);
        InputStreamReader inputStreamReader=null;
        BufferedReader bufferedReader=null;
        try{
        if(multipart){
            httpPost.setEntity(multiPartEntity);
        }else{
            UrlEncodedFormEntity entity=new UrlEncodedFormEntity(formsParam, "UTF-8");
            httpPost.setEntity(entity);
        }
        HttpResponse response=httpclient.execute(httpPost);
        InputStream inputStream=response.getEntity().getContent();
        inputStreamReader=new InputStreamReader(inputStream);
        bufferedReader=new BufferedReader(inputStreamReader);
        StringBuilder builder =new StringBuilder();
        String line=bufferedReader.readLine();
        while(line!=null){
            builder.append(line);
            System.out.println("line--------------------------------"+line);
            line=bufferedReader.readLine();
        }
        responseString=builder.toString();
        }catch(Exception ex){
            throw new RuntimeException(ex);
        }finally{
            if(inputStreamReader!=null){
                try{
                    inputStreamReader.close();
                }catch(Exception ex){
                    throw new RuntimeException(ex);
                }
            }if(bufferedReader!=null){
                try{
                    bufferedReader.close();
                }catch(Exception ex){
                    throw new RuntimeException(ex);
                }
            }
        }
        return responseString;
    }
}


However when I tried to run this I got an error "The client did not produce a request within the time that the server was prepared to wait".It looks like this is a problem with timeout.Also another error occurs while accessing invoking the web service.In the code I am trying to invoke the web service using a JSP ,but I get exception: java.lang.IllegalArgumentException which occurs at line 
response=requestPostService(PROCESS_INSTANCE,null,false); // since we are passing null for the second argument.My queries why we are passing  a null value or has it got some purpose to serve ?
The errror log in Jboss's server log is as given below.


22:43:30,172 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-1) Initializing Mojarra 2.1.3 (SNAPSHOT 20110825) for context '/drools-guvnor'
22:43:33,610 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-1) Hibernate Validator 4.2.0.Final
22:43:33,794 INFO  [org.jboss.web] (MSC service thread 1-1) registering web context: /drools-guvnor
22:43:33,796 INFO  [org.jboss.as] (MSC service thread 1-2) JBoss AS 7.0.2.Final "Arc" started in 208029ms - Started 430 of 497 services (67 services are passive or on-demand)
22:43:33,860 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "JBPMRestClient.war"
22:43:33,861 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "JBPMRest.war"
22:43:33,861 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "jbpm-gwt-console.war"
22:43:33,861 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "jbpm-gwt-console-server.war"
22:43:33,861 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "drools-guvnor.war"
22:43:33,861 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "designer.war"
23:22:48,542 INFO  [stdout] (http-localhost-127.0.0.1-8080-4) line--------------------------------<html><head><title>JBoss Web/7.0.1.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 408 - The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</u></p><p><b>description</b> <u>The client did not produce a request within the time that the server was prepared to wait (The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser).</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.1.Final</h3></body></html>

23:22:48,543 INFO  [stdout] (http-localhost-127.0.0.1-8080-4) Authentication------------------------<html><head><title>JBoss Web/7.0.1.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 408 - The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser</u></p><p><b>description</b> <u>The client did not produce a request within the time that the server was prepared to wait (The time allowed for the login process has been exceeded. If you wish to continue you must either click back twice and re-click the link you requested or close and re-open your browser).</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.1.Final</h3></body></html>

Can you please throw some light on this .

Regards
Sachin
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/739546#739546]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120603/a24f076f/attachment-0001.html 


More information about the jboss-user mailing list