Ravi R
Ravi R

Reputation: 23

How to pass a single argument that should have three values in Java?

I have to call a webservice, that takes only one argument, but that argument should contain three values(UserName,Password,company) inside it. How can I achieve this in Java?

Upvotes: 0

Views: 215

Answers (2)

Afsin Buyuksarac
Afsin Buyuksarac

Reputation: 298

Depending on the webservice method, this solution covers REST webservices. This is a GET example.

@GET
@Path("/{id}/{name}")
@Produces({MediaType.APPLICATION_XML})
public Person fetchPerson(
          @PathParam("id") Integer id,
          @PathParam("name") String name) {

Upvotes: 0

Mureinik
Mureinik

Reputation: 311018

The "Java" way of doing this would be to construct a class that wraps these three values:

public class UserData {
    private String username;
    private String password;
    private String company;

    /* Constructor from the three parameters, getters, and possibly setters */
}

If you don't want to go through the hassle of creating a specific class for it, you could use some other, more generic, container, such as Apache Commons Lang's Triple.

Upvotes: 1

Related Questions