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

  • Home
  • SEARCH
  • 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 6566063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:10:19+00:00 2026-05-25T14:10:19+00:00

I have implement a web service using jersey and I have a client making

  • 0

I have implement a web service using jersey and I have a client making HTTP requests. The web service talks with a database. When the client makes a request, the server through a query retrieves some data from the database(list of contacts). I would like to return these data to the client(as a response). So now i am just trying to send a simple sting array from server to client.

Server Code:

package de.vogella.jersey.first;
import java.util.ArrayList;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello2")
public class Hello2 {
//String msg3[] = {"one", "two"}; 
//ArrayList<String> listitems = new ArrayList<String>();

String msg2 = "message of the server";
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
    System.out.println("TEXT_PLAIN is request Hello_2");
    return "Hello Jersey from Hello_2";
}

@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)   
public String[] authedication(@FormParam("username") String us, @FormParam("password") String pass){ 

    String msg3[] = {"one", "two"}; 
    System.out.println("these are the results of the Hello2");
    System.out.println("--------------------------------------------------");
    System.out.println("The name is \"" + us + "\" is request");
    System.out.println("The password is \"" + pass + "\" is request");
    System.out.println("--------------------------------------------------");

    return msg3;
}

}

Client Code:

  public void addContactsToList(){
  Log.v(TAG, "Load contacts");
  HttpClient client = new DefaultHttpClient();
  EditText etxt_user = (EditText) findViewById(R.id.username);
  EditText etxt_pass = (EditText) findViewById(R.id.password);
  String username1 = etxt_user.getText().toString();
  String password1 = etxt_pass.getText().toString();
  HttpPost httppost = new HttpPost("http://10.0.2.2:8080/de.vogella.jersey.first/rest/hello2");
  Log.v(TAG, "message1");         
  //add your Data
  List< NameValuePair > nvps = new ArrayList< NameValuePair >();
  nvps.add(new BasicNameValuePair("username", username1));
  nvps.add(new BasicNameValuePair("password", password1));

  try {
        UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

        httppost.setEntity(p_entity);
        //Execute HTTP Post Request
        Log.v(TAG, "The request has been sent.");
        HttpResponse response = client.execute(httppost);

        Log.v(TAG, response.getStatusLine().toString());
        HttpEntity responseEntity = response.getEntity();
        //final InputStream inputStream = responseEntity.getContent();

        String x = EntityUtils.toString(responseEntity);

        Log.v(TAG,x);
        removeDialog(1);
        Intent intent=new Intent(getApplicationContext(),TestM_chat4_all_contacts.class);
        intent.putExtra("Contacts",x);
        startActivity(intent);

  } catch (Exception e)
  {
        Intent intent = new Intent(getApplicationContext(), LoginError.class);//calls the activity LoginError.java
        intent.putExtra("LoginMessage", "Unable to load your contacts");
        startActivity(intent);
        removeDialog(0);
   }

}

So can i send an array or an arraylist from the server and how the client reads these data? Also I am thinking to use JSON, is this implemantation(send array) possible using JSON?

Thank you in Advance!

  • 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-05-25T14:10:20+00:00Added an answer on May 25, 2026 at 2:10 pm

    On server you shoud produce JSON

    @Produces(MediaType.APPLICATION_JSON)
    

    Then on client you can use Gson to convert it automatically to Java types. For array you’d use

    String[] result = gson.fromJson(x, String[].class); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a web service with server and client authentication using keytool. The
I have a sql server 7.0 database and I will implement a web service
I am using a javax.servlet.http.HttpServletRequest to implement a web application. I have no problem
I'm using Jersey to create a REST web service for a server component. The
I have implement a small web service using .net 3.5. I have used linq
I have a RESTful web service and a rich client application using it. I
I'm using ASP.NET MVC 2 to implement a web service and I have a
I need to implement a very secured Web Service using WCF. I have read
I have implemented web service using rails server. The server uses rails default authentication
I have a javascript-based client that is currently polling a .NET web service for

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.