title: call a REST webservice from an other project
body: <p>I  have a rest webservice java class implemented in a project called pmtv2, and i want to call it from an other class in an other project called sigac as you can see in the picture.<a href="https://i.stack.imgur.com/5qO78.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5qO78.jpg" alt="enter image description here"></a></p>
  
  <p>here it is the WService class included in a package in pmtv2</p>
  
  <pre><code>package cat.diba.jee.pmtv2.ws.rest;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  import net.sf.json.JSONObject;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import cat.diba.jee.pmtv2.ws.rest.manager.RealitzarExpedientManager;
  import cat.diba.jee.pmtv2.ws.rest.manager.RealitzarTramitManager;
  import cat.diba.jee.pmtv2.ws.rest.message.RestMessage;
  import cat.diba.jee.pmtv2.ws.rest.object.RespostaExpedient;
  import cat.diba.jee.pmtv2.ws.rest.object.RespostaRealitzarTramit;
  import cat.diba.jee.pmtv2.ws.rest.utils.TokenUtils;
  
  /**
   * The Class PmtRestWsService.
   */
  @Path("/tramitacio")
  public class PmtRestWsService {
  
      /**
       * The Constant CLASS_ID.
       */
      private static final String CLASS_ID = PmtRestWsService.class.getName();
  
      /**
       * Log de la classe.
       */
      private static final Log LOG = LogFactory.getLog(CLASS_ID);
  
      /**
       * The Constant PARAM_SESSION.
       */
      private static final String PARAM_SESSION = "session";
  
      /**
       * The Constant PARAM_TOKEN.
       */
      private static final String PARAM_TOKEN = "token";
  
      /**
       * The Constant PARAM_USERNAME.
       */
      private static final String PARAM_USERNAME = "username";
  
      /**
       * The Constant PARAM_TRAMITS.
       */
      private static final String PARAM_TRAMITS = "tramits";
  
      /**
       * The constants PARAM_EXPEDIENTS
       */
      private static final String PARAM_EXPEDIENTS = "expedients";
  
      /**
       * Realitzar tramit.
       *
       * @param params the params
       * @return the pmt expedient
       */
      @POST
      @Path("/realitzarTramit")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces("application/json,application/xml")
      public RespostaRealitzarTramit realitzarTramit(String params) {
          LOG.debug("Parametres = " + params);
  
          RealitzarTramitManager manager = new RealitzarTramitManager();
          RespostaRealitzarTramit resposta = new RespostaRealitzarTramit();
  
          JSONObject jsonObject = new JSONObject(params);
          try {
              if (validarParametresEntrada(jsonObject)) {
                  String session = jsonObject.getString(PARAM_SESSION);
                  String token = jsonObject.getString(PARAM_TOKEN);
                  if (TokenUtils.validarToken(session, token)) {
                      resposta = manager.realitzarTramits(jsonObject, jsonObject.getString(PARAM_USERNAME));
                  } else {
                      //Token no validat
                      resposta.setTramitOK(false);
                      resposta.setError(RestMessage.ERROR_TOKEN_INVALID.getMessage());
                  }
              } else {
                  //Paràmetres invàlids
                  resposta.setTramitOK(false);
                  resposta.setError(RestMessage.ERROR_REALITZAR_TRAMIT_PARAMETRES_ENTRADA.getMessage());
              }
          } catch (Exception e) {
              // Errors als paràmetres d'entrada
              LOG.error("ERROR : " + e.getMessage() + " - ORIGEN : " + e.getStackTrace()[0]);
              resposta.setTramitOK(false);
              resposta.setError(RestMessage.ERROR_REALITZAR_TRAMIT_NO_CONTROLAT.getMessage());
              return resposta;
          }
          return resposta;
      }
  
      /**
       * Realitzar tramit.
       *
       * @param params the params
       * @return the pmt expedient
       */
      @POST
      @Path("/expedient")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces("application/json,application/xml")
      public RespostaExpedient realitzarExpedient(String params) {
          LOG.debug("Parametres = " + params);
  
          RealitzarExpedientManager manager = new RealitzarExpedientManager();
          RespostaExpedient resposta = new RespostaExpedient();
  
          JSONObject jsonObject = new JSONObject(params);
          try {
              if (validarParametresEntradaExpedient(jsonObject)) {
                  String session = jsonObject.getString(PARAM_SESSION);
                  String token = jsonObject.getString(PARAM_TOKEN);
                  if (TokenUtils.validarToken(session, token)) {
                      resposta = manager.realitzarExpedients(jsonObject, jsonObject.getString(PARAM_USERNAME));
                  } else {
                      //Token no validat
                      resposta.setExpedientOK(false);
                      resposta.setCodiError(901);
                      resposta.setError(RestMessage.ERROR_TOKEN_INVALID.getMessage());
                  }
              } else {
                  //Paràmetres invàlids
                  resposta.setExpedientOK(false);
                  resposta.setCodiError(902);
                  resposta.setError(RestMessage.ERROR_REALITZAR_EXPEDIENT_PARAMETRES_ENTRADA.getMessage());
              }
          } catch (Exception e) {
              // Errors als paràmetres d'entrada
              LOG.error("ERROR : " + e.getMessage() + " - ORIGEN : " + e.getStackTrace()[0]);
              resposta.setExpedientOK(false);
              resposta.setCodiError(998);
              resposta.setError(RestMessage.ERROR_REALITZAR_EXPEDIENT_NO_CONTROLAT.getMessage());
              return resposta;
          }
          return resposta;
      }
  
      /**
       * validacio de entrada de expedients
       * 
       * @param jsonObject
       * @return
       */
      private boolean validarParametresEntradaExpedient(JSONObject jsonObject) {
          LOG.debug("validarPeticio(jsonObject) - Inici");
  
          boolean result = true;
          try {
              jsonObject.getJSONArray(PARAM_EXPEDIENTS);
              jsonObject.getString(PARAM_USERNAME);
              jsonObject.getString(PARAM_SESSION);
              jsonObject.getString(PARAM_TOKEN);
          } catch (Exception e) {
              result = false;
          }
  
          LOG.debug("validarParametresEntrada(jsonObject) - Fi");
          return result;
      }
  
      /**
       * Validar parametres entrada.
       *
       * @param jsonObject the json object
       * @return true, if successful
       */
      private boolean validarParametresEntrada(final JSONObject jsonObject) {
          LOG.debug("validarPeticio(jsonObject) - Inici");
  
          boolean result = true;
          try {
              jsonObject.getJSONArray(PARAM_TRAMITS);
              jsonObject.getString(PARAM_USERNAME);
              jsonObject.getString(PARAM_SESSION);
              jsonObject.getString(PARAM_TOKEN);
          } catch (Exception e) {
              result = false;
          }
  
          LOG.debug("validarParametresEntrada(jsonObject) - Fi");
          return result;
      }
  }
  </code></pre>
  
  <p>is there any way to do it  ??</p>