0

Following is my code to handle Multipart using httpclient

if(methodParams.getDataType().length()>0 && methodParams.getDataType().equals("org.springframework.web.multipart.MultipartFile")){
                isMultipart = true; 
                MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
                // For usual String parameters
                entity.addPart( methodParams.getVariableDefined(), new StringBody("".toString() , "text/plain", Charset.forName( "UTF-8" )));
                postURL.setEntity( entity );
             }

but i get the following exception :

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.james.mime4j.util.CharsetUtil.getCharset(Ljava/lang/String;)Ljava/nio/charset/Charset;
    at org.apache.http.entity.mime.MIME.<clinit>(MIME.java:51)
    at org.apache.http.entity.mime.HttpMultipart.<clinit>(HttpMultipart.java:85)
    at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:77)
    at org.apache.http.entity.mime.MultipartEntity.<init>(MultipartEntity.java:96)
    at com.hexgen.tools.HexgenClassUtils.doPOST(HexgenClassUtils.java:151)
    at com.hexgen.reflection.HttpClientRequests.handleHTTPRequest(HttpClientRequests.java:74)
    at com.hexgen.reflection.HexgenWebAPITest.main(HexgenWebAPITest.java:115)

EDIT:

following are the dependency i use

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.0.1</version>
</dependency>

how to solve this.

9
  • You are using incompatible versions of httpmime and apache-mime4j I supose. Commented May 2, 2013 at 7:21
  • Please have a look at my edit Commented May 2, 2013 at 7:52
  • Alright, so there are some reasons to use 4.0.1 instead of the newest version? Commented May 2, 2013 at 8:36
  • 4.2.5 should work just fine ;) Commented May 2, 2013 at 8:39
  • And you may also remove dependency on httpclient since httpmime depends on it. Commented May 2, 2013 at 8:43

1 Answer 1

1

You can take a look at dependencies one more time, perhaps you've missed some jars.

You may also replace your old jars with newer version of a httpclient along with httpmime. httpclient is no longer relying on james mime4j since version 4.1.

You may also end up managing your dependencies with maven. Just in case if you are not using it.

Edit:

You may add the following

<dependency>
    <groupId>org.apache.james</groupId>
    <artifactId>apache-mime4j</artifactId>
    <version>0.6</version>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.