@Override public void setMethod(String meth) { client.setMethod(meth); }
@Override public void setQueryParams(String q) { client.setQueryParams(q); }
@Override public void addHeader(String tag, String value) { client.addHeader(tag, value); }
private static void dme2RawTest(DME2Manager dm, String aafurl, String user, String pass) { try { if(dm==null) { return; } URI uri = new URI(aafurl); print(true,"DME2 Direct Client Coding Methodology",uri.toString()); DME2Client client = dm.newClient( uri, 3000); client.setMethod("GET"); // FYI, DME2 defaults to "POST" client.setContext("/authz/perms/user/"+user); // DME2 direct requires separate setting of Context from URI if(pass!=null) { // rely on Cert if no pass client.setCredentials(user, pass); } client.setPayload(""); // DME2 will not send without something String resp = client.sendAndWait(7000); System.out.println(resp); } catch(Throwable e) { e.printStackTrace(); } } }
public DME2Locator(Access access, DME2Manager dm, String service, String version, String envContext, String routeOffer, boolean removeSelf) throws DME2Exception, UnknownHostException, LocatorException { this.access = access; if(dm==null) { this.dm = new DME2Manager("DME2Locator created DME2Manager",System.getProperties()); } else { this.dm = dm; } this.service = service; this.version = version; this.envContext = envContext; this.routeOffer = routeOffer; refresh(); DME2Server server = dm.getServer(); if(server == null) { thisMachine = InetAddress.getLocalHost().getHostName(); thisPort = 0; } else { try { thisMachine = server.getServerProperties().getHostname(); //thisPort = server.getPort(); thisPort = server.getServerProperties().getPort(); } catch(NullPointerException np) { // BAD BOY, DME2... access.log(Level.ERROR, "WARNING: DME2 threw a NullPointer Exception getting Server Machine and Port"); thisMachine = InetAddress.getLocalHost().getHostName(); thisPort = 0; } } this.removeSelf = removeSelf; }
@Override public void invalidate() throws CadiException { try { manager.refresh(); } catch (Exception e) { throw new CadiException(e); } }
public DME2Locator(Access access, DME2Manager dm, String service, String version, String envContext, String routeOffer, boolean removeSelf) throws DME2Exception, UnknownHostException, LocatorException { this.access = access; if(dm==null) { this.dm = new DME2Manager("DME2Locator created DME2Manager",System.getProperties()); } else { this.dm = dm; } this.service = service; this.version = version; this.envContext = envContext; this.routeOffer = routeOffer; refresh(); if(thisMachine==null) { // Can't get from dm... thisMachine = InetAddress.getLocalHost().getHostName(); thisPort = 0; } else { thisPort = dm.getPort(); } this.removeSelf = removeSelf; }
private DME2Manager newManager(PropAccess access) throws CadiException { Properties props = access.getDME2Properties(); // Critical that TLS Settings not ignored try { return new DME2Manager("AAFCon",props); } catch (DME2Exception e) { throw new CadiException(e); } }
/** * DME2 can't handle having QueryParams on the URL line, but it is the most natural way, so... * * Also, DME2 can't handle "/proxy" as part of Context in the main URI line, so we add it when we see authz-gw to "isProxy" */ public void setPathInfo(String pathinfo) { int qp = pathinfo.indexOf('?'); if(qp<0) { client.setContext(isProxy?("/proxy"+pathinfo):pathinfo); } else { client.setContext(isProxy?("/proxy"+pathinfo.substring(0,qp)):pathinfo.substring(0,qp)); client.setQueryParams(pathinfo.substring(qp+1)); } }
/** * unpublishing endpoints */ public void unPublishEndPoints() { DME2Manager manager; try { System.setProperty("AFT_LATITUDE", latitude); System.setProperty("AFT_LONGITUDE", longitude); System.setProperty("AFT_ENVIRONMENT", "AFTUAT"); manager = DME2Manager.getDefaultInstance(); DME2EndpointRegistry svcRegistry = manager.getEndpointRegistry(); svcRegistry.unpublish(serviceURL, hostName, Integer.parseInt(port)); } catch (DME2Exception e) { LOG.error("Failed due to DME2Exception" + e); } }
@Override public boolean refresh() { try { dm.refresh(); endpoints = dm.findEndpoints(service, version, envContext, routeOffer, true); if(removeSelf) { for(int i=0;i<endpoints.length;++i) { if(endpoints[i].getPort()==thisPort && endpoints[i].getHost().equals(thisMachine)) endpoints[i]=null; } } return endpoints.length!=0; } catch (Exception e) { access.log(Level.ERROR, e.getMessage()); } return false; }
public DEClient(DME2Manager manager, SecuritySetter<DME2Client> ss, URI uri, long timeout) throws DME2Exception, CadiException { client = new DME2Client(manager,uri,timeout); client.setAllowAllHttpReturnCodes(true); this.ss = ss; ss.setSecurity(client); replyHandler = new DME2RestfulHandler(Rcli.BLANK); client.setReplyHandler(replyHandler); }
@Override public void setSecurity(DME2Client client) { try { client.setCredentials(user, access.decrypt(crd, false)); } catch (IOException e) { access.log(Level.ERROR,e,"Error decrypting DME2 Password"); } }
private static void dme2RawTest(DME2Manager dm, String aafurl, String user, String pass) { try { if(dm==null) { return; } URI uri = new URI(aafurl); print(true,"DME2 Direct Client Coding Methodology",uri.toString()); DME2Client client = dm.newClient( uri, 3000); client.setMethod("GET"); // FYI, DME2 defaults to "POST" client.setContext("/authz/perms/user/"+user); // DME2 direct requires separate setting of Context from URI if(pass!=null) { // rely on Cert if no pass client.setCredentials(user, pass); } client.setPayload(""); // DME2 will not send without something String resp = client.sendAndWait(7000); System.out.println(resp); } catch(Throwable e) { e.printStackTrace(); } } }
@Override public boolean refresh() { try { dm.refresh(); //endpoints = dm.findEndpoints(service, version, envContext, routeOffer, true); if(removeSelf) { // for(int i=0;i<endpoints.length;++i) { // if(endpoints[i].getPort()==thisPort && endpoints[i].getHost().equals(thisMachine)) // endpoints[i]=null; } //} //return endpoints.length!=0; } catch (Exception e) { access.log(Level.ERROR, e.getMessage()); } return false; }
private DME2Manager newManager(PropAccess access) throws CadiException { Properties props = access.getDME2Properties(); // Critical that TLS Settings not ignored try { return new DME2Manager("AAFCon",props); } catch (DME2Exception e) { throw new CadiException(e); } }
public void setSecurity(DME2Client client) throws CadiException { if(isDenied()) { throw new CadiException(REPEAT_OFFENDER); } client.addHeader("Authorization", headValue); } }
@Override public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException { // NOTE: DME2 had Retry Logic embedded lower. try { return (retryable.code(rclient(initURI,ss))); } catch (ConnectException e) { // DME2 should catch try { manager.refresh(); } catch (Exception e1) { throw new CadiException(e1); } throw new CadiException(e); } }
@Override public void setSecurity(DME2Client client) throws CadiException { if(value!=null) { if(defSS==null) { throw new CadiException("Need App Credentials to send message"); } defSS.setSecurity(client); client.addHeader(Config.CADI_USER_CHAIN, value); } }
@Override public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException { // NOTE: DME2 had Retry Logic embedded lower. try { return (retryable.code(rclient(initURI,ss))); } catch (ConnectException e) { // DME2 should catch try { manager.refresh(); } catch (Exception e1) { throw new CadiException(e1); } throw new CadiException(e); } }