use of okhttp3.Address in project oxTrust by GluuFederation.
the class PatchUtil method removePatch.
public GluuCustomPerson removePatch(User source, GluuCustomPerson destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new GluuCustomPerson();
}
log.trace(" setting schemas ");
destination.setSchemas(source.getSchemas());
personService.addCustomObjectClass(destination);
log.trace(" setting userName ");
if (source.getUserName() != null && source.getUserName().length() > 0) {
destination.setUid(source.getUserName());
}
if (source.getName() != null) {
log.trace(" setting givenname ");
if (source.getName().getGivenName() != null) {
destination.setGivenName("");
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null) {
destination.setSurname("");
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null) {
// destination.setAttribute("oxTrustMiddleName",
// source.getName().getMiddleName());
destination.setAttribute("middleName", "");
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null) {
destination.setAttribute("oxTrusthonorificPrefix", "");
}
if (source.getName().getHonorificSuffix() != null) {
destination.setAttribute("oxTrusthonorificSuffix", "");
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null) {
// destination.setAttribute("oxTrustNickName",
// source.getNickName());
destination.setAttribute("nickname", "");
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null) {
destination.setAttribute("oxTrustProfileURL", "");
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
if (emails != null && emails.size() > 0) {
List<Email> newemails = source.getEmails();
Iterator<Email> emailsIt = emails.iterator();
Iterator<Email> newemailsIt = newemails.iterator();
while (emailsIt.hasNext()) {
Email email = emailsIt.next();
if (email != null && email.getType() != null) {
while (newemailsIt.hasNext()) {
Email newEmail = newemailsIt.next();
if (newEmail.getType() != null && newEmail.getType().getValue().equals(email.getType().getValue())) {
emailsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
}
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
if (addresses != null && addresses.size() > 0) {
List<Address> newaddresses = source.getAddresses();
Iterator<Address> addressesIt = addresses.iterator();
Iterator<Address> newaddressesIt = newaddresses.iterator();
while (addressesIt.hasNext()) {
Address address = addressesIt.next();
if (address != null && address.getType() != null) {
while (newaddressesIt.hasNext()) {
Address newaddress = newaddressesIt.next();
if (newaddress.getType().getValue() != null && newaddress.getType().getValue().equals(address.getType().getValue())) {
addressesIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
}
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
if (phoneNumbers != null && phoneNumbers.size() > 0) {
List<PhoneNumber> newPhoneNumbers = source.getPhoneNumbers();
Iterator<PhoneNumber> phoneNumbersIt = phoneNumbers.iterator();
Iterator<PhoneNumber> newPhoneNumbersIt = newPhoneNumbers.iterator();
while (phoneNumbersIt.hasNext()) {
PhoneNumber phoneNumber = phoneNumbersIt.next();
while (newPhoneNumbersIt.hasNext()) {
PhoneNumber newPhoneNumber = newPhoneNumbersIt.next();
if (newPhoneNumber.getType() != null && newPhoneNumber.getType().getValue().equals(phoneNumber.getType().getValue())) {
phoneNumbersIt.remove();
}
}
}
copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
}
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
if (ims != null && ims.size() > 0) {
List<Im> newims = source.getIms();
Iterator<Im> imsIt = ims.iterator();
Iterator<Im> newimssIt = newims.iterator();
while (imsIt.hasNext()) {
Im im = imsIt.next();
if (im != null && im.getType() != null) {
while (newimssIt.hasNext()) {
Im newIm = newimssIt.next();
if (newIm.getType() != null && newIm.getType().getValue().equals(im.getType().getValue())) {
imsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
}
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
if (photos != null && photos.size() > 0) {
List<Photo> newPhotos = source.getPhotos();
Iterator<Photo> photosIt = photos.iterator();
Iterator<Photo> newphotosIt = newPhotos.iterator();
while (photosIt.hasNext()) {
Photo old = photosIt.next();
if (old != null && old.getType() != null) {
while (newphotosIt.hasNext()) {
Photo newelement = newphotosIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
photosIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
}
}
if (source.getUserType() != null) {
destination.setAttribute("oxTrustUserType", "");
}
if (source.getTitle() != null) {
destination.setAttribute("oxTrustTitle", "");
}
if (source.getPreferredLanguage() != null) {
destination.setPreferredLanguage("");
}
if (source.getLocale() != null) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", "");
}
if (source.getTimezone() != null) {
destination.setTimezone("");
}
if (source.isActive() != null) {
destination.setAttribute("oxTrustActive", source.isActive().toString());
}
if (source.getPassword() != null && source.getPassword().length() > 0) {
destination.setUserPassword(source.getPassword());
}
// getting user groups
log.trace(" setting groups ");
if (source.getGroups() != null && source.getGroups().size() > 0) {
List<String> members = destination.getMemberOf();
if (members != null || members.size() > 0) {
members.removeAll(source.getGroups());
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
if (roles != null && roles.size() > 0) {
List<Role> newRoles = source.getRoles();
Iterator<Role> oldsIt = roles.iterator();
Iterator<Role> newsIt = newRoles.iterator();
while (oldsIt.hasNext()) {
Role old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
Role newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
}
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
if (entitlements != null && entitlements.size() > 0) {
List<Entitlement> newEentitlements = source.getEntitlements();
Iterator<Entitlement> oldsIt = entitlements.iterator();
Iterator<Entitlement> newsIt = newEentitlements.iterator();
while (oldsIt.hasNext()) {
Entitlement old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
Entitlement newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
}
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
if (X509Certificates != null && X509Certificates.size() > 0) {
List<X509Certificate> newX509Certificates = source.getX509Certificates();
Iterator<X509Certificate> oldsIt = X509Certificates.iterator();
Iterator<X509Certificate> newsIt = newX509Certificates.iterator();
while (oldsIt.hasNext()) {
X509Certificate old = oldsIt.next();
if (old != null && old.getType() != null) {
while (newsIt.hasNext()) {
X509Certificate newelement = newsIt.next();
if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
oldsIt.remove();
}
}
}
}
copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
}
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
if (source.isActive() != null) {
copyUtils2.setGluuStatus(source, destination);
}
return destination;
}
use of okhttp3.Address in project chefly_android by chef-ly.
the class HttpConnection method downloadFromFeed.
public String downloadFromFeed(RequestMethod requestPackage) throws IOException {
String address = requestPackage.getEndpoint();
String encodedParams = requestPackage.getEncodedParams();
//check for get request
if (requestPackage.getMethod().equals("GET") && encodedParams.length() > 0) {
address = String.format("%s?%s", address, encodedParams);
}
//create request object
OkHttpClient client;
if (BuildConfig.DEBUG) {
client = new OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).build();
} else {
client = new OkHttpClient();
}
Request.Builder requestBuilder = new Request.Builder().url(address);
// Add required HTTP Header
Map<String, String> headers = requestPackage.getHeaders();
if (headers.size() > 0) {
for (String k : headers.keySet()) {
if (k != null) {
requestBuilder.addHeader(k, headers.get(k));
}
}
}
//check for post request
if (requestPackage.getMethod().equals("POST")) {
//extract the parameters from the request
//get the reference of the pair
Map<String, String> params = requestPackage.getParams();
String msg = "";
if (params.size() == 1) {
for (String key : params.keySet()) msg = params.get(key);
} else {
JSONObject parameter = new JSONObject(params);
msg = parameter.toString();
}
RequestBody body = RequestBody.create(JSON, msg);
Log.d(TAG, msg);
requestBuilder.post(body);
//requestBuilder.addHeader("content-type", "application/json; charset=utf-8");
requestBuilder.addHeader("content-type", "application/x-www-form-urlencoded");
}
Request request = requestBuilder.build();
//get response with the use of the method newCall
//synchronous request
Response response = client.newCall(request).execute();
//check if the request is successful
if (response.isSuccessful()) {
this.statusMessage = response.message();
return response.body().string();
} else {
Log.d(TAG, response.toString());
throw new IOException("Exception: response code " + response.code());
}
}
use of okhttp3.Address in project zipkin by openzipkin.
the class PseudoAddressRecordSet method create.
static Dns create(List<String> urls, Dns actualDns) {
Set<String> schemes = new LinkedHashSet<>();
Set<String> hosts = new LinkedHashSet<>();
Set<InetAddress> ipAddresses = new LinkedHashSet<>();
Set<Integer> ports = new LinkedHashSet<>();
for (String url : urls) {
HttpUrl httpUrl = HttpUrl.parse(url);
schemes.add(httpUrl.scheme());
// Kick out if we can't cheaply read the address
byte[] addressBytes = null;
try {
addressBytes = ipStringToBytes(httpUrl.host());
} catch (RuntimeException e) {
}
if (addressBytes != null) {
try {
ipAddresses.add(InetAddress.getByAddress(addressBytes));
} catch (UnknownHostException e) {
hosts.add(httpUrl.host());
}
} else {
hosts.add(httpUrl.host());
}
ports.add(httpUrl.port());
}
checkArgument(ports.size() == 1, "Only one port supported with multiple hosts %s", urls);
checkArgument(schemes.size() == 1 && schemes.iterator().next().equals("http"), "Only http supported with multiple hosts %s", urls);
if (hosts.isEmpty())
return new StaticDns(ipAddresses);
return new ConcatenatingDns(ipAddresses, hosts, actualDns);
}
use of okhttp3.Address in project graylog2-server by Graylog2.
the class IndexerSetupService method startUp.
@Override
protected void startUp() throws Exception {
Tools.silenceUncaughtExceptionsInThisThread();
LOG.debug("Starting indexer");
node.start();
final Client client = node.client();
try {
/* try to determine the cluster health. if this times out we could not connect and try to determine if there's
anything listening at all. if that happens this usually has these reasons:
1. cluster.name is different
2. network.publish_host is not reachable
3. wrong address configured
4. multicast in use but broken in this environment
we handle a red cluster state differently because if we can get that result it means the cluster itself
is reachable, which is a completely different problem from not being able to join at all.
*/
final ClusterHealthRequest atLeastRed = client.admin().cluster().prepareHealth().setWaitForStatus(ClusterHealthStatus.RED).request();
final ClusterHealthResponse health = client.admin().cluster().health(atLeastRed).actionGet(configuration.getClusterDiscoveryTimeout(), MILLISECONDS);
// we don't get here if we couldn't join the cluster. just check for red cluster state
if (ClusterHealthStatus.RED.equals(health.getStatus())) {
final Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.URGENT).addType(Notification.Type.ES_CLUSTER_RED);
notificationService.publishIfFirst(notification);
LOG.warn("The Elasticsearch cluster state is RED which means shards are unassigned.");
LOG.info("This usually indicates a crashed and corrupt cluster and needs to be investigated. Graylog will write into the local disk journal.");
LOG.info("See {} for details.", DocsHelper.PAGE_ES_CONFIGURATION);
}
if (ClusterHealthStatus.GREEN.equals(health.getStatus())) {
notificationService.fixed(Notification.Type.ES_CLUSTER_RED);
}
notificationService.fixed(Notification.Type.ES_UNAVAILABLE);
} catch (ElasticsearchTimeoutException e) {
final String hosts = node.settings().get("discovery.zen.ping.unicast.hosts");
if (!isNullOrEmpty(hosts)) {
final Iterable<String> hostList = Splitter.on(',').omitEmptyStrings().trimResults().split(hosts);
for (String host : hostList) {
final URI esUri = URI.create("http://" + HostAndPort.fromString(host).getHostText() + ":9200/");
LOG.info("Checking Elasticsearch HTTP API at {}", esUri);
// Try the HTTP API endpoint
final Request request = new Request.Builder().get().url(esUri.resolve("/_nodes").toString()).build();
try (final Response response = httpClient.newCall(request).execute()) {
if (response.isSuccessful()) {
final JsonNode resultTree = objectMapper.readTree(response.body().byteStream());
final JsonNode nodesList = resultTree.get("nodes");
if (!configuration.isDisableVersionCheck()) {
final Iterator<String> nodes = nodesList.fieldNames();
while (nodes.hasNext()) {
final String id = nodes.next();
final Version clusterVersion = Version.fromString(nodesList.get(id).get("version").textValue());
checkClusterVersion(clusterVersion);
}
}
final String clusterName = resultTree.get("cluster_name").textValue();
checkClusterName(clusterName);
} else {
LOG.error("Could not connect to Elasticsearch at " + esUri + ". Is it running?");
}
} catch (IOException ioException) {
LOG.error("Could not connect to Elasticsearch: {}", ioException.getMessage());
}
}
}
final Notification notification = notificationService.buildNow().addSeverity(Notification.Severity.URGENT).addType(Notification.Type.ES_UNAVAILABLE);
notificationService.publishIfFirst(notification);
LOG.warn("Could not connect to Elasticsearch");
LOG.info("If you're using multicast, check that it is working in your network and that Elasticsearch is accessible. Also check that the cluster name setting is correct.");
LOG.info("See {} for details.", DocsHelper.PAGE_ES_CONFIGURATION);
}
}
use of okhttp3.Address in project okhttp by square.
the class MockWebServer method start.
/**
* Starts the server and binds to the given socket address.
*
* @param inetSocketAddress the socket address to bind the server on
*/
private synchronized void start(InetSocketAddress inetSocketAddress) throws IOException {
if (started)
throw new IllegalStateException("start() already called");
started = true;
executor = Executors.newCachedThreadPool(Util.threadFactory("MockWebServer", false));
this.inetSocketAddress = inetSocketAddress;
serverSocket = serverSocketFactory.createServerSocket();
// Reuse if the user specified a port
serverSocket.setReuseAddress(inetSocketAddress.getPort() != 0);
serverSocket.bind(inetSocketAddress, 50);
port = serverSocket.getLocalPort();
executor.execute(new NamedRunnable("MockWebServer %s", port) {
@Override
protected void execute() {
try {
logger.info(MockWebServer.this + " starting to accept connections");
acceptConnections();
} catch (Throwable e) {
logger.log(Level.WARNING, MockWebServer.this + " failed unexpectedly", e);
}
// Release all sockets and all threads, even if any close fails.
closeQuietly(serverSocket);
for (Iterator<Socket> s = openClientSockets.iterator(); s.hasNext(); ) {
closeQuietly(s.next());
s.remove();
}
for (Iterator<Http2Connection> s = openConnections.iterator(); s.hasNext(); ) {
closeQuietly(s.next());
s.remove();
}
dispatcher.shutdown();
executor.shutdown();
}
private void acceptConnections() throws Exception {
while (true) {
Socket socket;
try {
socket = serverSocket.accept();
} catch (SocketException e) {
logger.info(MockWebServer.this + " done accepting connections: " + e.getMessage());
return;
}
SocketPolicy socketPolicy = dispatcher.peek().getSocketPolicy();
if (socketPolicy == DISCONNECT_AT_START) {
dispatchBookkeepingRequest(0, socket);
socket.close();
} else {
openClientSockets.add(socket);
serveConnection(socket);
}
}
}
});
}
Aggregations