Question: Looking For A Reason Why My Java Code Could Not Create Pathway Image Using Reactome Restful Api
gravatar for samsara
6.5 years ago by
The Earth
samsara600 wrote:

I have been struggling with Reactome RESTful API to generate pathway diagram for a while. When performed HTTP GET requesto to, API returns base64 encoded image. Here, 109581 is Pathway database identifier. For some reason I am unable to write it to PNG image in java.

I am using Apache Commons Codec for base64 decoding and jersey for REST client.

Could you please find out the reason why i am unable to write to image after decoding base64 string ?

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.apache.commons.codec.binary.Base64;

 * @author bishwa
public class ReactomeRESTJava {

    public static void writeImage(String encodedString) throws IOException
        // Decode InputcodedString
        byte[] decodedByteArray = Base64.decodeBase64(encodedString);
        // convert byte into string
        String decodedString = new String(decodedByteArray);

        BufferedWriter out = new BufferedWriter(new FileWriter("test.png"));


    public static void main(String[] args) {
        // TODO code application logic here
            // Parameters ------------------------------------------------------
            String baseURL=""
                    + "/RESTfulWS/";
            //String method="POST";
            String method="GET";
            String url = "pathwayDiagram/109581/png";
            String input= "ID=170075,176374,68557";

            Client client1 = Client.create();
            WebResource webRS = client1.resource(baseURL+url);

            ClientResponse response = null ;

            // perform GET of POST request
            System.out.println("Fetching ..");
            switch (method) 
                case "POST":
                    response = webRS.accept("application/json")
                            .post(ClientResponse.class, input);
                case "GET":
                    response = webRS.accept("text/plain")

            // throw response error codes
            if(response.getStatus() != 200)
                throw new RuntimeException("Failed: HTTP error code: "
                        + response.getStatus());

            String output = response.getEntity(String.class);
            //System.out.println("Output from Server ..\n");

            // write base64 coded string to png image
            System.out.println("Writing image to a file...");

        } catch (RuntimeException | IOException e){}
pathway api java • 2.8k views
ADD COMMENTlink modified 6.5 years ago by Pierre Lindenbaum123k • written 6.5 years ago by samsara600

what do you mean "I'm unable to write..." ? What is the exact error ?

ADD REPLYlink written 6.5 years ago by Pierre Lindenbaum123k

The image written is blank.

ADD REPLYlink modified 6.5 years ago • written 6.5 years ago by samsara600
gravatar for Pierre Lindenbaum
6.5 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum123k wrote:

you should never write an array of bytes using a *Writer : UTF-8 or any 'Locale' characters will be interpreted. see Use a *OutputStream instead.

You'd better use:

FileOutputStream out=new FileOutputStream(new File("image.png"));
ADD COMMENTlink modified 6.5 years ago • written 6.5 years ago by Pierre Lindenbaum123k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 758 users visited in the last hour