Package com.jaxws.json.codec

Examples of com.jaxws.json.codec.JSONFault


            if (object instanceof Enum) {
                Object value = ((Enum<?>) object).name();
                this.add("_name", value, object.getClass().getMethod("name"), hasData, null);
            }
        } catch (Exception e) {
            throw new JSONFault("Server.json", "Failed to serialize object "+clazz.getName(), "JSONCodec", null, e);
        }

        this.add("}");
    }
View Full Code Here


          SOAPFault faultObj = message.readAsSOAPMessage().getSOAPBody().getFault();
          HashMap<String,Object> detail = new HashMap<String, Object>();
          try {
            fillChildElementInfo(faultObj.getDetail().getChildNodes(),4,detail);
          } catch(Throwable th){/*Dont mind about custom message set fail*/}
          responseJSONMap.put(FAULT,new JSONFault(faultObj.getFaultCodeAsQName().getLocalPart().toUpperCase(),
              faultObj.getFaultString(),faultObj.getFaultActor(),detail));
         
        } catch (SOAPException e) {
          LOG.log(Level.WARNING, "Failed to read soap fault message", e);
          responseJSONMap.put(FAULT, new JSONFault("Server.json",
              "Failed to read soap fault message","Codec",null));
        }
      }else{
        final String   payload    = message.getPayloadLocalPart();
        /*
         * Step 4.2: message is not fault. valid json response
         */
        try {
          new MessageBodyBuilder(this.codec).handleMessage(this.packet,payload);
          if(JSONCodec.responsePayloadEnabled){
            responseJSONMap.put(payload,invocationProperties.remove(JSONCodec.JSON_MAP_KEY));
          }else{
            responseJSONMap.putAll((Map<String, ? extends Object>) invocationProperties.remove(JSONCodec.JSON_MAP_KEY));
          }
        } catch (Throwable exp) {
          if(JSONCodec.STATUS_PROPERTY_NAME != null)
            responseJSONMap.put(JSONCodec.STATUS_PROPERTY_NAME, false);
          responseJSONMap.put(FAULT, new JSONFault("Client.json",
              "Error while parsing response: " + payload ,"Codec", null, exp));
        }
      }
     
    } else {
      if(JSONCodec.STATUS_PROPERTY_NAME != null)
        responseJSONMap.put(JSONCodec.STATUS_PROPERTY_NAME, false);
      /*
       * Step 4.2: message in packet is null
       */
      responseJSONMap.put(FAULT, new JSONFault("Server.json",
          "Invalid message null. Try with \"X-Debug: true\" header for more trace","Server",null));
    }
    /*
     * Step 5: Write processed message map to output stream
     */
 
View Full Code Here

        return ret;
    }

    private JSONFault buildInvalidInputException() {
        return new JSONFault(JSONFault.INVALID_STRUCTURE,"Input string is not well formed JSON (invalid char " +
                        this.c + ")","JSONReader",null);
    }
View Full Code Here

            "Your using form data. " +
            "Use your parameter as json like \"{operation:{\"myaparam\":.. OR specify " +
            "\"JSON_OPERATION\" parameter with your operation name.");
      }
    } catch (Exception e) {
      throw new JSONFault("Client","Failed to create message body."+e.getMessage(),"MessageBody Builder",null,e);
   
   
  }
View Full Code Here

        if(traceLog != null){
          traceLog.error("Exception occured while reading JSON inpu as string");
          traceLog.info("Error detail: Lines read successfully: " + jsonBuffer.toString());
          traceLog.info("Error detail: Exception message" + e.getMessage());
        }
        throw new JSONFault("Client",jsonBuffer.toString(),e.getMessage(),null,e);
      }finally{
        try {
          if(traceLog != null)
            traceLog.info("JSON input reader closed");
          input.close();
        bufferReader.close();
      } catch (Exception e) {}
      }
     
      /*
       * Step 3: If request method in post and operation name located in query string, then append
       * operation name part of query string.
       *
       * Refer getQueryStringInputStream() "else" condition in case of GET method
       */
      if(queryString != null && !queryString.isEmpty() && !isJSONGetRequest()){
        if(traceLog != null)
          traceLog.info("POST method with query string added. Opeartion name identified from first parameter");
      String params[] = queryString.split("&");
      // http post request: Operation name should be first parameter if query string present.
      if(params.length > 0 && params[0].indexOf('=') == -1){
        jsonBuffer.insert(0, ("{\"" + params[0] +"\":"));
        jsonBuffer.append("}");
      }
    }
     
      /*
       * Step 4: Parsing input JSON string into java Object.
       */
      if(traceLog != null)
        traceLog.info("Parsing input JSON string into java Object");
     
      Object inputJSON = new JSONReader().read(jsonBuffer.toString());
     
      /*
       * Step 5: If input json parsed successfully by JSON reader and is it is map the process as operation.
       */
      if(inputJSON != null && inputJSON instanceof Map){
        if(traceLog != null)
          traceLog.info("Input JSON parsed successfully as plain map");
        /********************************************************************************/
        /* ACTUAL JSON TO JAVA CONVERSION HAPPEN HERE                  */
        /********************************************************************************/
        Map<String, Object> requestJSONMap = (Map<String, Object>) inputJSON;
       
        /*
         * Step 5.1 check is it comming from json service, with status flag.
         */
        if(JSONCodec.STATUS_PROPERTY_NAME != null && requestJSONMap.containsKey(JSONCodec.STATUS_PROPERTY_NAME)){
          if(traceLog != null)
            traceLog.info("Input identified as direct output of jsonservice since it has " + JSONCodec.STATUS_PROPERTY_NAME);
         
          // Output of JSON service and its status is false, then create fault message.
        if(!new Boolean(requestJSONMap.get(JSONCodec.STATUS_PROPERTY_NAME).toString())){
          return new com.sun.xml.ws.message.FaultMessage(Messages.createEmpty(this.codec.getSoapVersion()),null);
        }
        // Remove codec set value WARN user should not used codec specific key
        requestJSONMap.remove(JSONCodec.STATUS_PROPERTY_NAME);
      }
     
        if(traceLog != null)
          traceLog.info("Reading operation using service endpoint definition");
     
      /*
       * Step 5.2: Remove out bound property from JSON to avoid it serializing in json.
       */
      if(requestJSONMap.containsKey(MessageContext.MESSAGE_OUTBOUND_PROPERTY)){
        requestJSONMap.remove(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
      }
      /*
       * Step 5.3: Only one operation should be handle.
       */
      if(requestJSONMap.size() == 1){
        // Must be only one operation
        Entry<String, Object> operation = requestJSONMap.entrySet().iterator().next();
        if(traceLog != null){
          traceLog.info("Operaion identified as . " + operation.getKey());
        }
        this.packet.invocationProperties.put(JSONCodec.JSON_MAP_KEY, operation.getValue());
        try {
          return new MessageBodyBuilder(this.codec).handleMessage(this.packet,operation.getKey());
        } catch (Exception e) {
          throw new JSONFault("Client","Failed to create message body."+e.getMessage(),"MessageBody Builder",null,e);
       
      } else if(traceLog != null){
        traceLog.error("Operaion unknown in this endpoint. Please read endpoint documentation page for list of operations.");
         
      }
      if(traceLog != null)
          traceLog.add("ERROR-JSON-DECODER" , "Unknown payload/operation in json request");
      throw new JSONFault("Client","Unknown payload/operation in json request","Codec",null);
      }else{
        if(traceLog != null) traceLog.error("Input JSON parsing failed. parse result : " + String.valueOf(jsonBuffer));
        throw new JSONFault("Client","Invalid JSON input : " + jsonBuffer.toString(),"Codec",null);
      }
  }
View Full Code Here

TOP

Related Classes of com.jaxws.json.codec.JSONFault

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.