public void removeService(final String serviceId, final String serviceVersion) throws ServiceException { final HttpPost post = new HttpPost(ServiceUtils.buildURL(host, port, useSSL, contextRoot + "/server/remove/" + serviceId + "/" + serviceVersion)); try { ServiceUtils.executeRequest(post, useSSL); } catch (final ServiceException e) { throw e; } catch (final Exception e) { throw new ServiceException("Could not remove service " + serviceId + ":" + serviceVersion, e); } }
/** * Add the service for the specified service-bundle to the RestServiceServer at the host and port. * * @param serviceBundlePath the path to the service-bundle * @return the {@link ServiceDescriptor} filled with server parameters * @throws ServiceException */ public RestServiceServerUtil addService(final Path serviceBundlePath) throws ServiceException { try { final HttpPost post = new HttpPost(ServiceUtils.buildURL(host, port, useSSL, contextRoot + "/server/add")); // post.addHeader(HttpHeaders.CONTENT_TYPE, marshaller.getMimeType()); post.addHeader(HttpHeaders.ACCEPT, ServiceUtils.getAcceptedMimeTypes()); post.setEntity(EntityBuilder.create().setBinary(Files.readAllBytes(serviceBundlePath)).build()); ServiceUtils.executeRequest(post, useSSL); return this; } catch (final ServiceException e) { throw e; } catch (final Exception e) { throw new ServiceException("Could not add service-bundle " + serviceBundlePath, e); } }
public static HttpResponse executeRequest(final String host, final int port, final boolean useSSL, final WebCall webCall, final List<String> remoteSupportedMimeTypes, final Serializable entity) throws ServiceException { HttpUriRequest request = null; IMarshaller marshaller = null; // determine the marshaller base on the specified remote mime-types if (remoteSupportedMimeTypes != null) { marshaller = determineCommonMimeType(remoteSupportedMimeTypes); } else if (webCall.getWebMethod().equalsIgnoreCase("POST")) { // if no mime-types were specified and its a POST request, then // throw exception - cannot serialize object without marshaller throw new ServiceException("Cannot call POST web-method without specifying the supported mime-types of the remote server!"); } if (webCall.getWebMethod().equalsIgnoreCase("GET")) { request = new HttpGet(buildURL(host, port, useSSL, webCall.getUri())); } else if (webCall.getWebMethod().equalsIgnoreCase("POST")) { request = new HttpPost(buildURL(host, port, useSSL, webCall.getUri())); ((HttpPost) request).setEntity(EntityBuilder.create().setBinary(marshaller.serialize(entity)).build()); } else if (webCall.getWebMethod().equalsIgnoreCase("DELETE")) { request = new HttpGet(buildURL(host, port, useSSL, webCall.getUri())); } else { throw new ServiceException("Unsupported web-call web method: " + webCall); } if (marshaller != null) { request.addHeader(HttpHeaders.CONTENT_TYPE, marshaller.getMimeType()); } request.addHeader(HttpHeaders.ACCEPT, getAcceptedMimeTypes()); return executeRequest(request, useSSL); }
/** * Gets the fully qualified URL string to the service. * * @param serviceDescriptor the {@link ServiceDescriptor} * @return the URL string */ public static String getServiceURL(final ServiceDescriptor serviceDescriptor) { return buildURL(serviceDescriptor.getHost(), serviceDescriptor.getPort(), serviceDescriptor.isUseSSL(), serviceDescriptor.getServiceUri().getUri()); }