Project

General

Profile

Actions

Feature #38495

closed

Java API - Issue Redmine

Added by Eliana Monteleone over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid

Description

public String doPostIssue() throws IOException {

        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope("redmine.org/issues", 80),
                new UsernamePasswordCredentials("admin", "admin"));

        HttpPost httpPost = new HttpPost("http://www.redmine.org/issues");

        System.out.println("executing request:\n" + httpPost.getRequestLine());
        HttpEntity entity = new EntityTemplate(cp);
        httpPost.setEntity(entity);
        HttpResponse response = httpclient.execute(httpPost);

        HttpEntity responseEntity = response.getEntity();
        String value = "";
        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (responseEntity != null) {
            System.out.println("Response content length: " 
                    + responseEntity.getContentLength());
            value = responseEntity.getContent().toString();
        }
        System.out.println(EntityUtils.toString(responseEntity));
        httpclient.getConnectionManager().shutdown();
        return value;
    }

    ContentProducer cp = new ContentProducer() {
        public void writeTo(OutputStream outstream) throws IOException {
            Writer writer = new OutputStreamWriter(outstream, "UTF-8");
            writer.write("format=json&action=new&");
            String payload = "{\"issue\": {\"subject\": \"New Issue by Eliana\",\"description\": \"Some description\",\"tracker_id\": \"1\",\"priority_id\":\"3\",\"custom_fields\": [{\"id\": \"1\", \"value\": \"" + new Random().nextInt() + "\"}]}}";

            writer.write(payload);
            writer.flush();
        }
    };

I have this response:

POST http://www.redmine.org/issues HTTP/1.1
----------------------------------------
HTTP/1.1 301 Moved Permanently
Response content length: 0

How should I fix it?

Actions

Also available in: Atom PDF