abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "vijayaraghavan (JIRA)" <j...@apache.org>
Subject [jira] [Created] (ABDERA-388) Apache Abdera Multipart Request throwing nullpointer Exception
Date Fri, 04 Apr 2014 07:25:14 GMT
vijayaraghavan created ABDERA-388:
-------------------------------------

             Summary: Apache Abdera Multipart Request throwing nullpointer Exception
                 Key: ABDERA-388
                 URL: https://issues.apache.org/jira/browse/ABDERA-388
             Project: Abdera
          Issue Type: Bug
    Affects Versions: 1.1.2
         Environment: Standalone java application
            Reporter: vijayaraghavan
            Priority: Critical


I am using Apache abdera to post multipart request to IBM connection 4.0 API. I am getting
nullpointer exception from Abdera API. Please let me know what's the root cause.

private void createEntryWithAttachment(){
    try {
        String activityId = "urn:lsid:ibm.com:oa:662d0dc7-0308-48ee-8291-d730c733d2d1";  
      
        String activityIdLocal = activityId.substring(activityId.lastIndexOf(":")+1, activityId.length());
        String createEntryLocal = createEntry+activityIdLocal;      

        Abdera abdera = new Abdera();
        AbderaClient client = new AbderaClient(abdera);         
        AbderaClient.registerTrustManager();
        System.out.println("pd --->"+pd);
        client.addCookie("poktam2cl.iespc.ibm.com", "PD-S-SESSION-ID", pd, "/", null, true);

        RequestOptions requestOptions = client.getDefaultRequestOptions();
        requestOptions.setUseChunked(true);
        requestOptions.setHeader("Connection", "close");
        requestOptions.setHeader("Content-Type", "multipart/related;type=\"application/atom+xml\"");
                       
        requestOptions.setContentType("multipart/related;type=\"application/atom+xml\"");
        requestOptions.setSlug("Sample.txt");


        Credentials credentials = new UsernamePasswordCredentials(username, password);
        client.addCredentials(createEntryLocal, AuthScope.ANY_REALM,AuthScope.ANY_SCHEME,
credentials);

        Entry entry = abdera.getFactory().newEntry();
        entry.setTitle("create entry with attachment title ");
        entry.setContent("create entry with attachment content");

        javax.xml.namespace.QName field = new QName("http://www.ibm.com/xmlns/prod/sn", "field",
"snx");
        org.apache.abdera.model.Element fieldElement = entry.addExtension(field);
        fieldElement.setAttributeValue("type", "file");
        fieldElement.setAttributeValue("name", "sampletextfile1");
        fieldElement.setAttributeValue("position", "3000");

        FileInputStream fis = new FileInputStream(filepath);
        requestOptions.setHeader("Content-Length", "35");

        entry.addCategory("http://www.ibm.com/xmlns/prod/sn/type","entry", "Entry");

        ClientResponse response = client.post(createEntryLocal, entry, fis, "multipart/related;type=\"application/atom+xml\"",
requestOptions );

        System.out.println("Entry Created with attachment's resp: " + response.getStatus());

        if(response.getStatus() == 201){
            System.out.println("Entry Created with attachment successfully .....");
            printIBMConnectionErrorMessage(response);
        }else{
            System.out.println("Entry with attachment creation failed");
            printIBMConnectionErrorMessage(response);
            //System.exit(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
} 

Output:

java.lang.NullPointerException
at org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity.writeInput(MultipartRelatedRequestEntity.java:74)
at org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity.writeRequest(MultipartRelatedRequestEntity.java:59)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.abdera.protocol.client.AbderaClient.execute(AbderaClient.java:688)
at org.apache.abdera.protocol.client.AbderaClient.post(AbderaClient.java:306)
at JavaAgentEntryWithAttachment.createEntryWithAttachment(JavaAgentEntryWithAttachment.java:157)
at JavaAgentEntryWithAttachment.main(JavaAgentEntryWithAttachment.java:66)

This exception is coming from abdera API, class called MultipartRelatedRequestEntity.java,
Line no 74. I have placed line no 74 source code below. So its clear that contentSrc is null
& Abdera API not allowing me to set this value. Please let me know what I am missing here.

String contentId = entry.getContentSrc().toString();



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message