Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8722439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:25:12+00:00 2026-06-13T07:25:12+00:00

I want to test my REST-Service using the RestEasy Client Framework. In my application

  • 0

I want to test my REST-Service using the RestEasy Client Framework.
In my application I am using Basic Authentication. According to the RestEasy documentation I am using the org.apache.http.impl.client.DefaultHttpClient to set the Credentials for Authentication.

For an HTTP-GET Request this works fine, I am authorized and I get the result Response which I wanted.

But what if I want to make a HTTP-Post/HTTP-Put with an Java Object (in XML) in the HTTP-Body of the Request? Is there a way to automatically marshall the Java Object into the HTTP-Body when I am using the org.apache.http.impl.client.DefaultHttpClient?

Here’s my code for authentication, can someone tell me how to make an HTTP-Post/HTTP-Put without writing an XML-String or using an InputStream?

@Test
public void testClient() throws Exception {

        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(
                        new AuthScope(host, port),
                        new UsernamePasswordCredentials(username, password));
        ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(
                        client);
        ClientRequest request = new ClientRequest(requestUrl, executer);
        request.accept("*/*").pathParameter("param", requestParam);

        // This works fine   
        ClientResponse<MyClass> response = request
                        .get(MyClass.class);
        assertTrue(response.getStatus() == 200);

        // What if i want to make the following instead:
        MyClass myClass = new MyClass();
        myClass.setName("AJKL");
        // TODO Marshall this in the HTTP Body => call method 


}

Is there maybe a possibillity to use the Server-side Mock Framework and then marshall and send my object there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:25:13+00:00Added an answer on June 13, 2026 at 7:25 am

    Ok, got it working, thats my new code:

    @Test
    public void testClient() throws Exception {
    
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(
                        new AuthScope(host, port),
                        new UsernamePasswordCredentials(username, password));
        ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(
                        client);
    
    
        RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
    
        Employee employee= new Employee();
        employee.setName("AJKL");
    
        EmployeeResource employeeResource= ProxyFactory.create(
                EmployeeResource.class, restServletUrl, executer);
    
        Response response  = employeeResource.createEmployee(employee);
    
    }
    

    EmployeeResource :

    @Path("/employee")
    public interface EmployeeResource {
    
        @PUT
        @Consumes({"application/json", "application/xml"})
        void createEmployee(Employee employee);
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to test an API using curl for Mac. According to the REST
I'm using REST::Client perl module to test my REST server. I want to print
I'm using the Jersey Client library to run tests against a rest service running
I started a Visual Studio WCF Rest Service Application project where I want to
I want to test the REST api on my Rails site. What is the
I want to test Add new item activity in my application. When user fills
I want to test a REST Resource: @GET @Path(/{dbName}) @Produces(MediaType.APPLICATION_JSON) public String getRequest(@PathParam(dbName) String
I'm putting together a REST service using ASP.NET Web API & Ninject, though I
I am creating a service REST type using WCF in C# Visual Studio 2010
I want to test a class which calls a RESTEasy webservice. It seems Junit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.