private <T> T get(String sessionID, String action, Class<T> expectedResponse) { HTTPClient client = m_clientFactory.create(m_sessionServiceUrl); HTTPRequest request; if (action != null) { request = client.get(sessionID, action); } else { request = client.get(sessionID); } HTTPResponse<T> response = request.as(expectedResponse).start(); if (response.isError()) { throw new InvalidSessionIDException(sessionID, response.getError()); } return response.getContent(); }
HTTPRequest httpRequest = processHttpAttributes(httpClient.get(), requestTransferable);
public WSSCapabilitiesDocument getCapabilities(String version, String service) throws ClientException, ServiceException { HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).get(); httpRequest.parameter("SERVICE", service, "REQUEST", "GetCapabilities"); try { HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (!httpResponse.getStatus().is(200)) { throw new ClientException("Error during WSS GetCapabilities request: " + httpResponse.getStatus().toString()); } String contentType = httpResponse.getContentType(); if (contentType.startsWith("text/xml")) { return WSSCapabilitiesDocument.parse(httpResponse.getContent()); } else if (contentType.startsWith("application/vnd.ogc.se_xml")) { throw ServiceException.createFromXML(new InputSource(httpResponse.getContent())); } else { throw new ClientException("WSS GetCapabilities response must be of MIME type text/xml. Found: " + contentType + ". Capabilities information unavailable.", ClientException.UNEXPECTED_MIME_TYPE); } } catch (Exception e) { LOG.error(e.getMessage(), e); throw new ClientException("Error while processing GETCAPABILITIES response from Security Service:\n" + e.getMessage(), ClientException.CONNECTION_FAILED); } }
/** * Performs the service request "CloseSession". * * @throws ClientException if something went wrong during the request * @throws org.n52.security.common.artifact.ServiceException if the response is of MIME type * <code>application/vnd.ogc.se_xml */ public void closeSession(String version, String sessionID) throws ClientException, ServiceException { HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).get(); httpRequest.parameter("VERSION", version, "SESSIONID", sessionID, "SERVICE", "WSS", "REQUEST", "CloseSession"); HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (httpResponse.isError()) { LOG.error("", httpResponse.getError()); throw new ClientException("I/O exception during CLOSESESSION request to Security Service:\n" + httpResponse.getStatus().getCode() + ": " + ((httpResponse.getError() != null) ? httpResponse.getError().getMessage() : " no exception available")); } }
public Document build() throws WebServiceDescriptionException { requestParameters = requestParameters == null ? new String[0] : requestParameters; HTTPRequest httpRequest = httpClientFactory.create(url).get(); HTTPResponse<InputStream> responseStream = httpRequest.parameter(requestParameters).asStream().start(); if (isInvalidResponse(responseStream)) { LOG.warn("Could not read capabilities from {}" + url); LOG.warn("Http response status code is {}", responseStream.getStatus().getCode()); throw new WebServiceDescriptionException("Could not read capabilities from " + url); } try { response = DOMUtil.createFromStream(responseStream.getContent(), DOMParserOptions.getDefault().expandEntityReferences()); } catch(Exception e) { throw new WebServiceDescriptionException("Could not parse capabilities document: " + e.getMessage()); }finally { requestParameters = null; // reset parameters } if (asIsoDocument) { return buildIsoDocument(); } return response; }
private String getSSOSessionId(String username, char[] password) throws FailedLoginException { HTTPClient client = m_httpClientFactory.create(m_endpoint); HTTPRequest req; switch (m_authnMode) { case AUTHN_MODE_USER_PW: req = client.post().parameter(m_usernameParam, username, m_passwordParam, new String(password)); break; default: req = client.get().basicAuth(username, password); break; } HTTPResponse<String> response = req.asString().start(); if (response.isError()) { if (response.getStatus() == HTTPCode.FORBIDDEN) { throw new FailedLoginException("Wrong credentials"); } LOG.error("Remote service connection failed: " + req.getEndpoint(), response.getError()); throw new FailedLoginException("Remote service connection failed: " + response.getError()); } return response.getContent().trim(); }