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); } }
throw ServiceException.createFromXML(new InputSource(httpResponse.getContent()));
public SessionInfo getSession(String version, Credential credential) throws ClientException, ServiceException { String authMethodUrn = guessAuthenticationMethodUrn(credential); // FIXME: if type of the credential is not given, the was urn is used. String authnMethod = authMethodUrn == null ? WASAuthenticationMethod.URN : authMethodUrn; String encodedCredential = getCredentialFactory().encode(authnMethod, credential); HTTPRequest httpRequest = httpClientFactory.create(getWssURLString()).post() .contentType("application/x-www-form-urlencoded", "UTF-8") .parameter("VERSION", version, "CREDENTIALS", encodedCredential, "SERVICE", "WSS", "REQUEST", "GetSession", "AUTHMETHOD", "authnMethod"); HTTPResponse<InputStream> httpResponse = httpRequest.asStream().start(); if (httpResponse.isError()) { LOG.error(httpResponse.getError().getMessage(), httpResponse.getError()); throw new ClientException("I/O exception during GETSESSION request to Security Service:\n" + httpResponse.getError(), ClientException.CONNECTION_FAILED); } String contentType = httpResponse.getContentType(); if (contentType.startsWith("text/xml")) { return SessionInfo.createFromXML(httpResponse.getContent()); } else if (contentType.startsWith("application/vnd.ogc.se_xml")) { throw ServiceException.createFromXML(new InputSource(httpResponse.getContent())); } else { LOG.error("GetSession response contained no session information. Response is: " + StringUtils.streamToString(httpResponse.getContent(), "UTF-8")); throw new ClientException("Security Service response specifies unknown/unexpected MIME type: " + contentType + ". Session information unavailable.", ClientException.UNEXPECTED_MIME_TYPE); } }