Example usage for org.apache.http.protocol HTTP CONTENT_TYPE

List of usage examples for org.apache.http.protocol HTTP CONTENT_TYPE

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP CONTENT_TYPE.

Prototype

String CONTENT_TYPE

To view the source code for org.apache.http.protocol HTTP CONTENT_TYPE.

Click Source Link

Usage

From source file:org.digitalcampus.oppia.task.ResetTask.java

@Override
protected Payload doInBackground(Payload... params) {

    Payload payload = params[0];//  w  w w  .ja  v  a  2s.  c o  m
    User u = (User) payload.getData().get(0);
    HTTPConnectionUtils client = new HTTPConnectionUtils(ctx);

    String url = prefs.getString(PrefsActivity.PREF_SERVER, ctx.getString(R.string.prefServerDefault))
            + MobileLearning.RESET_PATH;
    Log.d(TAG, url);
    HttpPost httpPost = new HttpPost(url);
    try {
        // update progress dialog
        publishProgress(ctx.getString(R.string.reset_process));
        // add post params
        JSONObject json = new JSONObject();
        json.put("username", u.getUsername());
        StringEntity se = new StringEntity(json.toString(), "utf8");
        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httpPost.setEntity(se);

        // make request
        HttpResponse response = client.execute(httpPost);

        // read response
        InputStream content = response.getEntity().getContent();
        BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 4096);
        String responseStr = "";
        String s = "";

        while ((s = buffer.readLine()) != null) {
            responseStr += s;
        }

        switch (response.getStatusLine().getStatusCode()) {
        case 400: // unauthorised
            payload.setResult(false);
            payload.setResultResponse(responseStr);
            break;
        case 201: // reset complete
            payload.setResult(true);
            payload.setResultResponse(ctx.getString(R.string.reset_complete));
            break;
        default:
            payload.setResult(false);
            payload.setResultResponse(ctx.getString(R.string.error_connection));
        }

    } catch (UnsupportedEncodingException e) {
        payload.setResult(false);
        payload.setResultResponse(ctx.getString(R.string.error_connection));
    } catch (ClientProtocolException e) {
        payload.setResult(false);
        payload.setResultResponse(ctx.getString(R.string.error_connection));
    } catch (IOException e) {
        payload.setResult(false);
        payload.setResultResponse(ctx.getString(R.string.error_connection));
    } catch (JSONException e) {
        Mint.logException(e);
        e.printStackTrace();
        payload.setResult(false);
        payload.setResultResponse(ctx.getString(R.string.error_processing_response));
    }
    return payload;
}

From source file:org.digitalcampus.oppia.task.SubmitQuizAttemptsTask.java

@Override
protected Payload doInBackground(Payload... params) {
    Payload payload = params[0];//from w w  w .  j a  v  a2  s  .c  om
    for (Object l : payload.getData()) {
        QuizAttempt qa = (QuizAttempt) l;
        HTTPConnectionUtils client = new HTTPConnectionUtils(ctx);

        try {

            String url = client.getFullURL(MobileLearning.QUIZ_SUBMIT_PATH);
            HttpPost httpPost = new HttpPost(url);
            StringEntity se = new StringEntity(qa.getData(), "utf8");
            se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            httpPost.setEntity(se);
            httpPost.addHeader(client.getAuthHeader(qa.getUser().getUsername(), qa.getUser().getApiKey()));
            // make request
            HttpResponse response = client.execute(httpPost);
            InputStream content = response.getEntity().getContent();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 4096);
            String responseStr = "";
            String s = "";

            while ((s = buffer.readLine()) != null) {
                responseStr += s;
            }

            switch (response.getStatusLine().getStatusCode()) {
            case 201: // submitted
                JSONObject jsonResp = new JSONObject(responseStr);
                DbHelper db = new DbHelper(ctx);
                db.markQuizSubmitted(qa.getId());
                db.updateUserPoints(qa.getUser().getUsername(), jsonResp.getInt("points"));
                db.updateUserBadges(qa.getUser().getUsername(), jsonResp.getInt("badges"));
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(true);
                break;
            case 400: // bad request - so to prevent re-submitting over and
                      // over
                      // just mark as submitted
                DbHelper db2 = new DbHelper(ctx);
                db2.markQuizSubmitted(qa.getId());
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(false);
                break;
            case 500: // server error - so to prevent re-submitting over and
                      // over
                      // just mark as submitted
                DbHelper db3 = new DbHelper(ctx);
                db3.markQuizSubmitted(qa.getId());
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(false);
                break;
            default:
                payload.setResult(false);
            }
        } catch (UnsupportedEncodingException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (ClientProtocolException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (IOException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (JSONException e) {
            payload.setResult(false);
            Mint.logException(e);
            e.printStackTrace();
        }
    }
    Editor editor = prefs.edit();
    long now = System.currentTimeMillis() / 1000;
    editor.putLong(PrefsActivity.PREF_TRIGGER_POINTS_REFRESH, now);
    editor.commit();
    return payload;
}

From source file:org.digitalcampus.oppia.task.SubmitQuizTask.java

@Override
protected Payload doInBackground(Payload... params) {
    Payload payload = params[0];/* w w w.ja v a  2  s  . co  m*/
    for (Object l : payload.getData()) {
        TrackerLog tl = (TrackerLog) l;
        HTTPConnectionUtils client = new HTTPConnectionUtils(ctx);

        try {

            String url = client.getFullURL(MobileLearning.QUIZ_SUBMIT_PATH);
            HttpPost httpPost = new HttpPost(url);
            StringEntity se = new StringEntity(tl.getContent(), "utf8");
            se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            httpPost.setEntity(se);
            httpPost.addHeader(client.getAuthHeader());
            // make request
            HttpResponse response = client.execute(httpPost);
            InputStream content = response.getEntity().getContent();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 4096);
            String responseStr = "";
            String s = "";

            while ((s = buffer.readLine()) != null) {
                responseStr += s;
            }

            switch (response.getStatusLine().getStatusCode()) {
            case 201: // submitted
                DbHelper db = new DbHelper(ctx);
                db.markQuizSubmitted(tl.getId());
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(true);
                // update points
                JSONObject jsonResp = new JSONObject(responseStr);
                Editor editor = prefs.edit();
                editor.putInt(PrefsActivity.PREF_POINTS, jsonResp.getInt("points"));
                editor.putInt(PrefsActivity.PREF_BADGES, jsonResp.getInt("badges"));
                editor.commit();
                break;
            case 400: // bad request - so to prevent re-submitting over and
                      // over
                      // just mark as submitted
                DbHelper db2 = new DbHelper(ctx);
                db2.markQuizSubmitted(tl.getId());
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(false);
                break;
            case 500: // bad request - so to prevent re-submitting over and
                      // over
                      // just mark as submitted
                DbHelper db3 = new DbHelper(ctx);
                db3.markQuizSubmitted(tl.getId());
                DatabaseManager.getInstance().closeDatabase();
                payload.setResult(false);
                break;
            default:
                payload.setResult(false);
            }
        } catch (UnsupportedEncodingException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (ClientProtocolException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (IOException e) {
            payload.setResult(false);
            publishProgress(ctx.getString(R.string.error_connection));
        } catch (JSONException e) {
            payload.setResult(false);
            if (!MobileLearning.DEVELOPER_MODE) {
                BugSenseHandler.sendException(e);
            } else {
                e.printStackTrace();
            }
        }
    }

    return payload;
}

From source file:org.digitalcampus.oppia.task.SubmitTrackerMultipleTask.java

@Override
protected Payload doInBackground(Payload... params) {
    Payload payload = new Payload();

    try {//from w  w w . j  a va2 s . com
        DbHelper db = new DbHelper(ctx);
        ArrayList<User> users = db.getAllUsers();
        DatabaseManager.getInstance().closeDatabase();

        for (User u : users) {
            DbHelper db1 = new DbHelper(ctx);
            payload = db1.getUnsentTrackers(u.getUserId());
            DatabaseManager.getInstance().closeDatabase();

            @SuppressWarnings("unchecked")
            Collection<Collection<TrackerLog>> result = (Collection<Collection<TrackerLog>>) split(
                    (Collection<Object>) payload.getData(), MobileLearning.MAX_TRACKER_SUBMIT);

            for (Collection<TrackerLog> trackerBatch : result) {
                String dataToSend = createDataString(trackerBatch);
                Log.d(TAG, "Debug data to Send: " + dataToSend);
                try {

                    HTTPConnectionUtils client = new HTTPConnectionUtils(ctx);
                    String url = client.getFullURL(MobileLearning.TRACKER_PATH);
                    HttpPatch httpPatch = new HttpPatch(url);

                    StringEntity se = new StringEntity(dataToSend, "utf8");
                    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                    httpPatch.setEntity(se);

                    httpPatch.addHeader(client.getAuthHeader(u.getUsername(), u.getApiKey()));

                    // make request
                    HttpResponse response = client.execute(httpPatch);

                    InputStream content = response.getEntity().getContent();
                    BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 4096);
                    String responseStr = "";
                    String s = "";

                    while ((s = buffer.readLine()) != null) {
                        responseStr += s;
                    }
                    Log.d(TAG, responseStr);
                    switch (response.getStatusLine().getStatusCode()) {
                    case 200: // submitted
                        for (TrackerLog tl : trackerBatch) {
                            DbHelper db2 = new DbHelper(ctx);
                            db2.markLogSubmitted(tl.getId());
                            DatabaseManager.getInstance().closeDatabase();
                        }
                        payload.setResult(true);
                        // update points
                        JSONObject jsonResp = new JSONObject(responseStr);
                        DbHelper dbpb = new DbHelper(ctx);
                        dbpb.updateUserPoints(u.getUserId(), jsonResp.getInt("points"));
                        dbpb.updateUserBadges(u.getUserId(), jsonResp.getInt("badges"));
                        DatabaseManager.getInstance().closeDatabase();

                        Editor editor = prefs.edit();
                        try {
                            editor.putBoolean(PrefsActivity.PREF_SCORING_ENABLED,
                                    jsonResp.getBoolean("scoring"));
                            editor.putBoolean(PrefsActivity.PREF_BADGING_ENABLED,
                                    jsonResp.getBoolean("badging"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        editor.commit();

                        try {
                            JSONObject metadata = jsonResp.getJSONObject("metadata");
                            MetaDataUtils mu = new MetaDataUtils(ctx);
                            mu.saveMetaData(metadata, prefs);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        break;
                    case 400: // submitted but invalid digest - returned 400 Bad Request - so record as submitted so doesn't keep trying
                        for (TrackerLog tl : trackerBatch) {
                            DbHelper db3 = new DbHelper(ctx);
                            db3.markLogSubmitted(tl.getId());
                            DatabaseManager.getInstance().closeDatabase();
                        }
                        ;
                        payload.setResult(true);
                        break;
                    default:
                        payload.setResult(false);
                    }

                } catch (UnsupportedEncodingException e) {
                    payload.setResult(false);
                } catch (ClientProtocolException e) {
                    payload.setResult(false);
                } catch (IOException e) {
                    payload.setResult(false);
                } catch (JSONException e) {
                    Mint.logException(e);
                    e.printStackTrace();
                    payload.setResult(false);
                }
                publishProgress(0);
            }

        }

    } catch (IllegalStateException ise) {
        ise.printStackTrace();
        payload.setResult(false);
    }

    Editor editor = prefs.edit();
    long now = System.currentTimeMillis() / 1000;
    editor.putLong(PrefsActivity.PREF_TRIGGER_POINTS_REFRESH, now);
    editor.commit();

    return payload;
}

From source file:org.pixmob.droidlink.net.NetworkClient.java

/**
 * Prepare a request for sending a Json formatted query.
 *//*w  w w.  j  av a 2  s .co  m*/
private static void prepareJsonRequest(HttpRequest req) {
    req.setHeader(HTTP.CONTENT_TYPE, "application/json");
    req.addHeader("Accept", "application/json");
}

From source file:org.siddhiesb.transport.passthru.ClientWorker.java

public void run() {

    if (expectEntityBody) {
        String cType = response.getHeader(HTTP.CONTENT_TYPE);
        String contentType;/*from   w ww.j ava 2s.c  o  m*/
        if (cType != null) {
            // This is the most common case - Most of the time servers send the Content-Type
            contentType = cType;
        } else {
            // Server hasn't sent the header - Try to infer the content type
            contentType = inferContentType();
        }
    }
    // copy the HTTP status code as a message context property with the key HTTP_SC to be
    // used at the sender to set the proper status code when passing the message

    int statusCode = this.response.getStatus();

    /*Dispatching to the MediationEngine*/
    genericMediationEngine.process(clientWorkerPTCtx);

}

From source file:org.siddhiesb.transport.passthru.ServerWorker.java

private void processEntityEnclosingRequest() {
    String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
    String method = request.getRequest() != null
            ? request.getRequest().getRequestLine().getMethod().toUpperCase()
            : "";

    commonContext.setProperty("To", request.getUri());
    commonContext.setProperty("HTTP_METHOD", method);
    commonContext.setProperty(HTTP.CONTENT_TYPE, contentTypeHeader);

    /*Setting the PassThru Pipe*/
    commonContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, request.getPipe());
    /* Set message direction - Request */
    commonContext.setProperty(CommonAPIConstants.MESSAGE_DIRECTION,
            CommonAPIConstants.MESSAGE_DIRECTION_REQUEST);

    /*ToDo : Set Pipe and dispatch to Mediation Engine */
    genericMediationEngine.process(commonContext);
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.http.InboundHttpServerWorker.java

public void run() {
    if (request != null) {
        try {//from   w w  w .j  a v  a  2  s .c om
            //get already created axis2 context from ServerWorker
            MessageContext axis2MsgContext = getRequestContext();

            //create Synapse Message Context
            org.apache.synapse.MessageContext synCtx = createSynapseMessageContext(request, axis2MsgContext);
            updateAxis2MessageContextForSynapse(synCtx);

            setInboundProperties(synCtx);
            String method = request.getRequest() != null
                    ? request.getRequest().getRequestLine().getMethod().toUpperCase()
                    : "";
            processHttpRequestUri(axis2MsgContext, method);

            String endpointName = HTTPEndpointManager.getInstance().getEndpointName(port, tenantDomain);
            if (endpointName == null) {
                handleException(
                        "Endpoint not found for port : " + port + "" + " tenant domain : " + tenantDomain);
            }
            InboundEndpoint endpoint = synCtx.getConfiguration().getInboundEndpoint(endpointName);

            if (endpoint == null) {
                log.error("Cannot find deployed inbound endpoint " + endpointName + "for process request");
                return;
            }

            //                OpenEventCollector.reportEntryEvent(synCtx, endpointName, endpoint.getAspectConfiguration(),
            //                                                    ComponentType.INBOUNDENDPOINT);

            CustomLogSetter.getInstance().setLogAppender(endpoint.getArtifactContainerName());

            if (!isRESTRequest(axis2MsgContext, method)) {
                if (request.isEntityEnclosing()) {
                    processEntityEnclosingRequest(axis2MsgContext, false);
                } else {
                    processNonEntityEnclosingRESTHandler(null, axis2MsgContext, false);
                }
            } else {
                AxisOperation axisOperation = ((Axis2MessageContext) synCtx).getAxis2MessageContext()
                        .getAxisOperation();
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().setAxisOperation(null);
                String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
                SOAPEnvelope soapEnvelope = handleRESTUrlPost(contentTypeHeader);
                processNonEntityEnclosingRESTHandler(soapEnvelope, axis2MsgContext, false);
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().setAxisOperation(axisOperation);

            }

            dispatchPattern = HTTPEndpointManager.getInstance().getPattern(tenantDomain, port);

            boolean continueDispatch = true;
            if (dispatchPattern != null) {
                patternMatcher = dispatchPattern.matcher(request.getUri());
                if (!patternMatcher.matches()) {
                    if (log.isDebugEnabled()) {
                        log.debug("Requested URI does not match given dispatch regular expression.");
                    }
                    continueDispatch = false;
                }
            }

            if (continueDispatch && dispatchPattern != null) {

                boolean processedByAPI = false;

                // Trying to dispatch to an API
                processedByAPI = restHandler.process(synCtx);
                if (log.isDebugEnabled()) {
                    log.debug("Dispatch to API state : enabled, Message is " + (!processedByAPI ? "NOT" : "")
                            + "processed by an API");
                }

                if (!processedByAPI) {
                    //check the validity of message routing to axis2 path
                    boolean isAxis2Path = isAllowedAxis2Path(synCtx);

                    if (isAxis2Path) {
                        //create axis2 message context again to avoid settings updated above
                        axis2MsgContext = createMessageContext(null, request);

                        processHttpRequestUri(axis2MsgContext, method);

                        //set inbound properties for axis2 context
                        setInboundProperties(axis2MsgContext);

                        if (!isRESTRequest(axis2MsgContext, method)) {
                            if (request.isEntityEnclosing()) {
                                processEntityEnclosingRequest(axis2MsgContext, isAxis2Path);
                            } else {
                                processNonEntityEnclosingRESTHandler(null, axis2MsgContext, isAxis2Path);
                            }
                        } else {
                            String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
                            SOAPEnvelope soapEnvelope = handleRESTUrlPost(contentTypeHeader);
                            processNonEntityEnclosingRESTHandler(soapEnvelope, axis2MsgContext, true);
                        }
                    } else {
                        //this case can only happen regex exists and it DOES match
                        //BUT there is no api or proxy found message to be injected
                        //should be routed to the main sequence instead inbound defined sequence
                        injectToMainSequence(synCtx, endpoint);
                    }
                }
            } else if (continueDispatch && dispatchPattern == null) {
                // else if for clarity compiler will optimize
                injectToSequence(synCtx, endpoint);
            } else {
                //this case can only happen regex exists and it DOES NOT match
                //should be routed to the main sequence instead inbound defined sequence
                injectToMainSequence(synCtx, endpoint);
            }

            // send ack for client if needed
            sendAck(axis2MsgContext);
        } catch (Exception e) {
            log.error("Exception occurred when running " + InboundHttpServerWorker.class.getName(), e);
        }
    } else {
        log.error("InboundSourceRequest cannot be null");
    }
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.common.InboundMessageHandler.java

/**
 * Create synapse message context and dispatch the sequence to Axis2 Engine
 *
 * @param request/*from w w  w .  j  av a 2  s. c om*/
 * @throws AxisFault
 */
public void processRequest(Http2SourceRequest request) throws AxisFault {

    String tenantDomain = getTenantDomain(request);
    MessageContext synCtx = getSynapseMessageContext(tenantDomain);

    InboundEndpoint endpoint = synCtx.getConfiguration().getInboundEndpoint(this.config.getName());
    if (endpoint == null) {
        throw new AxisFault(
                "Cannot find deployed inbound endpoint " + this.config.getName() + "for process request");
    }

    org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx)
            .getAxis2MessageContext();
    updateMessageContext(axis2MsgCtx, request);
    synCtx.setProperty(Http2Constants.STREAM_ID, request.getStreamID());
    synCtx.setProperty(Http2Constants.STREAM_CHANNEL, request.getChannel());

    axis2MsgCtx.setProperty("OutTransportInfo", this);

    axis2MsgCtx.setProperty(Http2Constants.STREAM_ID, request.getStreamID());
    axis2MsgCtx.setProperty(Http2Constants.STREAM_CHANNEL, request.getChannel());
    if (request.getRequestType() != null) {
        axis2MsgCtx.setProperty(Http2Constants.HTTP2_REQUEST_TYPE, request.getRequestType());
    }

    axis2MsgCtx.setServerSide(true);
    axis2MsgCtx.setProperty("TransportInURL", request.getUri());
    String method = request.getMethod();
    axis2MsgCtx.setIncomingTransportName(request.getScheme());
    processHttpRequestUri(axis2MsgCtx, method, request);
    synCtx.setProperty(SynapseConstants.IS_INBOUND, true);
    synCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, responseSender);
    axis2MsgCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, responseSender);
    synCtx.setWSAAction(request.getHeader(InboundHttpConstants.SOAP_ACTION));
    axis2MsgCtx.setProperty(Http2Constants.HTTP2_PUSH_PROMISE_REQEUST_ENABLED, config.isEnableServerPush());
    if (config.isEnableServerPush()) {
        axis2MsgCtx.setProperty(Http2Constants.HTTP2_DISPATCH_SEQUENCE, config.getDispatchSequence());
        axis2MsgCtx.setProperty(Http2Constants.HTTP2_ERROR_SEQUENCE, config.getErrorSequence());
    }
    if (!isRESTRequest(axis2MsgCtx, method)) {
        if (request.getPipe() != null) {
            processEntityEnclosingRequest(axis2MsgCtx, false, request);
        } else {
            processNonEntityEnclosingRESTHandler(null, axis2MsgCtx, false, request);
        }
    } else {
        AxisOperation axisOperation = ((Axis2MessageContext) synCtx).getAxis2MessageContext()
                .getAxisOperation();
        ((Axis2MessageContext) synCtx).getAxis2MessageContext().setAxisOperation(null);
        String contentTypeHeader = request.getHeader(HTTP.CONTENT_TYPE);
        SOAPEnvelope soapEnvelope = handleRESTUrlPost(contentTypeHeader, axis2MsgCtx, request);
        processNonEntityEnclosingRESTHandler(soapEnvelope, axis2MsgCtx, false, request);
        ((Axis2MessageContext) synCtx).getAxis2MessageContext().setAxisOperation(axisOperation);

    }
    boolean continueDispatch = true;
    if (dispatchPattern != null) {
        patternMatcher = dispatchPattern.matcher(request.getUri());
        if (!patternMatcher.matches()) {
            if (log.isDebugEnabled()) {
                log.debug("Requested URI does not match given dispatch regular expression.");
            }
            continueDispatch = false;
        }
    }

    if (continueDispatch && dispatchPattern != null) {

        boolean processedByAPI = false;
        RESTRequestHandler restHandler = new RESTRequestHandler();
        processedByAPI = restHandler.process(synCtx);
        if (log.isDebugEnabled()) {
            log.debug("Dispatch to API state : enabled, Message is " + (!processedByAPI ? "NOT" : "")
                    + "processed by an API");
        }

        if (!processedByAPI) {
            //check the validity of message routing to axis2 path
            boolean isAxis2Path = isAllowedAxis2Path(synCtx, request, axis2MsgCtx);

            if (isAxis2Path) {
                //create axis2 message context again to avoid settings updated above
                if (!isRESTRequest(axis2MsgCtx, method)) {
                    if (request.getPipe() != null) {
                        processEntityEnclosingRequest(axis2MsgCtx, isAxis2Path, request);
                    } else {
                        processNonEntityEnclosingRESTHandler(null, axis2MsgCtx, isAxis2Path, request);
                    }
                } else {
                    String contentTypeHeader = request.getHeader(HTTP.CONTENT_TYPE);
                    SOAPEnvelope soapEnvelope = handleRESTUrlPost(contentTypeHeader, axis2MsgCtx, request);
                    processNonEntityEnclosingRESTHandler(soapEnvelope, axis2MsgCtx, true, request);
                }
            } else {
                //this case can only happen regex exists and it DOES match
                //BUT there is no api or proxy found message to be injected
                //should be routed to the main sequence instead inbound defined sequence
                injectToMainSequence(synCtx, endpoint);
            }
        }
    } else if (continueDispatch && dispatchPattern == null) {
        // else if for clarity compiler will optimize
        injectToSequence(synCtx, endpoint);
    } else {
        //this case can only happen regex exists and it DOES NOT match
        //should be routed to the main sequence instead inbound defined sequence
        injectToMainSequence(synCtx, endpoint);
    }
}

From source file:org.wso2.carbon.mediation.transport.handlers.requestprocessors.swagger.format.SwaggerGenerator.java

/**
 * Update the response with provided response string.
 *
 * @param response       CarbonHttpResponse which will be updated
 * @param responseString String response to be updated in response
 * @param contentType    Content type of the response to be updated in response headaers
 * @throws Exception Any exception occured during the update
 *///from  w w  w. j a  v a  2  s. c  o  m
protected void updateResponse(CarbonHttpResponse response, String responseString, String contentType)
        throws AxisFault {
    try {
        ((BlobOutputStream) response.getOutputStream()).getBlob().readFrom(
                new ByteArrayInputStream(responseString.getBytes(SwaggerConstants.DEFAULT_ENCODING)),
                responseString.length());
    } catch (StreamCopyException streamCopyException) {
        handleException("Error in generating Swagger definition : failed to copy data to response ",
                streamCopyException);
    } catch (UnsupportedEncodingException encodingException) {
        handleException("Error in generating Swagger definition : exception in encoding ", encodingException);
    }
    response.setStatus(SwaggerConstants.HTTP_OK);
    response.getHeaders().put(HTTP.CONTENT_TYPE, contentType);
}