use of java.net.HttpURLConnection in project che by eclipse.
the class DockerRegistryChecker method checkRegistryIsAvailable.
/**
* Checks that registry is available and if it is not - logs warning message.
*/
@PostConstruct
private void checkRegistryIsAvailable() throws IOException {
if (snapshotUseRegistry && !isNullOrEmpty(machineDockerRegistry)) {
String registryUrl = "http://" + machineDockerRegistry;
LOG.info("Probing registry '{}'", registryUrl);
final HttpURLConnection conn = (HttpURLConnection) new URL(registryUrl).openConnection();
conn.setConnectTimeout(30 * 1000);
try {
final int responseCode = conn.getResponseCode();
LOG.info("Probe of registry '{}' succeed with HTTP response code '{}'", registryUrl, responseCode);
} catch (IOException ioEx) {
LOG.warn("Docker registry {} is not available, " + "which means that you won't be able to save snapshots of your workspaces." + "\nHow to configure registry?" + "\n\tLocal registry -> https://docs.docker.com/registry/" + "\n\tRemote registry -> set up 'che.docker.registry.auth.*' properties", registryUrl);
} finally {
conn.disconnect();
}
}
}
use of java.net.HttpURLConnection in project pinpoint by naver.
the class HttpURLConnectionInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
final HttpURLConnection request = (HttpURLConnection) target;
boolean connected = false;
if (target instanceof ConnectedGetter) {
connected = ((ConnectedGetter) target)._$PINPOINT$_isConnected();
}
boolean connecting = false;
if (target instanceof ConnectingGetter) {
connecting = ((ConnectingGetter) target)._$PINPOINT$_isConnecting();
}
if (connected || connecting) {
return;
}
final boolean sampling = trace.canSampled();
if (!sampling) {
request.setRequestProperty(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
return;
}
scope.getCurrentInvocation().setAttachment(TRACE_BLOCK_BEGIN_MARKER);
SpanEventRecorder recorder = trace.traceBlockBegin();
TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
final URL url = request.getURL();
final String host = url.getHost();
final int port = url.getPort();
// TODO How to represent protocol?
String endpoint = getEndpoint(host, port);
request.setRequestProperty(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
request.setRequestProperty(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
request.setRequestProperty(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
request.setRequestProperty(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
if (host != null) {
request.setRequestProperty(Header.HTTP_HOST.toString(), endpoint);
}
recorder.recordServiceType(JdkHttpConstants.SERVICE_TYPE);
// Don't record end point because it's same with destination id.
recorder.recordDestinationId(endpoint);
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(url.toString(), param));
}
use of java.net.HttpURLConnection in project jersey by jersey.
the class HelloWorldTest method testHelloWorld.
@Test
@Ignore("not compatible with test framework (doesn't use client())")
public void testHelloWorld() throws Exception {
URL getUrl = UriBuilder.fromUri(getBaseUri()).path(App.ROOT_PATH).build().toURL();
HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
try {
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "text/plain");
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
} finally {
connection.disconnect();
}
}
use of java.net.HttpURLConnection in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method mimeTempFileRemovedAfterAbortedUpload.
/**
* Mocked JERSEY-2794 reproducer. Real test is under integration tests.
*/
@Test
public void mimeTempFileRemovedAfterAbortedUpload(@Mocked final MIMEMessage message) throws Exception {
new Expectations() {
{
message.getAttachments();
result = new MIMEParsingException();
}
};
final URL url = new URL(getBaseUri().toString() + "MediaTypeWithBoundaryResource");
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("PUT");
connection.setRequestProperty("Accept", "text/plain");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY");
connection.setDoOutput(true);
connection.connect();
final OutputStream outputStream = connection.getOutputStream();
outputStream.write("--XXXX_YYYY".getBytes());
outputStream.write('\n');
outputStream.write("Content-Type: text/plain".getBytes());
outputStream.write('\n');
outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes());
outputStream.write('\n');
outputStream.write('\n');
// Send big chunk of data.
for (int i = 0; i < 16 * 4096; i++) {
outputStream.write('E');
if (i % 1024 == 0) {
outputStream.flush();
}
}
// Do NOT send end of the MultiPart message to simulate the issue.
// Get Response ...
final int response = connection.getResponseCode();
// ... Disconnect.
connection.disconnect();
assertThat("Bad Request expected", response, is(400));
// Make sure that the Mimepull message and it's parts have been closed and temporary files deleted.
new Verifications() {
{
message.close();
times = 1;
}
};
}
use of java.net.HttpURLConnection in project jersey by jersey.
the class DuplicateHeaderITCase method testDuplicateHeaderImpl.
private void testDuplicateHeaderImpl(final int headerCount, int expectedResponseCode, final String path) throws IOException {
final String headerName = HttpHeaders.CONTENT_TYPE;
URL getUrl = UriBuilder.fromUri(getBaseUri()).path(path).build().toURL();
HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
try {
connection.setRequestMethod("GET");
for (int i = 0; i < headerCount; i++) {
connection.addRequestProperty(headerName, "N/A");
}
connection.connect();
assertEquals(path + " [" + headerName + ":" + headerCount + "x]", expectedResponseCode, connection.getResponseCode());
} finally {
connection.disconnect();
}
}
Aggregations