Example usage for javax.servlet.http HttpServletRequest getReader

List of usage examples for javax.servlet.http HttpServletRequest getReader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getReader.

Prototype

public BufferedReader getReader() throws IOException;

Source Link

Document

Retrieves the body of the request as character data using a BufferedReader.

Usage

From source file:com.github.achatain.catalog.servlet.ItemServlet.java

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final String userId = getUserId(req);
    final String colId = extractCollectionIdFromRequest(req);

    final ItemDto itemDto = gson.fromJson(req.getReader(), ItemDto.class);
    Preconditions.checkArgument(itemDto != null, "Request body is missing");

    LOG.info(format("User [%s] to store the following item [%s] in the collection [%s]", userId,
            gson.toJson(itemDto), colId));

    itemService.createItem(userId, colId, itemDto);
}

From source file:org.kuali.ole.web.LicenseRestServlet.java

private String updateLicenses(HttpServletRequest req) throws IOException {
    DocstoreService ds = BeanLocator.getDocstoreService();
    String requestBody = CharStreams.toString(req.getReader());
    Licenses licenses = (Licenses) Licenses.deserialize(requestBody);
    ds.updateLicenses(licenses);/*from  w  ww .ja  v  a2 s . com*/
    return "";
}

From source file:org.opendatakit.common.web.servlet.CommonServletBase.java

/**
 * Takes the request and displays request in plain text in the response
 *
 * @param req The HTTP request received at the server
 * @param resp The HTTP response to be sent to client
 * @throws IOException// ww w  . j  ava2s . c o m
 */
protected final void printRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {
        BufferedReader received = req.getReader();

        String line = received.readLine();
        while (line != null) {
            resp.getWriter().println(line);
            line = received.readLine();
        }
    } catch (Exception e) {
        e.printStackTrace(resp.getWriter());
    }
}

From source file:PostServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!"text/xml".equals(request.getContentType())) {
        response.getWriter().println("Please post as text/xml.");
    } else {//from w  ww . j  a  v  a 2s. co m
        try {
            Document doc = builder.build(request.getReader());
            StringBuffer buff = new StringBuffer();
            buff.append("You searched for name '" + nameXPath.valueOf(doc) + "'");
            String year = yearXPath.valueOf(doc);
            if (!"notselected".equals(year)) {
                buff.append(" and year '" + year + "'");
            }
            buff.append(".");
            response.getWriter().print(buff.toString());
        } catch (JDOMException e) {
            response.getWriter().print("Error getting search terms: " + e.getMessage());
        }
    }
}

From source file:org.kuali.ole.web.LicenseRestServlet.java

private String updateLicense(HttpServletRequest req) throws IOException {
    DocstoreService ds = BeanLocator.getDocstoreService();
    String requestBody = CharStreams.toString(req.getReader());

    License license = new License();
    License licenseObj = (License) license.deserialize(requestBody);
    ds.updateLicense(licenseObj);//from w w  w.  ja v  a  2 s .  c om
    return responseUrl + licenseObj.getId();

}

From source file:org.wso2.carbon.identity.oidc.dcr.factory.OIDCRegistrationRequestFactoryTest.java

@Test(dataProvider = "OIDCRequestBuilderCreationData")
public void testCreate(String request, String sectorIdUrl, String subjectType, String tokenSignAlg,
        String tokenEncrAlg, String tokenEncrEnc, String userInfoRespSignAlg, String userInfoRespEncrAlg,
        String userInfoRespEnceEnc, String reqObjSignAlg, String reqObjEncrAlg, String reqObjEncrEnc,
        String tokenEPAuthSignAlg, String defaultMaxAge, String requireAuthTime, String defaultAcrValues,
        String initLoginUrl, List<String> requestUris) throws Exception {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
    when(mockRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request)));
    when(mockRequest.getHeaderNames()).thenReturn(Collections.<String>emptyEnumeration());
    when(mockRequest.getAttributeNames()).thenReturn(Collections.<String>emptyEnumeration());

    OIDCRegistrationRequest.OIDCRegistrationRequestBuilder requestBuilder = testedRegistrationRequestFactory
            .create(mockRequest, mockResponse);
    RegistrationRequest registrationRequest = requestBuilder.build();
    RegistrationRequestProfile requestProfile = registrationRequest.getRegistrationRequestProfile();
    assertTrue(requestProfile instanceof OIDCRegistrationRequestProfile,
            "Request profile should be an instance " + "of OIDCRegistrationRequestProfile");
    OIDCRegistrationRequestProfile oidcRegRequestProfile = (OIDCRegistrationRequestProfile) requestProfile;

    assertEquals(requestBuilder.getRequest(), mockRequest, "Builder should have the provided request.");
    assertEquals(requestBuilder.getResponse(), mockResponse, "Builder should have the provided response.");
    assertEquals(oidcRegRequestProfile.getSectorIdentifierUri(), sectorIdUrl, "Invalid Sector Id URL");
    assertEquals(oidcRegRequestProfile.getSubjectType(), subjectType, "Invalid subject type");
    assertEquals(oidcRegRequestProfile.getIdTokenSignedResponseAlg(), tokenSignAlg,
            "Invalid token sign " + "algorithm");
    assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseAlg(), tokenEncrAlg,
            "Invalid token encryption" + " alg");
    assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseEnc(), tokenEncrEnc,
            "Invalid token encryption" + " enc");
    assertEquals(oidcRegRequestProfile.getUserinfoSignedResponseAlg(), userInfoRespSignAlg,
            "Invalid userinfo " + "response sign alg");
    assertEquals(oidcRegRequestProfile.getUserinfoencryptedResponseAlg(), userInfoRespEncrAlg,
            "Invalid userinfo " + "response encr alg");
    assertEquals(oidcRegRequestProfile.getUserinfoEncryptedResponseEnc(), userInfoRespEnceEnc,
            "Invalid userinfo " + "response encr enc");
    assertEquals(oidcRegRequestProfile.getRequestObjectSigningAlg(), reqObjSignAlg,
            "Invalid request obj sign " + "alg");
    assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionAlg(), reqObjEncrAlg,
            "Invalid request obj encr" + " alg");
    assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionEnc(), reqObjEncrEnc,
            "Invalid request obj encr" + " enc");
    assertEquals(oidcRegRequestProfile.getTokenEndpointAuthSigningAlg(), tokenEPAuthSignAlg,
            "Invalid token " + "endpoint auth response alg.");
    assertEquals(oidcRegRequestProfile.getDefaultMaxAge(), defaultMaxAge, "Invalid default max age");
    assertEquals(oidcRegRequestProfile.getRequireAuthTime(), requireAuthTime, "Invalid require auth time");
    assertEquals(oidcRegRequestProfile.getDefaultAcrValues(), defaultAcrValues, "Invalid default acr values");
    assertEquals(oidcRegRequestProfile.getInitiateLoginUri(), initLoginUrl, "Invalid initiate login uri");
    assertTrue(CollectionUtils.isEqualCollection(oidcRegRequestProfile.getRequestUris(), requestUris),
            "Invalid " + "request URLs ");
}

From source file:org.apache.ode.axis2.SoapHeader2Test.java

@BeforeMethod
protected void setUp() throws Exception {
    super.setUp();
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setContextPath("/TestSoapHeader2");
    contextHandler.setHandler(new AbstractHandler() {
        public void handle(String s, HttpServletRequest request, HttpServletResponse response, int i)
                throws IOException, ServletException {
            boolean header1found = false, header2found = false;
            String line;//from   ww  w . j  av  a  2s .  co  m
            while ((line = request.getReader().readLine()) != null && (!header1found || !header2found)) {
                header1found = header1found
                        || line.matches(".*header1-field1.*Hello from TestSoapHeader2.*header1-field1>");
                header2found = header2found
                        || line.matches(".*header2-field1.*Hello from TestSoapHeader2.*header2-field1>");
            }
            response.getOutputStream().print(
                    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:unit=\"http://ode/bpel/unit-test.wsdl\">\n"
                            + "   <soapenv:Header/>\n" + "   <soapenv:Body>\n" + "      <unit:body>\n");
            if (header1found && header2found) {
                response.getOutputStream()
                        .print("         <unit:message>TestSoapHeader2 passed</unit:message>\n");
            } else {
                response.getOutputStream()
                        .print("         <unit:message>Some soap headers are missing!</unit:message>\n");
            }
            response.getOutputStream()
                    .print("      </unit:body>\n" + "   </soapenv:Body>\n" + "</soapenv:Envelope>");
            response.getOutputStream().close();
            response.setStatus(200);
            ((Request) request).setHandled(true);
        }
    });

    jettyWrapper = new JettyWrapper(getTestPort(1), contextHandler);
    jettyWrapper.start();
}

From source file:com.roncoo.pay.controller.common.BaseController.java

/**
 * //from  ww w. j  a  v a 2s .  com
 * @param request
 *            
 * @return ??
 * @throws IOException
 */
public String parseRequestString(HttpServletRequest request) throws IOException {
    String inputLine;
    String notityXml = "";
    while ((inputLine = request.getReader().readLine()) != null) {
        notityXml += inputLine;
    }
    request.getReader().close();
    return notityXml;
}

From source file:com.roncoo.controller.BaseController.java

public String readRequest(HttpServletRequest request) throws IOException {
    StringBuilder sb = new StringBuilder();
    try {/* w ww  .  j  a v a2s  .  c  o m*/
        String line;
        while ((line = request.getReader().readLine()) != null) {
            sb.append(line);
        }
    } finally {
        request.getReader().close();
    }
    return sb.toString();
}

From source file:io.specto.hoverfly.recorder.HoverflyFilter.java

private HoverflyRecording.HoverFlyRequest recordRequest(final HttpServletRequest request) throws IOException {
    final String path = request.getPathInfo();
    final String query = request.getQueryString();
    final String requestMethod = request.getMethod();
    final String destination = simulatedBaseUrl;
    final String requestBody = request.getReader() != null ? CharStreams.toString(request.getReader()) : "";
    return new HoverflyRecording.HoverFlyRequest(path, requestMethod, destination, query, requestBody);
}