/** * Create a new root location * * @param payload * The request body * @param p_request * The request header * @throws JsonParseException * @throws JsonMappingException * @throws IOException * @throws SQLException */ @PUT @Path("location") public Response addLocation(String payload, @Context HttpServletRequest p_request) throws JsonParseException, JsonMappingException, IOException, SQLException { EnOceanStorage l_storage = EnOceanStorage.getInstance(); Location l_location = m_mapper.readValue(payload, Location.class); l_storage.addLocation(l_location); try { DNSUtils.getInstance(EnOceanConfig.getDNSIP(), getIPAddr(), EnOceanConfig.getDNSZone()).addNewHost( l_location.getName().toLowerCase()); } catch (ZoneTransferException e) { logger.error("Add location", e); } return Response.status(checkXToken(p_request)).entity(null).build(); }
/** * Update the specified location * * @param payload * The request body * @param p_id * The location id * @param p_request * The request header * @return Status code (200 or 401) * @throws JsonParseException * @throws JsonMappingException * @throws IOException * @throws SQLException */ @POST @Path("location/{id}") public Response modifyLocation(String payload, @PathParam("id") int p_id, @Context HttpServletRequest p_request) throws JsonParseException, JsonMappingException, IOException, SQLException { Location l_location = m_mapper.readValue(payload, Location.class); EnOceanStorage l_storage = EnOceanStorage.getInstance(); l_storage.updateLocation(l_location, p_id); try { DNSUtils.getInstance(EnOceanConfig.getDNSIP(), getIPAddr(), EnOceanConfig.getDNSZone()).addNewHost( l_location.getName().toLowerCase()); } catch (ZoneTransferException e) { logger.error("Add location", e); } return Response.status(checkXToken(p_request)).entity(null).build(); }
/** * Create a new location * * @param payload * The request body * @param p_parentId * The parent group's id * @param p_request * The request header * @return Satus code (200 or 401) * @throws JsonParseException * @throws JsonMappingException * @throws IOException * @throws SQLException */ @PUT @Path("location/{parentId}") public Response addLocation(String payload, @PathParam("parentId") int p_parentId, @Context HttpServletRequest p_request) throws JsonParseException, JsonMappingException, IOException, SQLException { EnOceanStorage l_storage = EnOceanStorage.getInstance(); Location l_location = m_mapper.readValue(payload, Location.class); String l_fullPath = l_storage.addLocation(l_location, p_parentId); String[] l_pathArray = l_fullPath.split("[.]"); if (EnOceanConfig.getDNSZone().toLowerCase() .startsWith(l_pathArray[l_pathArray.length - 1].toLowerCase())) l_fullPath = l_fullPath.substring(0, l_fullPath.lastIndexOf(".")); try { DNSUtils.getInstance(EnOceanConfig.getDNSIP(), getIPAddr(), EnOceanConfig.getDNSZone()).addNewHost( l_fullPath.toLowerCase()); } catch (ZoneTransferException e) { logger.error("Add location", e); } return Response.status(checkXToken(p_request)).entity(null).build(); }
public static List<ForwardLookupResult> attemptZoneTransfer(String domain, List<ForwardLookupResult> nameServers) throws TextParseException { List<ForwardLookupResult> result = new ArrayList<>(); ZoneTransferIn xfr; Iterator i = nameServers.iterator(); for (ForwardLookupResult nameServer : nameServers) { try { xfr = ZoneTransferIn.newAXFR(new Name(domain), nameServer.getIpAddress(), null); List records = xfr.run(); for (Iterator it = records.iterator(); it.hasNext();) { Record r = (Record) it.next(); if (r.getType() == 1) { ForwardLookupResult rec = new ForwardLookupResult(domain); String hostName = ((ARecord) r).getName().toString().toLowerCase(); if (hostName.endsWith(".")) { hostName = hostName.substring(0, hostName.length() - 1); } rec.setHostName(hostName); rec.setIpAddress(((ARecord) r).getAddress().getHostAddress()); rec.setLookupType("A"); result.add(rec); } } } catch (IOException ioex) { Logger.getLogger("ForwardLookupHelper.attemptZoneTransfer").log(Level.WARNING, null, ioex); } catch (ZoneTransferException zex) { Log.debug("ForwardLookupHelper.attemptZoneTransfer: Failed zonetransfer"); } } return result; }
/** * Builds a Requisition based on the A records returned in a zone transfer from the * specified zone. * * @return an instance of the JaxB annotated Requisition class than can be marshaled * into the XML and streamed to the Provisioner * * @throws IOException * @throws ZoneTransferException */ private Requisition buildRequisitionFromZoneTransfer() throws IOException, ZoneTransferException { ZoneTransferIn xfer = null; List<Record> records = null; LogUtils.debugf(this, "connecting to host %s:%d", m_url.getHost(), m_port); try { xfer = ZoneTransferIn.newIXFR(new Name(m_zone), m_serial.longValue(), m_fallback.booleanValue(), m_url.getHost(), m_port, m_key); records = getRecords(xfer); } catch (ZoneTransferException e) // Fallbacking to AXFR { String message = "IXFR not supported trying AXFR: "+e; log().warn(message, e); xfer = ZoneTransferIn.newAXFR(new Name(m_zone), m_url.getHost(), m_key); records = getRecords(xfer); } Requisition r = null; if (records.size() > 0) { //for now, set the foreign source to the specified dns zone r = new Requisition(getForeignSource()); for (Record rec : records) { if (matchingRecord(rec)) { r.insertNode(createRequisitionNode(rec)); } } } return r; }
@SuppressWarnings("unchecked") private List<Record> getRecords(ZoneTransferIn xfer) throws IOException, ZoneTransferException { return (List<Record>) xfer.run(); }