Extremly weird error - only happens when code is ran on server?


I’m trying to create an app in java that lets a server create it’s own subdomains. By default it creates an A record to allow the subdomain, but if the server isn’t dedicated and uses a single port, I need a SRV record to make it work. When I attempt to create the SRV record from my localhost (when I test the code) it works perfectly, however, when I upload it to the server, it suddendly gives me this error.
{“result”:null,“success”:false,“errors”:[{“code”:1004,“message”:“DNS Validation Error”,“error_chain”:[{“code”:9002,“message”:“Invalid DNS Record Type”}]}],“messages”:}
final JsonObject obj = new JsonObject();

	obj.addProperty("type", "SRV");
	obj.addProperty("ttl", 1);
	obj.addProperty("content", "0 0 25668 my.domain.xyz");

	final JsonObject data = new JsonObject();

	data.addProperty("name", "my");
	data.addProperty("port", 25668);
	data.addProperty("priority", 0);
	data.addProperty("proto", "_tcp");
	data.addProperty("service", "_minecraft");
	data.addProperty("target", "my.domain.xyz");
	data.addProperty("weight", 0);

	obj.add("data", data);


	final HttpResponse<JsonNode> result = Unirest.post(URL_STRING + "zones/" + zone + "/dns_records")

It’s extremly weird to me. Could it be that the domain is set to go to the server that the code is being called from? :thinking:

Thanks for reading my post. :slight_smile:

Not sure what you mean by that, but I’d simply check if the HTTP request you are sending has the right request body. Judging from the error message it would seem as if the error was there.

Also, take the request and run it through cURL, then you can verify if the request is properly being generated.

Generally though, that’s probably better a question for StackOverflow :slight_smile:

Thank you for your quick reply. I will try sending the request through cURL, but as said earlier when I run the code on my local computer it works perfectly fine. :worried:

I only meant that the domain (or zone) I’m handling is linking to the server that I’m calling the code from. I’m not sure if that makes sense? I’m trying to make an SRV record that makes the subdomain link to the server, that I’m running the code from.

I’m sorry if this place is inappropiate for the question. :sweat_smile:

EDIT: Just tried to run the json through cURL, and it works there :face_with_raised_eyebrow:

Not really I am afraid. As long as the request body is correct and all authentication headers are in place as well you shouldn’t get that error. Also double check the URL.

Maybe there is an issue with that library. That’s something you best clarify at https://github.com/Kong/unirest-java/issues

1 Like

You were right, I was loading the Unirest library at runtime. I tried shading it instead (+2,2mb with dependencies, sigh) and it worked.

I guess that solves it, thank you for your kind help. :+1:

No worries, glad we sorted it out.

If you want something more compact, I’d recommend jodd.org.

The author broke everything into modules at this point, but when it was still a single JAR file it was about 1.8 megabytes - and that included a lot more than just HTTP. The HTTP client alone is at https://github.com/oblac/jodd-http

1 Like

That seems great by the looks of it. I’ll definitely check that out, thank you! :smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.