本文整理匯總了Java中org.xbill.DNS.Name.fromString方法的典型用法代碼示例。如果您正苦於以下問題:Java Name.fromString方法的具體用法?Java Name.fromString怎麽用?Java Name.fromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xbill.DNS.Name
的用法示例。
在下文中一共展示了Name.fromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSentMessageTooLongThrowsException
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Test
public void testSentMessageTooLongThrowsException() throws Exception {
Update oversize = new Update(Name.fromString("tld", Name.root));
for (int i = 0; i < 2000; i++) {
oversize.add(
ARecord.newRecord(
Name.fromString("test-extremely-long-name-" + i + ".tld", Name.root),
Type.A,
DClass.IN));
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
when(mockSocket.getOutputStream()).thenReturn(outputStream);
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> resolver.send(oversize));
assertThat(thrown).hasMessageThat().contains("message larger than maximum");
}
示例2: doUpdate
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private void doUpdate(AdapterOperation op) {
OnmsNode node = null;
log().debug("doUpdate: operation: " + op.getType().name());
try {
node = m_nodeDao.get(op.getNodeId());
DnsRecord record = new DnsRecord(node);
log().debug("doUpdate: DnsRecord: hostname: " + record.getHostname() + " zone: " + record.getZone() + " ip address " + record.getIp().getHostAddress());
DnsRecord oldRecord = m_nodeDnsRecordMap.get(Integer.valueOf(node.getId()));
Update update = new Update(Name.fromString(record.getZone()));
if (oldRecord != null && oldRecord.getHostname() != record.getHostname()) {
update.delete(Name.fromString(oldRecord.getHostname()), Type.A);
}
update.replace(Name.fromString(record.getHostname()), Type.A, 3600, record.getIp().getHostAddress());
m_resolver.send(update);
m_nodeDnsRecordMap.put(Integer.valueOf(op.getNodeId()), record);
} catch (Throwable e) {
log().error("addNode: Error handling node added event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
示例3: doDelete
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private void doDelete(AdapterOperation op) {
try {
DnsRecord record = m_nodeDnsRecordMap.get(Integer.valueOf(op.getNodeId()));
if (record != null) {
Update update = new Update(Name.fromString(record.getZone()));
update.delete(Name.fromString(record.getHostname()), Type.A);
m_resolver.send(update);
m_nodeDnsRecordMap.remove(Integer.valueOf(op.getNodeId()));
}
} catch (Throwable e) {
log().error("deleteNode: Error handling node deleted event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
示例4: doUpdate
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private void doUpdate(AdapterOperation op) {
log().debug("doUpdate: operation: " + op.getType().name());
for (ReverseDnsRecord record : m_reverseDnsProvisioningAdapterService.get(op.getNodeId()) ) {
log().debug("doUpdate: ReverseDnsRecord: hostname: " + record.getHostname() + " zone: " + record.getZone() + " ip address: " + record.getIp().getHostAddress());
try {
Update update = new Update(Name.fromString(record.getZone()));
Name ptrRecord=ReverseMap.fromAddress(record.getIp());
update.replace(ptrRecord, Type.PTR, 3600, record.getHostname());
m_resolver.send(update);
m_reverseDnsProvisioningAdapterService.update(op.getNodeId(),record);
} catch (Exception e) {
log().error("updateNode: Error handling updated event.", e);
sendAndThrow(op.getNodeId(), e);
}
}
}
示例5: testUnsignedThatMustBeSigned
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Test
public void testUnsignedThatMustBeSigned() throws IOException {
Name query = Name.fromString("www.ingotronic.ch.");
// prepare a faked, unsigned response message that must have a signature
// to be valid
Message message = new Message();
message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertEquals("validate.bogus.missingsig", getReason(response));
}
示例6: testModifiedSignature
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Test
public void testModifiedSignature() throws IOException {
Name query = Name.fromString("www.ingotronic.ch.");
// prepare a faked, unsigned response message that must have a signature
// to be valid
Message message = new Message();
message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
message.addRecord(new RRSIGRecord(query, DClass.IN, 0, Type.A, Algorithm.RSASHA256, 5, new Date(System.currentTimeMillis() + 5000), new Date(System.currentTimeMillis() - 5000), 1234, Name.fromString("ingotronic.ch."), new byte[] { 1, 2, 3 }), Section.ANSWER);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertTrue(getReason(response).startsWith("failed.answer.positive:{ www.ingotronic.ch."));
}
示例7: getReverseIPName
import org.xbill.DNS.Name; //導入方法依賴的package包/類
public static Name getReverseIPName(final InetAddress adr, final Name postfix)
{
final byte[] addr = adr.getAddress();
final StringBuilder sb = new StringBuilder();
if (addr.length == 4)
for (int i = addr.length - 1; i >= 0; i--)
{
sb.append(addr[i] & 0xFF);
if (i > 0)
sb.append(".");
}
else
{
final int[] nibbles = new int[2];
for (int i = addr.length - 1; i >= 0; i--)
{
nibbles[0] = (addr[i] & 0xFF) >> 4;
nibbles[1] = addr[i] & 0xFF & 0xF;
for (int j = nibbles.length - 1; j >= 0; j--)
{
sb.append(Integer.toHexString(nibbles[j]));
if (i > 0 || j > 0)
sb.append(".");
}
}
}
try
{
return Name.fromString(sb.toString(), postfix);
}
catch (final TextParseException e)
{
throw new IllegalStateException("name cannot be invalid");
}
}
示例8: makeQuery
import org.xbill.DNS.Name; //導入方法依賴的package包/類
public static synchronized Message makeQuery(String nameString, int id) throws TextParseException {
Name name = Name.fromString(nameString, Name.root);
Record question = Record.newRecord(name, Type.A, DClass.ANY);
Message query = Message.newQuery(question);
query.getHeader().setID(id);
return query;
}
示例9: toAbsoluteName
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private Name toAbsoluteName(String name) {
try {
return Name.fromString(name, Name.root);
} catch (TextParseException e) {
throw new RuntimeException(
String.format("toAbsoluteName failed for name: %s in zone: %s", name, zoneName), e);
}
}
示例10: process
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) throws Exception {
String server = exchange.getIn().getHeader(DnsConstants.DNS_SERVER, String.class);
SimpleResolver resolver = new SimpleResolver(server);
int type = Type.value(exchange.getIn().getHeader(DnsConstants.DNS_TYPE, String.class));
if (type == -1) {
// default: if unparsable value given, use A.
type = Type.A;
}
String dclassValue = exchange.getIn().getHeader(DnsConstants.DNS_CLASS, String.class);
if (dclassValue == null) {
dclassValue = "";
}
int dclass = DClass.value(dclassValue);
if (dclass == -1) {
// by default, value is IN.
dclass = DClass.IN;
}
Name name = Name.fromString(exchange.getIn().getHeader(DnsConstants.DNS_NAME, String.class), Name.root);
Record rec = Record.newRecord(name, type, dclass);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
exchange.getIn().setBody(response);
}
示例11: process
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Override
public void process(Exchange exchange) throws Exception {
SimpleResolver resolver = new SimpleResolver();
int type = Type.TXT;
Name name = Name.fromString(String.valueOf(exchange.getIn().getHeader(DnsConstants.TERM)) + ".wp.dg.cx", Name.root);
Record rec = Record.newRecord(name, type, DClass.IN);
Message query = Message.newQuery(rec);
Message response = resolver.send(query);
Record[] records = response.getSectionArray(Section.ANSWER);
if (records.length > 0) {
exchange.getIn().setBody(records[0].rdataToString());
} else {
exchange.getIn().setBody(null);
}
}
示例12: messageWithRCode
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private Message messageWithRCode(String query, int rcode) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
result.getHeader().setRcode(rcode);
return result;
}
示例13: messageWithNodes
import org.xbill.DNS.Name; //導入方法依賴的package包/類
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
for (String name1 : names){
result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER);
}
return result;
}
示例14: testAnswerSectionSearchNotFoundDifferentName
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Test()
public void testAnswerSectionSearchNotFoundDifferentName() throws UnknownHostException, TextParseException {
Message m = new Message();
Record r = new ARecord(Name.fromString("asdf."), DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset result = sm.findAnswerRRset(Name.root, Type.MX, DClass.IN);
assertNull(result);
}
示例15: testKeyWhenNameUnderAnchorDS
import org.xbill.DNS.Name; //導入方法依賴的package包/類
@Test
public void testKeyWhenNameUnderAnchorDS() throws TextParseException {
SRRset set = new SRRset(new RRset(new DSRecord(Name.fromString("bla."), DClass.IN, 0, 0, 0, 0, new byte[]{0})));
TrustAnchorStore tas = new TrustAnchorStore();
tas.store(set);
SRRset anchor = tas.find(Name.fromString("asdf.bla."), DClass.IN);
assertEquals(set, anchor);
}