Example usage for com.google.gwt.user.client.rpc RpcRequestBuilder STRONG_NAME_HEADER

List of usage examples for com.google.gwt.user.client.rpc RpcRequestBuilder STRONG_NAME_HEADER

Introduction

In this page you can find the example usage for com.google.gwt.user.client.rpc RpcRequestBuilder STRONG_NAME_HEADER.

Prototype

String STRONG_NAME_HEADER

To view the source code for com.google.gwt.user.client.rpc RpcRequestBuilder STRONG_NAME_HEADER.

Click Source Link

Document

Used by #doFinish .

Usage

From source file:com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.java

License:Apache License

public Object doInvoke(RequestCallbackAdapter.ResponseReader responseReader, String requestData)
        throws Throwable {
    Map<String, String> headersCopy = new LinkedHashMap<String, String>();
    synchronized (RemoteServiceSyncProxy.class) {
        headersCopy.putAll(headers);//  w  w w .ja va  2s .  co  m
    }
    HttpURLConnection connection = null;
    InputStream is = null;
    int statusCode;
    // Send request
    try {
        URL url = new URL(remoteServiceURL);
        connection = connectionManager.openConnection(url);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty(RpcRequestBuilder.STRONG_NAME_HEADER, serializationPolicyName);
        connection.setRequestProperty("Content-Type", "text/x-gwt-rpc; charset=utf-8");
        connection.setRequestProperty("Content-Length", "" + requestData.getBytes("UTF-8").length);
        // Explicitly set these to override any system properties.
        connection.setReadTimeout(socketTimeout * 1000);
        connection.setConnectTimeout(socketTimeout * 1000);
        for (Entry<String, String> header : headersCopy.entrySet()) {
            connection.setRequestProperty(header.getKey(), header.getValue());
        }
        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
        writer.write(requestData);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new InvocationException("IOException while sending RPC request", e);
    }
    // Receive and process response
    try {
        connectionManager.handleResponseHeaders(connection);
        statusCode = connection.getResponseCode();
        is = connection.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer)) > 0) {
            baos.write(buffer, 0, len);
        }
        String encodedResponse = baos.toString("UTF8");
        // System.out.println("Response payload (len = " +
        // encodedResponse.length() + "): " + encodedResponse);
        if (statusCode != HttpURLConnection.HTTP_OK) {
            throw new StatusCodeException(statusCode, encodedResponse);
        } else if (encodedResponse == null) {
            // This can happen if the XHR is interrupted by the server dying
            throw new InvocationException("No response payload");
        } else if (isReturnValue(encodedResponse)) {
            encodedResponse = encodedResponse.substring(4);
            return responseReader.read(createStreamReader(encodedResponse));
        } else if (isThrownException(encodedResponse)) {
            encodedResponse = encodedResponse.substring(4);
            Throwable throwable = (Throwable) createStreamReader(encodedResponse).readObject();
            throw throwable;
        } else {
            throw new InvocationException("Unknown response " + encodedResponse);
        }
    } catch (IOException e) {
        throw new InvocationException("IOException while receiving RPC response", e);
    } catch (SerializationException e) {
        throw new InvocationException("Error while deserialization response", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignore) {
            }
        }
        if (connection != null) {
            // connection.disconnect();
        }
    }
}

From source file:com.google.web.bindery.requestfactory.server.Logging.java

License:Apache License

/**
 * Logs a message./*w  w  w  . j  a  v a2s.  c o  m*/
 * 
 * @param logRecordJson a json serialized LogRecord, as provided by
 *          {@link com.google.gwt.logging.client.JsonLogRecordClientUtil#logRecordAsJsonObject(LogRecord)}
 * @throws RemoteLoggingException if logging fails
 */
public static void logMessage(String logRecordJson) throws RemoteLoggingException {
    /*
     * if the header does not exist, we pass null, which is handled gracefully
     * by the deobfuscation code.
     */
    HttpServletRequest threadLocalRequest = RequestFactoryServlet.getThreadLocalRequest();
    String strongName = null;
    if (threadLocalRequest != null) {
        // can be null during tests
        strongName = threadLocalRequest.getHeader(RpcRequestBuilder.STRONG_NAME_HEADER);
    }
    RemoteLoggingServiceUtil.logOnServer(logRecordJson, strongName, deobfuscator, null);
}

From source file:de.itsvs.cwtrpc.core.CwtRpcUtils.java

License:Apache License

public static boolean containsStrongName(HttpServletRequest request) {
    return (request.getHeader(RpcRequestBuilder.STRONG_NAME_HEADER) != null);
}

From source file:ru.fly.server.LoggingServiceImpl.java

License:Apache License

@Override
public LogRecord log(String level, LogRecord rec) throws FlyException {
    String strongName = req.getHeader(RpcRequestBuilder.STRONG_NAME_HEADER);
    Throwable t = rec.getThrowable();
    for (StackTraceDeobfuscator d : deobfuscators) {
        t = d.deobfuscateThrowable(t, strongName);
    }// w ww . ja  va  2s .  co  m
    if ("error".equals(level)) {
        log.error(rec.getMessage(), t);
    } else if ("warn".equals(level)) {
        log.warn(rec.getMessage(), t);
    }
    return new LogRecord(t);
}

From source file:se.aaslin.developer.roboproxy.remote.RemoteServiceSyncProxy.java

License:Apache License

public Object doInvoke(RequestCallbackAdapter.ResponseReader responseReader, String requestData)
        throws Throwable {
    HttpURLConnection connection = null;
    InputStream is = null;//from   w  w w.  j a va 2 s. c  om
    int statusCode;

    if (DUMP_PAYLOAD) {
        System.out.println("Send request to " + remoteServiceURL);
        System.out.println("Request payload: " + requestData);
    }

    // Send request
    CookieHandler oldCookieHandler = CookieHandler.getDefault();
    try {
        CookieHandler.setDefault(cookieManager);

        URL url = new URL(remoteServiceURL);

        connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty(RpcRequestBuilder.STRONG_NAME_HEADER, serializationPolicyName);
        connection.setRequestProperty(RpcRequestBuilder.MODULE_BASE_HEADER, moduleBaseURL);
        connection.setRequestProperty("Content-Type", "text/x-gwt-rpc; charset=utf-8");
        connection.setRequestProperty("Content-Length", "" + requestData.getBytes("UTF-8").length);

        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
        writer.write(requestData);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new InvocationException("IOException while sending RPC request", e);
    } finally {
        CookieHandler.setDefault(oldCookieHandler);
    }

    // Receive and process response
    try {
        statusCode = connection.getResponseCode();
        is = connection.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer)) > 0) {
            baos.write(buffer, 0, len);
        }
        String encodedResponse = baos.toString("UTF8");
        if (DUMP_PAYLOAD) {
            System.out.println("Response code: " + statusCode);
            System.out.println("Response payload: " + encodedResponse);
        }

        // System.out.println("Response payload (len = " +
        // encodedResponse.length() + "): " + encodedResponse);
        if (statusCode != HttpURLConnection.HTTP_OK) {
            throw new StatusCodeException(statusCode, encodedResponse);
        } else if (encodedResponse == null) {
            // This can happen if the XHR is interrupted by the server dying
            throw new InvocationException("No response payload");
        } else if (isReturnValue(encodedResponse)) {
            encodedResponse = encodedResponse.substring(4);
            return responseReader.read(createStreamReader(encodedResponse));
        } else if (isThrownException(encodedResponse)) {
            encodedResponse = encodedResponse.substring(4);
            Throwable throwable = (Throwable) createStreamReader(encodedResponse).readObject();
            throw throwable;
        } else {
            throw new InvocationException("Unknown response " + encodedResponse);
        }
    } catch (IOException e) {
        throw new InvocationException("IOException while receiving RPC response", e);
    } catch (SerializationException e) {
        throw new InvocationException("Error while deserialization response", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ignore) {
            }
        }
        if (connection != null) {
            // connection.disconnect();
        }
    }
}