List of usage examples for org.springframework.remoting.httpinvoker HttpInvokerClientConfiguration getCodebaseUrl
@Nullable String getCodebaseUrl();
From source file:hr.fer.zemris.vhdllab.platform.remoting.HttpClientRequestExecutor.java
@SuppressWarnings("null") @Override/*from w ww.j a v a 2 s . c o m*/ protected void executePostMethod(HttpInvokerClientConfiguration config, HttpClient httpClient, PostMethod postMethod) throws IOException { AuthScope scope = new AuthScope(config.getCodebaseUrl(), AuthScope.ANY_PORT); super.executePostMethod(config, httpClient, postMethod); switch (postMethod.getStatusCode()) { case HttpStatus.SC_UNAUTHORIZED: UsernamePasswordCredentials credentials; if (Environment.isDevelopment() && !showRetryMessage) { credentials = new UsernamePasswordCredentials("test", "test"); // credentials = new UsernamePasswordCredentials("admin", "admin"); showRetryMessage = true; } else { CommandManager manager = Application.instance().getActiveWindow().getCommandManager(); LoginCommand command = (LoginCommand) manager.getCommand("loginCommand"); command.execute(); credentials = command.getCredentials(); } if (credentials == null) { System.exit(1); } ApplicationContextHolder.getContext().setUserId(credentials.getUserName()); showRetryMessage = true; getHttpClient().getState().setCredentials(scope, credentials); executePostMethod(config, httpClient, postMethod); break; } }
From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.java
/** * Execute the given request through the HttpClient. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #createHttpPost/*w ww . ja v a2 s. co m*/ * @see #setRequestBody * @see #executeHttpPost * @see #validateResponse * @see #getResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpPost postMethod = createHttpPost(config); setRequestBody(config, postMethod, baos); try { HttpResponse response = executeHttpPost(config, getHttpClient(), postMethod); validateResponse(config, response); InputStream responseBody = getResponseBody(config, response); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { postMethod.releaseConnection(); } }
From source file:com.ish.client.Http2InvokerRequestExecutor.java
@Override protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception { if (this.connectTimeout >= 0) { httpClient.setConnectTimeout(this.connectTimeout); }/*from w w w. j a va 2 s.c o m*/ if (this.readTimeout >= 0) { httpClient.setIdleTimeout(this.readTimeout); } ContentResponse response = httpClient.newRequest(config.getServiceUrl()).method(HttpMethod.POST) .content(new BytesContentProvider(baos.toByteArray())).send(); if (response.getStatus() >= 300) { throw new IOException("Did not receive successful HTTP response: status code = " + response.getStatus() + ", status message = [" + response.getReason() + "]"); } return readRemoteInvocationResult(new ByteArrayInputStream(response.getContent()), config.getCodebaseUrl()); }
From source file:org.piraso.server.spring.remoting.HttpInvokerRequestExecutorWrapper.java
public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws Exception { if (helper != null && pirasoContext.isMonitored()) { try {// www . j a v a2 s .co m ByteArrayOutputStream baos = helper.getByteArrayOutputStream(invocation); HttpURLConnection con = helper.openConnection(config); helper.prepareConnection(con, baos.size()); con.setRequestProperty(REMOTE_ADDRESS_HEADER, pirasoContext.getEntryPoint().getRemoteAddr()); con.setRequestProperty(REQUEST_ID_HEADER, String.valueOf(pirasoContext.getRequestId())); String groupId = getGroupId(); if (groupId != null) { con.setRequestProperty(GROUP_ID_HEADER, groupId); } helper.writeRequestBody(config, con, baos); helper.validateResponse(config, con); InputStream responseBody = helper.readResponseBody(config, con); return helper.readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } catch (HttpInvokerReflectionException e) { LOG.warn("Error on propagating piraso context. Will revert to direct delegation.", e); } } return delegate.executeRequest(config, invocation); }
From source file:org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.java
/** * Execute the given request through Commons HttpClient. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #createPostMethod/* w w w. j av a2 s . com*/ * @see #setRequestBody * @see #executePostMethod * @see #validateResponse * @see #getResponseBody */ protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { PostMethod postMethod = createPostMethod(config); try { setRequestBody(config, postMethod, baos); executePostMethod(config, getHttpClient(), postMethod); validateResponse(config, postMethod); InputStream responseBody = getResponseBody(config, postMethod); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { // Need to explicitly release because it might be pooled. postMethod.releaseConnection(); } }
From source file:org.tizzit.util.spring.httpinvoker.StreamSupportingHttpInvokerRequestExecutor.java
protected RemoteInvocationResult doExecuteRequest(final HttpInvokerClientConfiguration config, final ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { final WorkaroundByteArrayOutputStream wbaos = (WorkaroundByteArrayOutputStream) baos; RemoteInvocationResult result = null; if (wbaos.getRemoteInvocation() instanceof StreamSupportingRemoteInvocation) { result = doExecuteRequest(config, wbaos, (StreamSupportingRemoteInvocation) wbaos.getRemoteInvocation()); } else {/*from www . j av a 2s . co m*/ PostMethod postMethod = createPostMethod(config); try { setRequestBody(config, postMethod, baos); executePostMethod(config, getHttpClient(), postMethod); validateResponse(config, postMethod); InputStream responseBody = getResponseBody(config, postMethod); result = readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { // Need to explicitly release because it might be pooled. postMethod.releaseConnection(); } } return result; }
From source file:org.tizzit.util.spring.httpinvoker.StreamSupportingHttpInvokerRequestExecutor.java
/** * Execute a request to send the given serialized remote invocation. * <p>Implementations will usually call <code>readRemoteInvocationResult</code> * to deserialize a returned RemoteInvocationResult object. * * @param config the HTTP invoker configuration that specifies the target * service/*from w ww . j a va 2s . co m*/ * @param baos the ByteArrayOutputStream that contains the serialized * RemoteInvocation object * * @return the RemoteInvocationResult object * * @throws IOException if thrown by I/O operations * @throws ClassNotFoundException if thrown during deserialization * @see #readRemoteInvocationResult(java.io.InputStream, String) */ protected RemoteInvocationResult doExecuteRequest(final HttpInvokerClientConfiguration config, final ByteArrayOutputStream baos, final StreamSupportingRemoteInvocation invocation) throws IOException, ClassNotFoundException { final ByteArrayInputStream serializedInvocation = new ByteArrayInputStream(baos.toByteArray()); final PostMethod postMethod; final InputStream body; if (invocation.getClientSideInputStream() != null) { // We don't want to close the client side input stream unless the remote // method closes the input stream, so we "shield" the close for now. body = new CompositeInputStream(new InputStream[] { serializedInvocation, new CloseShieldedInputStream(invocation.getClientSideInputStream()) }); postMethod = createPostMethodForStreaming(config); } else { body = serializedInvocation; postMethod = createPostMethod(config); } boolean delayReleaseConnection = false; try { postMethod.setRequestBody(body); executePostMethod(config, getHttpClient(), postMethod); HttpState state = getHttpClient().getState(); /*postMethod.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); String host = targetURL.getHost(); String path = targetURL.getPath(); boolean secure = ("https".equalsIgnoreCase(targetURL.getProtocol())) ? true : false; //$NON-NLS-1$ String ck1 = (String) postMethod.getParams().g msgContext.getProperty(HTTPConstants.HEADER_COOKIE); String ck2 = (String) msgContext.getProperty(HTTPConstants.HEADER_COOKIE2); if (ck1 != null) { int index = ck1.indexOf('='); state.addCookie(new Cookie(host, ck1.substring(0, index), ck1.substring(index + 1), path, null, secure)); } if (ck2 != null) { int index = ck2.indexOf('='); state.addCookie(new Cookie(host, ck2.substring(0, index), ck2.substring(index + 1), path, null, secure)); } httpClient.setState(state); */ final RemoteInvocationResult ret = readRemoteInvocationResult(postMethod.getResponseBodyAsStream(), config.getCodebaseUrl()); if (ret instanceof StreamSupportingRemoteInvocationResult) { final StreamSupportingRemoteInvocationResult ssrir = (StreamSupportingRemoteInvocationResult) ret; // Close the local InputStream parameter if the remote method // explicitly closed the InputStream parameter on the other side. if (invocation.getClientSideInputStream() != null) { if (ssrir.getMethodClosedParamInputStream() != null) { if (Boolean.TRUE.equals(ssrir.getMethodClosedParamInputStream())) { invocation.getClientSideInputStream().close(); } } else { warnInputStreamParameterStateNotSpecified(invocation); } } // If there is a return stream, then we need to leave the PostMethod // connection open until the return stream is closed, so augment the // return stream for this. if (ssrir.getHasReturnStream()) { final InputStream sourceRetIs = ssrir.getClientSideInputStream(); if (sourceRetIs != null) { ssrir.setClientSideInputStream(new FilterInputStream(sourceRetIs) { public void close() throws IOException { super.close(); postMethod.releaseConnection(); } }); delayReleaseConnection = true; } } } else if (invocation.getClientSideInputStream() != null) { warnInputStreamParameterStateNotSpecified(invocation); } return ret; } finally { // need to explicitly release because it might be pooled if (!delayReleaseConnection) { postMethod.releaseConnection(); } } }